From dccbc896fe2e03df266a25ac3c908006dc145efb 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 the behavior of the API when the API token has expired --- diff --git a/tests/test_progit_flask_api_auth.py b/tests/test_progit_flask_api_auth.py index d72415d..0132d07 100644 --- a/tests/test_progit_flask_api_auth.py +++ b/tests/test_progit_flask_api_auth.py @@ -102,6 +102,38 @@ class PagureFlaskApiAuthtests(tests.Modeltests): } ) + def test_auth_expired(self): + """ Test the authentication when the token has expired. + """ + tests.create_projects(self.session) + tests.create_tokens(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 expired_token'} + + output = self.app.post('/api/0/test/new_issue', headers=headers) + 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" + } + ) + def test_auth(self): """ Test the token based authentication. """