From 37d1e918116c473198417a128be219c1d81d9056 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: May 22 2015 08:49:22 +0000 Subject: Add unit-tests to check an API token when it all goes well --- diff --git a/tests/test_progit_flask_api_auth.py b/tests/test_progit_flask_api_auth.py index 70d109f..d72415d 100644 --- a/tests/test_progit_flask_api_auth.py +++ b/tests/test_progit_flask_api_auth.py @@ -102,6 +102,39 @@ class PagureFlaskApiAuthtests(tests.Modeltests): } ) + def test_auth(self): + """ Test the token based authentication. + """ + tests.create_projects(self.session) + tests.create_tokens(self.session) + tests.create_acls(self.session) + tests.create_tokens_acl(self.session) + + output = self.app.post('/api/0/test/new_issue') + self.assertEqual(output.status_code, 401) + data = json.loads(output.data) + self.assertDictEqual( + data, + { + "error": "Invalid or expired token. Please visit " \ + "https://pagure.org/ get or renew your API token.", + "output": "notok" + } + ) + + headers = {'Authorization': 'token aaabbbcccddd'} + + output = self.app.post('/api/0/test/new_issue', headers=headers) + self.assertEqual(output.status_code, 400) + data = json.loads(output.data) + self.assertDictEqual( + data, + { + "error": "Invalid or incomplete input submited", + "error_code": 4 + } + ) + if __name__ == '__main__': SUITE = unittest.TestLoader().loadTestsFromTestCase(