About interacting and testing with django tastypie -
i read many tutorial django testing don't know how can test function insde resource , example user resource signin function , obj_create. appreciate helps because can not figure out how test them. k thanks.
class userresource(modelresource):
school = fields.toonefield('frittie.app.api.api.locationresource', 'user') class meta: queryset = userprofile.objects.all() resource_name = 'user' allowed_methods = ['get','post'] serializer = serializer(formats=['json', 'plist']) authorization= authorization() #models.signals.post_save.connect(create_api_key, sender=user) #fields = ['username', 'email'] def obj_create(self, bundle, request=none, **kwargs): if not request.method == "post": raise badrequest('object not found or not allowed create new one.') username, email, password = bundle.data['username'], bundle.data['password'], bundle.data['password'], try: bundle.obj = user.objects.create_user(username, email, password) except integrityerror: raise badrequest('that username exists') return bundle def signin(self, request, **kwargs): self.method_check(request, allowed=['post']) username = request.post['username'] password = request.post['password'] user = authenticate(username=username, password=password) if user not none: if user.is_active: login(request, user) return self.create_response(request, {'success': true}) else: # return 'disabled account' error message return self.create_response(request, {'success': false}) else: # return 'invalid login' error message. return self.create_response(request, {'success': false})
tastypie has descent testing documentation - resourcetestcase api reference
Comments
Post a Comment