diff --git a/pagure/lib/git_auth.py b/pagure/lib/git_auth.py index 3e75f6c..149f852 100644 --- a/pagure/lib/git_auth.py +++ b/pagure/lib/git_auth.py @@ -419,8 +419,8 @@ class Gitolite2Auth(GitAuthHelper): stream.write('# end of header\n') if groups: - for key, users in groups.iteritems(): - stream.write('@%s = %s\n' % (key, ' '.join(users))) + for key in sorted(groups): + stream.write('@%s = %s\n' % (key, ' '.join(groups[key]))) stream.write('# end of groups\n\n') prev = None @@ -552,8 +552,8 @@ class Gitolite2Auth(GitAuthHelper): stream.write('# end of header\n') if groups: - for key, users in groups.iteritems(): - stream.write('@%s = %s\n' % (key, ' '.join(users))) + for key in sorted(groups): + stream.write('@%s = %s\n' % (key, ' '.join(groups[key]))) stream.write('# end of groups\n\n') prev = None diff --git a/pagure/lib/model.py b/pagure/lib/model.py index ad45a5c..533e450 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -560,12 +560,15 @@ class Project(BASE): milestones = {} if self._milestones: - milestones = json.loads(self._milestones) - for k in milestones: - if not isinstance(milestones[k], dict): - milestones[k] = {'date': milestones[k], 'active': True} + def _convert_to_dict(value): + if isinstance(value, dict): + return value else: - break + return {'date': value, 'active': True} + milestones = dict([ + (k, _convert_to_dict(v)) for k, v in + json.loads(self._milestones).items() + ]) return milestones diff --git a/pagure/lib/tasks.py b/pagure/lib/tasks.py index e94e883..8a329d1 100644 --- a/pagure/lib/tasks.py +++ b/pagure/lib/tasks.py @@ -767,7 +767,7 @@ def update_checksums_file(self, session, folder, filenames): with open(sha_file, 'a') as stream: if new_file: stream.write('# Generated and updated by pagure\n') - for algo in algos: + for algo in sorted(algos): stream.write('%s (%s) = %s\n' % ( algo.upper(), filename, algos[algo].hexdigest())) diff --git a/tests/__init__.py b/tests/__init__.py index caaf2c9..e4a619f 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -11,6 +11,7 @@ __requires__ = ['SQLAlchemy >= 0.7'] import pkg_resources +import json import logging import os import re @@ -31,6 +32,7 @@ from datetime import date from datetime import datetime from datetime import timedelta from functools import wraps +from urlparse import urlparse, parse_qs import mock import pygit2 @@ -325,6 +327,10 @@ class SimplePagureTest(unittest.TestCase): del self.app del self._app + def shortDescription(self): + doc = self.__str__() +": "+self._testMethodDoc + return doc or None + def get_csrf(self, url='/new', output=None): """Retrieve a CSRF token from given URL.""" if output is None: @@ -334,6 +340,16 @@ class SimplePagureTest(unittest.TestCase): return output.data.split( 'name="csrf_token" type="hidden" value="')[1].split('">')[0] + def assertURLEqual(self, url_1, url_2): + url_parsed_1 = list(urlparse(url_1)) + url_parsed_1[4] = parse_qs(url_parsed_1[4]) + url_parsed_2 = list(urlparse(url_2)) + url_parsed_2[4] = parse_qs(url_parsed_2[4]) + return self.assertListEqual(url_parsed_1, url_parsed_2) + + def assertJSONEqual(self, json_1, json_2): + return self.assertEqual(json.loads(json_1), json.loads(json_2)) + class Modeltests(SimplePagureTest): """ Model tests. """ diff --git a/tests/test_pagure_flask_api.py b/tests/test_pagure_flask_api.py index a032160..927e497 100644 --- a/tests/test_pagure_flask_api.py +++ b/tests/test_pagure_flask_api.py @@ -46,7 +46,7 @@ class PagureFlaskApitests(tests.SimplePagureTest): output = self.app.get('/api/0/foo/tags/') self.assertEqual(output.status_code, 404) data = json.loads(output.data) - self.assertEqual(data.keys(), ['output', 'error']) + self.assertEqual(set(data.keys()), set(['output', 'error'])) self.assertEqual(data['output'], 'notok') self.assertEqual(data['error'], 'Project not found') diff --git a/tests/test_pagure_flask_api_issue_custom_fields.py b/tests/test_pagure_flask_api_issue_custom_fields.py index 29523dd..8b13fea 100644 --- a/tests/test_pagure_flask_api_issue_custom_fields.py +++ b/tests/test_pagure_flask_api_issue_custom_fields.py @@ -111,13 +111,14 @@ class PagureFlaskApiCustomFieldIssuetests(tests.Modeltests): '/api/0/test/issue/1/custom', headers=headers, data=payload) self.assertEqual(output.status_code, 200) data = json.loads(output.data) + data["messages"].sort() self.assertDictEqual( data, { - "messages": [ + "messages": sorted([ {"bugzilla": "No changes"}, {"upstream": "Custom field upstream adjusted to True"}, - ] + ]) } ) @@ -134,16 +135,17 @@ class PagureFlaskApiCustomFieldIssuetests(tests.Modeltests): data=payload) self.assertEqual(output.status_code, 200) data = json.loads(output.data) + data["messages"].sort() self.assertDictEqual( data, { - "messages": [ + "messages": sorted([ {"bugzilla": "Custom field bugzilla adjusted to " "https://bugzilla.redhat.com/1234"}, {"reviewstatus": "Custom field reviewstatus adjusted to ack"}, {"upstream": "Custom field upstream adjusted to False (was: True)"}, - ] + ]) } ) @@ -159,15 +161,16 @@ class PagureFlaskApiCustomFieldIssuetests(tests.Modeltests): data=payload) self.assertEqual(output.status_code, 200) data = json.loads(output.data) + data["messages"].sort() self.assertDictEqual( data, { - "messages": [ + "messages": sorted([ {"bugzilla": "Custom field bugzilla reset " "(from https://bugzilla.redhat.com/1234)"}, {"reviewstatus": "Custom field reviewstatus reset (from ack)"}, {"upstream": "Custom field upstream reset (from False)"}, - ] + ]) } ) diff --git a/tests/test_pagure_flask_api_project.py b/tests/test_pagure_flask_api_project.py index f8ddac1..a950152 100644 --- a/tests/test_pagure_flask_api_project.py +++ b/tests/test_pagure_flask_api_project.py @@ -1057,8 +1057,6 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "username": None }, "pagination": { - "first": "http://localhost/api/0/projects?per_page=20&page=1", - "last": "http://localhost/api/0/projects?per_page=20&page=1", "next": None, "page": 1, "pages": 1, @@ -1174,6 +1172,15 @@ class PagureFlaskApiProjecttests(tests.Modeltests): ], "total_projects": 3 } + # Test URLs + self.assertURLEqual( + data["pagination"].pop("first"), + "http://localhost/api/0/projects?per_page=20&page=1", + ) + self.assertURLEqual( + data["pagination"].pop("last"), + "http://localhost/api/0/projects?per_page=20&page=1", + ) self.assertDictEqual(data, expected_data) def test_api_projects_pagination_per_page(self): @@ -1199,13 +1206,10 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "username": None }, "pagination": { - "first": "http://localhost/api/0/projects?per_page=2&page=1", - "last": "http://localhost/api/0/projects?per_page=2&page=2", "next": None, "page": 2, "pages": 2, "per_page": 2, - "prev": "http://localhost/api/0/projects?per_page=2&page=1", }, "projects": [ { @@ -1247,6 +1251,18 @@ class PagureFlaskApiProjecttests(tests.Modeltests): ], "total_projects": 3 } + self.assertURLEqual( + data["pagination"].pop("first"), + "http://localhost/api/0/projects?per_page=2&page=1", + ) + self.assertURLEqual( + data["pagination"].pop("prev"), + "http://localhost/api/0/projects?per_page=2&page=1", + ) + self.assertURLEqual( + data["pagination"].pop("last"), + "http://localhost/api/0/projects?per_page=2&page=2", + ) self.assertDictEqual(data, expected_data) def test_api_projects_pagination_invalid_page(self): @@ -1303,6 +1319,18 @@ class PagureFlaskApiProjecttests(tests.Modeltests): output = self.app.get('/api/0/projects?page=99999') self.assertEqual(output.status_code, 200) data = json.loads(output.data) + self.assertURLEqual( + data["pagination"].pop("first"), + "http://localhost/api/0/projects?per_page=20&page=1", + ) + self.assertURLEqual( + data["pagination"].pop("last"), + "http://localhost/api/0/projects?per_page=20&page=1", + ) + self.assertURLEqual( + data["pagination"].pop("prev"), + "http://localhost/api/0/projects?per_page=20&page=99998", + ) self.assertEqual( data, { @@ -1318,13 +1346,10 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "username": None }, "pagination": { - "first": "http://localhost/api/0/projects?per_page=20&page=1", - "last": "http://localhost/api/0/projects?per_page=20&page=1", "next": None, "page": 99999, "pages": 1, "per_page": 20, - "prev": "http://localhost/api/0/projects?per_page=20&page=99998" }, "projects": [], "total_projects": 3 diff --git a/tests/test_pagure_flask_dump_load_ticket.py b/tests/test_pagure_flask_dump_load_ticket.py index 83de075..7023ee0 100644 --- a/tests/test_pagure_flask_dump_load_ticket.py +++ b/tests/test_pagure_flask_dump_load_ticket.py @@ -207,7 +207,7 @@ class PagureFlaskDumpLoadTicketTests(tests.Modeltests): # Check after re-loading self.assertEqual(len(issue.comments), 3) self.assertEqual(len(issue.tags), 2) - self.assertEqual(issue.tags_text, ['future', 'feature']) + self.assertEqual(sorted(issue.tags_text), sorted(['future', 'feature'])) self.assertEqual(issue.assignee.username, 'pingou') self.assertEqual(issue.children, []) self.assertEqual(issue.parents, []) diff --git a/tests/test_pagure_flask_ui_fork.py b/tests/test_pagure_flask_ui_fork.py index 142ba7c..e588e8b 100644 --- a/tests/test_pagure_flask_ui_fork.py +++ b/tests/test_pagure_flask_ui_fork.py @@ -21,6 +21,7 @@ import os import pygit2 from mock import patch, MagicMock +from bs4 import BeautifulSoup sys.path.insert(0, os.path.join(os.path.dirname( os.path.abspath(__file__)), '..')) @@ -1473,23 +1474,33 @@ index 0000000..2a552bb '/test/pull-request/1/update', data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) - self.assertIn( - '