How do I write unit tests for those endpoints of my API that require oAuth authentication?
Simply adding oAuth tokens to the request headers doesn't work (perhaps because the test database is not persistent). Loading fixtures into the database doesn't help either.
I am using django-rest-framework together with django-oauth-toolkit.
My test.py code:
class Com_jm_Test(TestCase):
fixtures=['oauth.json',]
print 'test com jm'
multi_db=True
def test_list_job(self):
self.client=Client(HTTP_AUTHORIZATION='Bearer 0cx2G9gKm4XZdK8BFxoWy7AE025tvq')
response=self.client.get('/com-jm/jobs/')
self.assertEqual(response.status_code,200)
The result:
AssertionError: 401 != 200