Hi Tom, thanks for your reply
When using http://www.django-rest-framework.org/api-guide/testing/#apiclient with force_authenticated() now I got : File "/home/foxmask/DjangoVirtualEnv/orotangi/orotangi/orotangi/api/test.py", line 48, in test_create_book self.assertEqual(response.status_code, status.HTTP_201_CREATED) AssertionError: 403 != 201 test.py looks like this def test_create_book(self): """ Ensure we can create a new book object. """ data = {'name': 'Book1', 'user': self.user.username} response = self.client.post('/api/orotangi/books/', data, format='json') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(Books.objects.count(), 1) self.assertEqual(Books.objects.get().name, 'Book1') line 48 is the 1rst assertEqual() I noticed that the 403 error is related to this settings REST_FRAMEWORK = { [...] 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.SessionAuthentication', 'rest_framework.authentication.BasicAuthentication' ), 'TEST_REQUEST_DEFAULT_FORMAT': 'json' } But In my setup() I wrote : def setUp(self): """ :return: """ try: self.user = User.objects.get(username='john') except User.DoesNotExist: self.user = User.objects.create_user(username='john', email='j...@doe.info', password='doe') self.client = APIClient(enforce_csrf_checks=True) self.client.force_authenticate(user=self.user) so I was expecting to fill the session What did I do wrong ? regards. 2017-05-01 19:17 GMT+02:00 Tom Christie <christie....@gmail.com>: > Use APIclient, and use .autuenticate(user) > > -- > You received this message because you are subscribed to the Google Groups > "Django REST framework" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-rest-framework+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Trigger Happy https://trigger-happy.eu/ -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.