From b6ff16b624f203e66d86d7afbe72a20975809621 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Feb 05 2019 14:49:54 +0000 Subject: db ordering fixes --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 87e9460..9146d8b 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -7724,8 +7724,7 @@ class InsertProcessor(object): if not self.data and not self.rawdata: return "-- incomplete update: no assigns" parts = ['INSERT INTO %s ' % self.table] - columns = to_list(self.data.keys()) - columns.extend(to_list(self.rawdata.keys())) + columns = sorted(to_list(self.data.keys()) + to_list(self.rawdata.keys())) parts.append("(%s) " % ', '.join(columns)) values = [] for key in columns: @@ -7811,10 +7810,10 @@ class UpdateProcessor(object): parts = ['UPDATE %s SET ' % self.table] assigns = ["%s = %%(data.%s)s" % (key, key) for key in self.data] assigns.extend(["%s = (%s)" % (key, self.rawdata[key]) for key in self.rawdata]) - parts.append(', '.join(assigns)) + parts.append(', '.join(sorted(assigns))) if self.clauses: parts.append('\nWHERE ') - parts.append(' AND '.join(["( %s )" % c for c in self.clauses])) + parts.append(' AND '.join(["( %s )" % c for c in sorted(self.clauses)])) return ''.join(parts) def __repr__(self): @@ -7887,12 +7886,23 @@ class QueryProcessor(object): if columns and aliases: if len(columns) != len(aliases): raise Exception('column and alias lists must be the same length') - self.colsByAlias = dict(zip(aliases, columns)) + # reorder + alias_table = sorted(zip(aliases, columns)) + self.aliases = [x[0] for x in alias_table] + self.columns = [x[1] for x in alias_table] + self.colsByAlias = dict(alias_table) else: self.colsByAlias = {} + if columns: + self.columns = sorted(columns) + if aliases: + self.aliases = sorted(aliases) self.tables = tables self.joins = joins - self.clauses = clauses + if clauses: + self.clauses = sorted(clauses) + else: + self.clauses = clauses self.cursors = 0 if values: self.values = values @@ -7930,7 +7940,7 @@ SELECT %(col_str)s col_str = 'count(*)' else: col_str = self._seqtostr(self.columns) - table_str = self._seqtostr(self.tables) + table_str = self._seqtostr(self.tables, sort=True) join_str = self._joinstr() clause_str = self._seqtostr(self.clauses, sep=')\n AND (') if clause_str: @@ -7951,8 +7961,10 @@ SELECT %(col_str)s return '' % \ (self.columns, self.aliases, self.tables, self.joins, self.clauses, self.values, self.opts) - def _seqtostr(self, seq, sep=', '): + def _seqtostr(self, seq, sep=', ', sort=False): if seq: + if sort: + seq = sorted(seq) return sep.join(seq) else: return '' diff --git a/tests/test_hub/data/image/import_1/db.json b/tests/test_hub/data/image/import_1/db.json index 9ffdfb2..ca9f44e 100644 --- a/tests/test_hub/data/image/import_1/db.json +++ b/tests/test_hub/data/image/import_1/db.json @@ -1,205 +1,205 @@ { "inserts": [ [ - "INSERT INTO archiveinfo (build_id, archive_id, type_id, checksum, filename, checksum_type, btype_id, buildroot_id, id, size) VALUES (%(build_id)s, %(archive_id)s, %(type_id)s, %(checksum)s, %(filename)s, %(checksum_type)s, %(btype_id)s, %(buildroot_id)s, %(id)s, %(size)s)", - { - "build_id": 137, - "archive_id": "ARCHIVE_ID", - "type_id": "ARCHIVETYPE", - "checksum": "19a674d997af7098a444b60d7b51cee6", - "filename": "tdl-x86_64.xml", - "checksum_type": 0, - "btype_id": "BTYPEID:image", - "buildroot_id": null, - "id": 1001, + "INSERT INTO archiveinfo (archive_id, btype_id, build_id, buildroot_id, checksum, checksum_type, filename, id, size, type_id) VALUES (%(archive_id)s, %(btype_id)s, %(build_id)s, %(buildroot_id)s, %(checksum)s, %(checksum_type)s, %(filename)s, %(id)s, %(size)s, %(type_id)s)", + { + "build_id": 137, + "archive_id": "ARCHIVE_ID", + "type_id": "ARCHIVETYPE", + "checksum": "19a674d997af7098a444b60d7b51cee6", + "filename": "tdl-x86_64.xml", + "checksum_type": 0, + "btype_id": "BTYPEID:image", + "buildroot_id": null, + "id": 1001, "size": 36 - }, + }, {} - ], + ], [ - "INSERT INTO image_archives (archive_id, arch) VALUES (%(archive_id)s, %(arch)s)", + "INSERT INTO image_archives (arch, archive_id) VALUES (%(arch)s, %(archive_id)s)", { - "archive_id": 1001, + "archive_id": 1001, "arch": "x86_64" - }, + }, {} - ], + ], [ - "INSERT INTO archiveinfo (build_id, archive_id, type_id, checksum, filename, checksum_type, btype_id, buildroot_id, id, size) VALUES (%(build_id)s, %(archive_id)s, %(type_id)s, %(checksum)s, %(filename)s, %(checksum_type)s, %(btype_id)s, %(buildroot_id)s, %(id)s, %(size)s)", + "INSERT INTO archiveinfo (archive_id, btype_id, build_id, buildroot_id, checksum, checksum_type, filename, id, size, type_id) VALUES (%(archive_id)s, %(btype_id)s, %(build_id)s, %(buildroot_id)s, %(checksum)s, %(checksum_type)s, %(filename)s, %(id)s, %(size)s, %(type_id)s)", { - "build_id": 137, - "archive_id": "ARCHIVE_ID", - "type_id": "ARCHIVETYPE", - "checksum": "a5114a20d790cf17eca1b1115a4546f8", - "filename": "image.ks", - "checksum_type": 0, - "btype_id": "BTYPEID:image", - "buildroot_id": null, - "id": 1002, + "build_id": 137, + "archive_id": "ARCHIVE_ID", + "type_id": "ARCHIVETYPE", + "checksum": "a5114a20d790cf17eca1b1115a4546f8", + "filename": "image.ks", + "checksum_type": 0, + "btype_id": "BTYPEID:image", + "buildroot_id": null, + "id": 1002, "size": 30 - }, + }, {} - ], + ], [ - "INSERT INTO image_archives (archive_id, arch) VALUES (%(archive_id)s, %(arch)s)", + "INSERT INTO image_archives (arch, archive_id) VALUES (%(arch)s, %(archive_id)s)", { - "archive_id": 1002, + "archive_id": 1002, "arch": "x86_64" - }, + }, {} - ], + ], [ - "INSERT INTO archiveinfo (build_id, archive_id, type_id, checksum, filename, checksum_type, btype_id, buildroot_id, id, size) VALUES (%(build_id)s, %(archive_id)s, %(type_id)s, %(checksum)s, %(filename)s, %(checksum_type)s, %(btype_id)s, %(buildroot_id)s, %(id)s, %(size)s)", + "INSERT INTO archiveinfo (archive_id, btype_id, build_id, buildroot_id, checksum, checksum_type, filename, id, size, type_id) VALUES (%(archive_id)s, %(btype_id)s, %(build_id)s, %(buildroot_id)s, %(checksum)s, %(checksum_type)s, %(filename)s, %(id)s, %(size)s, %(type_id)s)", { - "build_id": 137, - "archive_id": "ARCHIVE_ID", - "type_id": "ARCHIVETYPE", - "checksum": "9828cf75d9d17ac8e79e53ed71c6a71c", - "filename": "image-base.ks", - "checksum_type": 0, - "btype_id": "BTYPEID:image", - "buildroot_id": null, - "id": 1003, + "build_id": 137, + "archive_id": "ARCHIVE_ID", + "type_id": "ARCHIVETYPE", + "checksum": "9828cf75d9d17ac8e79e53ed71c6a71c", + "filename": "image-base.ks", + "checksum_type": 0, + "btype_id": "BTYPEID:image", + "buildroot_id": null, + "id": 1003, "size": 35 - }, + }, {} - ], + ], [ - "INSERT INTO image_archives (archive_id, arch) VALUES (%(archive_id)s, %(arch)s)", + "INSERT INTO image_archives (arch, archive_id) VALUES (%(arch)s, %(archive_id)s)", { - "archive_id": 1003, + "archive_id": 1003, "arch": "x86_64" - }, + }, {} - ], + ], [ - "INSERT INTO archiveinfo (build_id, archive_id, type_id, checksum, filename, checksum_type, btype_id, buildroot_id, id, size) VALUES (%(build_id)s, %(archive_id)s, %(type_id)s, %(checksum)s, %(filename)s, %(checksum_type)s, %(btype_id)s, %(buildroot_id)s, %(id)s, %(size)s)", + "INSERT INTO archiveinfo (archive_id, btype_id, build_id, buildroot_id, checksum, checksum_type, filename, id, size, type_id) VALUES (%(archive_id)s, %(btype_id)s, %(build_id)s, %(buildroot_id)s, %(checksum)s, %(checksum_type)s, %(filename)s, %(id)s, %(size)s, %(type_id)s)", { - "build_id": 137, - "archive_id": "ARCHIVE_ID", - "type_id": "ARCHIVETYPE", - "checksum": "f601c0f647d7cdd4c92aa511876f8533", - "filename": "foo-x86_64.xml", - "checksum_type": 0, - "btype_id": "BTYPEID:image", - "buildroot_id": null, - "id": 1004, + "build_id": 137, + "archive_id": "ARCHIVE_ID", + "type_id": "ARCHIVETYPE", + "checksum": "f601c0f647d7cdd4c92aa511876f8533", + "filename": "foo-x86_64.xml", + "checksum_type": 0, + "btype_id": "BTYPEID:image", + "buildroot_id": null, + "id": 1004, "size": 36 - }, + }, {} - ], + ], [ - "INSERT INTO image_archives (archive_id, arch) VALUES (%(archive_id)s, %(arch)s)", + "INSERT INTO image_archives (arch, archive_id) VALUES (%(arch)s, %(archive_id)s)", { - "archive_id": 1004, + "archive_id": 1004, "arch": "x86_64" - }, + }, {} - ], + ], [ - "INSERT INTO archiveinfo (build_id, archive_id, type_id, checksum, filename, checksum_type, btype_id, buildroot_id, id, size) VALUES (%(build_id)s, %(archive_id)s, %(type_id)s, %(checksum)s, %(filename)s, %(checksum_type)s, %(btype_id)s, %(buildroot_id)s, %(id)s, %(size)s)", + "INSERT INTO archiveinfo (archive_id, btype_id, build_id, buildroot_id, checksum, checksum_type, filename, id, size, type_id) VALUES (%(archive_id)s, %(btype_id)s, %(build_id)s, %(buildroot_id)s, %(checksum)s, %(checksum_type)s, %(filename)s, %(id)s, %(size)s, %(type_id)s)", { - "build_id": 137, - "archive_id": "ARCHIVE_ID", - "type_id": "ARCHIVETYPE", - "checksum": "84547200ef5002292ecdd50c62de518e", - "filename": "my-image-7.4.2-2.x86_64.ova", - "checksum_type": 0, - "btype_id": "BTYPEID:image", - "buildroot_id": null, - "id": 1005, + "build_id": 137, + "archive_id": "ARCHIVE_ID", + "type_id": "ARCHIVETYPE", + "checksum": "84547200ef5002292ecdd50c62de518e", + "filename": "my-image-7.4.2-2.x86_64.ova", + "checksum_type": 0, + "btype_id": "BTYPEID:image", + "buildroot_id": null, + "id": 1005, "size": 49 - }, + }, {} - ], + ], [ - "INSERT INTO image_archives (archive_id, arch) VALUES (%(archive_id)s, %(arch)s)", + "INSERT INTO image_archives (arch, archive_id) VALUES (%(arch)s, %(archive_id)s)", { - "archive_id": 1005, + "archive_id": 1005, "arch": "x86_64" - }, + }, {} - ], + ], [ - "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", + "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", { - "archive_id": 1002, + "archive_id": 1002, "rpm_id": 1000 - }, + }, {} - ], + ], [ - "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", + "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", { - "archive_id": 1002, + "archive_id": 1002, "rpm_id": 1001 - }, + }, {} - ], + ], [ - "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", + "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", { - "archive_id": 1002, + "archive_id": 1002, "rpm_id": 1002 - }, + }, {} - ], + ], [ - "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", + "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", { - "archive_id": 1003, + "archive_id": 1003, "rpm_id": 1000 - }, + }, {} - ], + ], [ - "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", + "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", { - "archive_id": 1003, + "archive_id": 1003, "rpm_id": 1001 - }, + }, {} - ], + ], [ - "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", + "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", { - "archive_id": 1003, + "archive_id": 1003, "rpm_id": 1002 - }, + }, {} - ], + ], [ - "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", + "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", { - "archive_id": 1005, + "archive_id": 1005, "rpm_id": 1000 - }, + }, {} - ], + ], [ - "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", + "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", { - "archive_id": 1005, + "archive_id": 1005, "rpm_id": 1001 - }, + }, {} - ], + ], [ - "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", + "INSERT INTO archive_rpm_components (archive_id, rpm_id) VALUES (%(archive_id)s, %(rpm_id)s)", { - "archive_id": 1005, + "archive_id": 1005, "rpm_id": 1002 - }, + }, {} ] - ], + ], "updates": [ [ - "UPDATE build SET state = %(data.state)s, id = %(data.id)s, completion_time = (now())\nWHERE ( id=%(build_id)i )", + "UPDATE build SET completion_time = (now()), id = %(data.id)s, state = %(data.state)s\nWHERE ( id=%(build_id)i )", { - "state": 1, + "state": 1, "id": "BUILD_ID" - }, + }, { "completion_time": "now()" } diff --git a/tests/test_hub/test_import_build.py b/tests/test_hub/test_import_build.py index 22f1186..2422d9a 100644 --- a/tests/test_hub/test_import_build.py +++ b/tests/test_hub/test_import_build.py @@ -76,18 +76,18 @@ class TestImportRPM(unittest.TestCase): _singleValue.return_value = 9876 kojihub.import_rpm(self.filename) fields = [ - 'build_id', - 'name', 'arch', + 'build_id', + 'buildroot_id', 'buildtime', - 'payloadhash', 'epoch', - 'version', - 'buildroot_id', - 'release', 'external_repo_id', 'id', + 'name', + 'payloadhash', + 'release', 'size', + 'version', ] statement = 'INSERT INTO rpminfo (%s) VALUES (%s)' % ( ", ".join(fields), @@ -135,18 +135,18 @@ class TestImportRPM(unittest.TestCase): _singleValue.return_value = 9876 kojihub.import_rpm(self.src_filename) fields = [ - 'build_id', - 'name', 'arch', + 'build_id', + 'buildroot_id', 'buildtime', - 'payloadhash', 'epoch', - 'version', - 'buildroot_id', - 'release', 'external_repo_id', 'id', + 'name', + 'payloadhash', + 'release', 'size', + 'version', ] statement = 'INSERT INTO rpminfo (%s) VALUES (%s)' % ( ", ".join(fields), @@ -253,19 +253,19 @@ class TestImportBuild(unittest.TestCase): kojihub.import_build(self.src_filename, [self.filename]) fields = [ - 'task_id', + 'completion_time', + 'epoch', 'extra', + 'id', + 'owner', + 'pkg_id', + 'release', + 'source', 'start_time', - 'epoch', - 'completion_time', 'state', + 'task_id', 'version', - 'source', 'volume_id', - 'owner', - 'release', - 'pkg_id', - 'id', ] statement = 'INSERT INTO build (%s) VALUES (%s)' % ( ", ".join(fields), diff --git a/tests/test_hub/test_list_archives.py b/tests/test_hub/test_list_archives.py index 1f529ee..60694af 100644 --- a/tests/test_hub/test_list_archives.py +++ b/tests/test_hub/test_list_archives.py @@ -141,8 +141,8 @@ class TestListArchives(DBQueryTestCase): joins=['archivetypes on archiveinfo.type_id = archivetypes.id', 'btype ON archiveinfo.btype_id = btype.id', 'maven_archives ON archiveinfo.id = maven_archives.archive_id'], - clauses=['maven_archives.group_id = %(group_id)s', - 'maven_archives.artifact_id = %(artifact_id)s', + clauses=['maven_archives.artifact_id = %(artifact_id)s', + 'maven_archives.group_id = %(group_id)s', 'maven_archives.version = %(version)s'], values={'group_id': 'gid', 'artifact_id': 'aid', @@ -171,13 +171,15 @@ class TestListArchives(DBQueryTestCase): 'platforms': 'all', 'flags': ['A', 'B']}) self.assertLastQueryEqual(tables=['archiveinfo'], - joins=['archivetypes on archiveinfo.type_id = archivetypes.id', + joins=sorted([ + 'archivetypes on archiveinfo.type_id = archivetypes.id', 'btype ON archiveinfo.btype_id = btype.id', - 'win_archives ON archiveinfo.id = win_archives.archive_id'], - clauses=['win_archives.relpath = %(relpath)s', + 'win_archives ON archiveinfo.id = win_archives.archive_id']), + clauses=sorted([ + 'win_archives.relpath = %(relpath)s', r"platforms ~ E'\\mall\\M'", r"flags ~ E'\\mA\\M'", - r"flags ~ E'\\mB\\M'"], + r"flags ~ E'\\mB\\M'"]), values={'relpath': 'somerelpath'}, colsByAlias={'relpath': 'win_archives.relpath', 'platforms': 'win_archives.platforms', diff --git a/tests/test_hub/test_list_channels.py b/tests/test_hub/test_list_channels.py index 595e05a..78149e7 100644 --- a/tests/test_hub/test_list_channels.py +++ b/tests/test_hub/test_list_channels.py @@ -37,10 +37,10 @@ class TestListChannels(unittest.TestCase): self.assertEqual(len(self.queries), 1) query = self.queries[0] self.assertEqual(query.tables, ['channels']) - self.assertEqual(query.aliases, ('name', 'id')) + self.assertEqual(query.aliases, ['id', 'name']) self.assertEqual(query.joins, None) self.assertEqual(query.values, {}) - self.assertEqual(query.columns, ('channels.name', 'channels.id')) + self.assertEqual(query.columns, ['channels.id', 'channels.name']) self.assertEqual(query.clauses, None) def test_host(self): @@ -54,10 +54,10 @@ class TestListChannels(unittest.TestCase): 'host_channels.host_id = %(host_id)s' ] self.assertEqual(query.tables, ['host_channels']) - self.assertEqual(query.aliases, ('name', 'id')) + self.assertEqual(query.aliases, ['id', 'name']) self.assertEqual(query.joins, joins) self.assertEqual(query.values, {'host_id': 1234}) - self.assertEqual(query.columns, ('channels.name', 'channels.id')) + self.assertEqual(query.columns, ['channels.id', 'channels.name']) self.assertEqual(query.clauses, clauses) def test_host_and_event(self): @@ -71,10 +71,10 @@ class TestListChannels(unittest.TestCase): 'host_channels.host_id = %(host_id)s', ] self.assertEqual(query.tables, ['host_channels']) - self.assertEqual(query.aliases, ('name', 'id')) + self.assertEqual(query.aliases, ['id', 'name']) self.assertEqual(query.joins, joins) self.assertEqual(query.values, {'host_id': 1234}) - self.assertEqual(query.columns, ('channels.name', 'channels.id')) + self.assertEqual(query.columns, ['channels.id', 'channels.name']) self.assertEqual(query.clauses, clauses) def test_event_only(self): diff --git a/tests/test_hub/test_list_hosts.py b/tests/test_hub/test_list_hosts.py index 60161e7..a2b8ecd 100644 --- a/tests/test_hub/test_list_hosts.py +++ b/tests/test_hub/test_list_hosts.py @@ -59,9 +59,9 @@ class TestListHosts(unittest.TestCase): self.assertEqual(query.joins, ['host ON host.id = host_config.host_id', 'host_channels ON host.id = host_channels.host_id']) self.assertEqual(query.clauses, [ - 'host_config.active IS TRUE', - 'host_channels.channel_id = %(channelID)i', 'host_channels.active IS TRUE', + 'host_channels.channel_id = %(channelID)i', + 'host_config.active IS TRUE', ]) def test_list_hosts_single_arch(self): @@ -71,7 +71,8 @@ class TestListHosts(unittest.TestCase): query = self.queries[0] self.assertEqual(query.tables, ['host_config']) self.assertEqual(query.joins, ['host ON host.id = host_config.host_id']) - self.assertEqual(query.clauses, ['host_config.active IS TRUE',r"""(arches ~ E'\\mx86_64\\M')"""]) + self.assertEqual(query.clauses, [r"""(arches ~ E'\\mx86_64\\M')""", + 'host_config.active IS TRUE']) def test_list_hosts_multi_arch(self): self.exports.listHosts(arches=['x86_64', 's390']) @@ -80,7 +81,9 @@ class TestListHosts(unittest.TestCase): query = self.queries[0] self.assertEqual(query.tables, ['host_config']) self.assertEqual(query.joins, ['host ON host.id = host_config.host_id']) - self.assertEqual(query.clauses, ['host_config.active IS TRUE',r"""(arches ~ E'\\mx86_64\\M' OR arches ~ E'\\ms390\\M')"""]) + self.assertEqual(query.clauses, [ + r"""(arches ~ E'\\mx86_64\\M' OR arches ~ E'\\ms390\\M')""", + 'host_config.active IS TRUE']) def test_list_hosts_bad_arch(self): with self.assertRaises(koji.GenericError): @@ -111,7 +114,7 @@ class TestListHosts(unittest.TestCase): query = self.queries[0] self.assertEqual(query.tables, ['host_config']) self.assertEqual(query.joins, ['host ON host.id = host_config.host_id']) - self.assertEqual(query.clauses, ['host_config.active IS TRUE','enabled IS TRUE']) + self.assertEqual(query.clauses, ['enabled IS TRUE', 'host_config.active IS TRUE']) def test_list_hosts_disabled(self): self.exports.listHosts(enabled=0) @@ -120,4 +123,4 @@ class TestListHosts(unittest.TestCase): query = self.queries[0] self.assertEqual(query.tables, ['host_config']) self.assertEqual(query.joins, ['host ON host.id = host_config.host_id']) - self.assertEqual(query.clauses, ['host_config.active IS TRUE','enabled IS FALSE']) + self.assertEqual(query.clauses, ['enabled IS FALSE', 'host_config.active IS TRUE']) diff --git a/tests/test_hub/test_notifications.py b/tests/test_hub/test_notifications.py index 0cea57c..d45c138 100644 --- a/tests/test_hub/test_notifications.py +++ b/tests/test_hub/test_notifications.py @@ -72,13 +72,13 @@ class TestNotifications(unittest.TestCase): # only query to watchers self.assertEqual(len(self.queries), 1) q = self.queries[0] - self.assertEqual(q.columns, ('email',)) + self.assertEqual(q.columns, ['email']) self.assertEqual(q.tables, ['build_notifications']) - self.assertEqual(q.clauses, [ 'status = %(users_status)i', - 'usertype IN %(users_usertypes)s', - 'package_id IS NULL', + self.assertEqual(q.clauses, ['package_id IS NULL', + 'status = %(users_status)i', + 'success_only = FALSE', 'tag_id IS NULL', - 'success_only = FALSE']) + 'usertype IN %(users_usertypes)s']) self.assertEqual(q.joins, ['JOIN users ON build_notifications.user_id = users.id']) self.assertEqual(q.values['state'], state) self.assertEqual(q.values['build'], build) @@ -96,13 +96,13 @@ class TestNotifications(unittest.TestCase): # there should be only query to watchers self.assertEqual(len(self.queries), 1) q = self.queries[0] - self.assertEqual(q.columns, ('email',)) + self.assertEqual(q.columns, ['email']) self.assertEqual(q.tables, ['build_notifications']) - self.assertEqual(q.clauses, ['status = %(users_status)i', - 'usertype IN %(users_usertypes)s', - 'package_id = %(package_id)i OR package_id IS NULL', + self.assertEqual(q.clauses, ['package_id = %(package_id)i OR package_id IS NULL', + 'status = %(users_status)i', + 'success_only = FALSE', 'tag_id IS NULL', - 'success_only = FALSE']) + 'usertype IN %(users_usertypes)s']) self.assertEqual(q.joins, ['JOIN users ON build_notifications.user_id = users.id']) self.assertEqual(q.values['package_id'], build['package_id']) self.assertEqual(q.values['state'], state) @@ -134,19 +134,19 @@ class TestNotifications(unittest.TestCase): } emails = kojihub.get_notification_recipients(build, tag_id, state) - self.assertEqual(emails, ['owner_name@test.domain.com', 'pkg_owner_name@test.domain.com']) + self.assertEqual(sorted(emails), ['owner_name@test.domain.com', 'pkg_owner_name@test.domain.com']) # there should be only query to watchers self.assertEqual(len(self.queries), 1) q = self.queries[0] - self.assertEqual(q.columns, ('email',)) + self.assertEqual(q.columns, ['email']) self.assertEqual(q.tables, ['build_notifications']) - self.assertEqual(q.clauses, ['status = %(users_status)i', - 'usertype IN %(users_usertypes)s', - 'package_id = %(package_id)i OR package_id IS NULL', + self.assertEqual(q.clauses, ['package_id = %(package_id)i OR package_id IS NULL', + 'status = %(users_status)i', + 'success_only = FALSE', 'tag_id = %(tag_id)i OR tag_id IS NULL', - 'success_only = FALSE']) + 'usertype IN %(users_usertypes)s']) self.assertEqual(q.joins, ['JOIN users ON build_notifications.user_id = users.id']) self.assertEqual(q.values['package_id'], build['package_id']) self.assertEqual(q.values['state'], state)