thanks for your reply
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='jo...@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.