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(