Does the Django Rest APIClient class make an actual request? -



Does the Django Rest APIClient class make an actual request? -

i wondering if request beingness made via http. in app have test looks like

class authenticate(apitestcase): def setup(self): self.client = apiclient() self.password_for_admin = '123456' self.admin = user.objects.create_superuser(username='myname', email='email@email.com', password='123456') self.token = token.objects.create(user=self.admin) def test_authenticate(self): """ comment """ self.client.credentials(http_authorization='basic ' + base64.b64encode('{}:{}'.format(self.admin.username, self.password_for_admin))) response = self.client.post('/api/authenticate/') print response

and in view i've got:

@api_view(('post',)) def authenticate(request, format=none): """ comment """ import pprint log.debug(pprint.pprint(request)) try: "asdlfjl" except exception, e: response = "an error occurred, {}".format(e) homecoming response(response)

my settings looks like:

installed_apps = ( ... 'django.contrib.sessions', ) middleware_classes = ( 'django.contrib.sessions.middleware.sessionmiddleware', ... )

the request beingness printed out none in log file. need session. tried request.session (which none) , that's led me question.

i figured out. server send request using testserver domain. sort of misleading question , code wrong. user authenticated using rest basic backend time reach view method.

through much research found out user beingness authenticated rest login method doesn't called rest backend. since login doesn't called rest backend session never attached request. changed authenticate method login , called login doing this:

... @api_view(('post',)) def login(request, format=none): try: django.contrib.auth import login if request.user , request.user.is_active: login(request, request.user) ... response = ... else: response = {} except exception, e: response = "an error occurred, {}".format(e) homecoming response(response)

django django-rest-framework django-sessions

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -