everyone. I am trying to write tests for RESTful API implemented using django-tastypie with http basic auth. So, I have the following code:
def http_auth(username, password): credentials = base64.encodestring('%s:%s' % (username, password)).strip() auth_string = 'Basic %s' % credentials return auth_string class FileApiTest(TestCase): fixtures = ['test/fixtures/test_users.json'] def setUp(self): self.extra = { 'HTTP_AUTHORIZATION': http_auth('testuser', 'qwerty') } def test_folder_resource(self): response = self.client.get('/api/1.0/folder/', **self.extra) self.assertEqual(response.status_code, 200) def test_folder_resource_post(self): response = self.client.post('/api/1.0/folder/', **self.extra) self.assertNotEqual(response.status_code, 401) GET request is done well, returning status code 200. But POST request always returns 401. I am sure I am doing something wrong. Any advice?
authorization = DjangoAuthorization()authentication = BasicAuthentication(realm=settings.SOCIAL_API_REALM)