diff --git a/tests/test_pagure_flask_api_auth.py b/tests/test_pagure_flask_api_auth.py index ef76281..ac9e574 100644 --- a/tests/test_pagure_flask_api_auth.py +++ b/tests/test_pagure_flask_api_auth.py @@ -22,6 +22,7 @@ from mock import patch sys.path.insert(0, os.path.join(os.path.dirname( os.path.abspath(__file__)), '..')) +import pagure.api import pagure.lib import tests @@ -47,28 +48,18 @@ class PagureFlaskApiAuthtests(tests.Modeltests): output = self.app.post('/api/0/foo/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/ to get or renew your API token.", - "error_code": "EINVALIDTOK", - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) headers = {'Authorization': 'token aabbbccc'} output = self.app.post('/api/0/foo/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/ to get or renew your API token.", - "error_code": "EINVALIDTOK", - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) def test_auth_noacl(self): """ Test the authentication when the token does not have any ACL. @@ -79,28 +70,18 @@ class PagureFlaskApiAuthtests(tests.Modeltests): 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK", - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) headers = {'Authorization': 'token aaabbbcccddd'} 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK", - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) def test_auth_expired(self): """ Test the authentication when the token has expired. @@ -111,28 +92,18 @@ class PagureFlaskApiAuthtests(tests.Modeltests): 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK", - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK", - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) def test_auth(self): """ Test the token based authentication. @@ -144,14 +115,9 @@ class PagureFlaskApiAuthtests(tests.Modeltests): 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK", - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) headers = {'Authorization': 'token aaabbbcccddd'} diff --git a/tests/test_pagure_flask_api_fork.py b/tests/test_pagure_flask_api_fork.py index 9ade4c8..916a6a6 100644 --- a/tests/test_pagure_flask_api_fork.py +++ b/tests/test_pagure_flask_api_fork.py @@ -23,6 +23,7 @@ from mock import patch sys.path.insert(0, os.path.join(os.path.dirname( os.path.abspath(__file__)), '..')) +import pagure.api import pagure.lib import tests @@ -341,14 +342,9 @@ class PagureFlaskApiForktests(tests.Modeltests): '/api/0/test2/pull-request/1/close', 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK", - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) # Invalid PR output = self.app.post( @@ -455,14 +451,9 @@ class PagureFlaskApiForktests(tests.Modeltests): '/api/0/test2/pull-request/1/merge', 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK", - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) # Invalid PR output = self.app.post( @@ -550,14 +541,9 @@ class PagureFlaskApiForktests(tests.Modeltests): '/api/0/test2/pull-request/1/comment', 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK", - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) # No input output = self.app.post( @@ -664,14 +650,9 @@ class PagureFlaskApiForktests(tests.Modeltests): '/api/0/test2/pull-request/1/flag', 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK", - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) # No input output = self.app.post( diff --git a/tests/test_pagure_flask_api_issue.py b/tests/test_pagure_flask_api_issue.py index 7bd337d..60c20e1 100644 --- a/tests/test_pagure_flask_api_issue.py +++ b/tests/test_pagure_flask_api_issue.py @@ -57,14 +57,9 @@ class PagureFlaskApiIssuetests(tests.Modeltests): output = self.app.post('/api/0/test2/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/ to get or renew your API token.", - "error_code": "EINVALIDTOK", - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) # No input output = self.app.post('/api/0/test/new_issue', headers=headers) @@ -540,13 +535,9 @@ class PagureFlaskApiIssuetests(tests.Modeltests): output = self.app.get('/api/0/test/issue/2', 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK" - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) # Create a new token for another user item = pagure.lib.model.Token( @@ -657,14 +648,9 @@ class PagureFlaskApiIssuetests(tests.Modeltests): output = self.app.post('/api/0/test2/issue/1/status', 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK", - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) # No input output = self.app.post('/api/0/test/issue/1/status', headers=headers) @@ -802,14 +788,9 @@ class PagureFlaskApiIssuetests(tests.Modeltests): '/api/0/foo/issue/1/status', data=data, 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK" - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) @patch('pagure.lib.git.update_git') @patch('pagure.lib.notify.send_email') @@ -840,14 +821,9 @@ class PagureFlaskApiIssuetests(tests.Modeltests): output = self.app.post('/api/0/test2/issue/1/comment', 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK", - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) # No input output = self.app.post('/api/0/test/issue/1/comment', headers=headers) @@ -982,14 +958,9 @@ class PagureFlaskApiIssuetests(tests.Modeltests): '/api/0/foo/issue/1/comment', data=data, 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK" - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) # No comment added repo = pagure.lib.get_project(self.session, 'foo') @@ -1166,14 +1137,9 @@ class PagureFlaskApiIssuetests(tests.Modeltests): output = self.app.post('/api/0/test2/issue/1/assign', 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK", - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) # No input output = self.app.post('/api/0/test/issue/1/assign', headers=headers) @@ -1308,14 +1274,9 @@ class PagureFlaskApiIssuetests(tests.Modeltests): '/api/0/foo/issue/1/assign', data=data, 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK" - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) # No comment added repo = pagure.lib.get_project(self.session, 'foo') diff --git a/tests/test_pagure_flask_api_project.py b/tests/test_pagure_flask_api_project.py index 4792e53..039becf 100644 --- a/tests/test_pagure_flask_api_project.py +++ b/tests/test_pagure_flask_api_project.py @@ -249,14 +249,9 @@ class PagureFlaskApiProjecttests(tests.Modeltests): output = self.app.post('/api/0/new', 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK" - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) headers = {'Authorization': 'token aaabbbcccddd'} @@ -340,14 +335,9 @@ class PagureFlaskApiProjecttests(tests.Modeltests): output = self.app.post('/api/0/fork', 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/ to get or renew your API token.", - "error_code": "EINVALIDTOK" - } - ) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name, + data['error_code']) + self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error']) headers = {'Authorization': 'token aaabbbcccddd'} diff --git a/tests/test_pagure_flask_ui_issues.py b/tests/test_pagure_flask_ui_issues.py index e68de08..77f863e 100644 --- a/tests/test_pagure_flask_ui_issues.py +++ b/tests/test_pagure_flask_ui_issues.py @@ -565,9 +565,9 @@ class PagureFlaskIssuestests(tests.Modeltests): '' in output.data) self.assertIn( - '

' + '

' '@pingou changed the status to Fixed' - '

', + '

'.format(app_url=pagure.APP.config['APP_URL']), output.data) # Add new comment