Move mapping tests into own dir; start refactoring

This commit is contained in:
Sergey Golitsynskiy
2021-10-21 18:50:25 -04:00
parent a834b54039
commit e66454734a
5 changed files with 20 additions and 21 deletions
+19
View File
@@ -0,0 +1,19 @@
def collection_consists_of_objects(collection, *objects):
"""
Returns True iff list(collection) == list(objects), where object equality is determined
by primary key equality: object1.id == object2.id.
"""
if len(collection) != len(objects): # False if lengths are different
return False
if not collection: # True if both are empty
return True
# Sort, then compare each member by its 'id' attribute, which must be its primary key.
collection.sort(key=lambda item: item.id)
objects = list(objects)
objects.sort(key=lambda item: item.id)
for item1, item2 in zip(collection, objects):
if item1.id is None or item2.id is None or item1.id != item2.id:
return False
return True
@@ -72,6 +72,7 @@ from sqlalchemy import (
)
import galaxy.model.mapping as mapping
from .common import collection_consists_of_objects
class BaseTest:
@@ -7483,27 +7484,6 @@ def get_unique_value():
return uuid4().hex
def collection_consists_of_objects(collection, *objects):
"""
Returns True iff list(collection) == list(objects), where object equality is determined
by primary key equality: object1.id == object2.id.
"""
if len(collection) != len(objects): # False if lengths are different
return False
if not collection: # True if both are empty
return True
# Sort, then compare each member by its 'id' attribute, which must be its primary key.
collection.sort(key=lambda item: item.id)
objects = list(objects)
objects.sort(key=lambda item: item.id)
for item1, item2 in zip(collection, objects):
if item1.id is None or item2.id is None or item1.id != item2.id:
return False
return True
def _run_average_rating_test(session, obj, user, obj_rating_association_factory):
# obj has been expunged; to access its deferred properties,
# it needs to be added back to the session.