From 57d00b8c8b90717022e9b04691c5c1f1eab5ca7c Mon Sep 17 00:00:00 2001 From: Adrian Cederberg Date: Thu, 5 Sep 2024 13:29:06 -0600 Subject: [PATCH] feature(models): Tests pass with ids removed. --- src/captura/controllers/access.py | 4 +-- src/captura/controllers/create.py | 26 +++++++------- src/captura/controllers/delete.py | 8 ++--- src/captura/schemas.py | 4 --- src/captura/util.py | 1 - src/captura/views/assignments.py | 4 +-- src/captura/views/documents.py | 2 +- src/simulatus/__init__.py | 6 ++-- src/simulatus/reports.py | 12 +++---- tests/test_controllers/test_access.py | 14 ++++---- tests/test_controllers/test_assoc.py | 6 ++-- tests/test_dummy.py | 34 ++++++++++--------- tests/test_models.py | 16 ++++----- .../test_assignments_collections_unit.py | 14 ++++---- .../test_assignments_documents_unit.py | 16 ++++----- tests/test_views/test_collections_unit.py | 12 +++---- .../test_views/test_grants_documents_unit.py | 34 +++++++++---------- tests/test_views/test_grants_users_unit.py | 4 +-- 18 files changed, 107 insertions(+), 110 deletions(-) diff --git a/src/captura/controllers/access.py b/src/captura/controllers/access.py index 1affab8..bbd4b34 100644 --- a/src/captura/controllers/access.py +++ b/src/captura/controllers/access.py @@ -488,7 +488,7 @@ def check_one(collection: Collection) -> Collection: match self.method: case H.GET if allow_public: - if not collection.public and collection.id_user != token_user.id: + if not collection.public and collection.uuid_user != token_user.uuid: raise ErrAccessCollection.httpexception( "_msg_private", 403, @@ -497,7 +497,7 @@ def check_one(collection: Collection) -> Collection: ) return collection case H.GET | H.POST | H.DELETE | H.PUT | H.PATCH: - if token_user.id != collection.id_user: + if token_user.uuid != collection.uuid_user: raise ErrAccessCollection.httpexception( "_msg_modify", 403, diff --git a/src/captura/controllers/create.py b/src/captura/controllers/create.py index 84c46fb..4cf3a69 100644 --- a/src/captura/controllers/create.py +++ b/src/captura/controllers/create.py @@ -332,14 +332,14 @@ def create_assignment( data: Data[ResolvedAssignmentDocument] | Data[ResolvedAssignmentCollection], target: Collection | Document, ) -> Assignment: - id_source_name = f"id_{data.data.kind_source.name}" - id_target_name = f"id_{data.data.kind_target.name}" - id_source_value = data.data.source.id # type: ignore + uuid_source_name = f"uuid_{data.data.kind_source.name}" + uuid_target_name = f"uuid_{data.data.kind_target.name}" + uuid_source_value = data.data.source.uuid # type: ignore kwargs = { "uuid": secrets.token_urlsafe(8), - id_source_name: id_source_value, - id_target_name: target.id, + uuid_source_name: uuid_source_value, + uuid_target_name: target.uuid, } return Assignment( **kwargs, @@ -414,17 +414,17 @@ def create_grant( case bad: raise ValueError(f"Invalid source `{bad}`.") - id_source_name = f"id_{data.data.kind_source.name}" - id_target_name = f"id_{data.data.kind_target.name}" - id_source_value = data.data.source.id # type: ignore + uuid_source_name = f"uuid_{data.data.kind_source.name}" + uuid_target_name = f"uuid_{data.data.kind_target.name}" + uuid_source_value = data.data.source.uuid # type: ignore kwargs = { "uuid": secrets.token_urlsafe(8), "uuid_parent": grant_parent_uuid, "pending_from": pending_from, "pending": True, - id_source_name: id_source_value, - id_target_name: target.id, + uuid_source_name: uuid_source_value, + uuid_target_name: target.uuid, } return Grant(**kwargs, **self.create_data.model_dump()) @@ -512,8 +512,8 @@ def document( data.data.token_user_grants = { user.uuid: ( Grant( - id_user=user.id, - id_document=document.id, + uuid_user=user.uuid, + uuid_document=document.uuid, level=Level.own, pending=False, pending_from=PendingFrom.created, @@ -748,7 +748,7 @@ def collection(self, data: Data[ResolvedCollection]) -> Data[ResolvedCollection] session, param.uuid_user, ) - collection.id_user = user.id + collection.uuid_user = user.uuid data.event.children.append( Event( **self.event_common, diff --git a/src/captura/controllers/delete.py b/src/captura/controllers/delete.py index e3e3622..f1b91aa 100644 --- a/src/captura/controllers/delete.py +++ b/src/captura/controllers/delete.py @@ -239,8 +239,8 @@ def split_assocs( model_assoc.uuid.in_(data.data.uuid_assoc), and_( model_target.uuid.in_(data.data.uuid_target), - getattr(model_assoc, "id_" + data.data.kind_source.name) - == data.data.source.id, + getattr(model_assoc, "uuid_" + data.data.kind_source.name) + == data.data.source.uuid, ), ) ) @@ -474,7 +474,7 @@ def _collection( .join(Document) .where( Document.uuid.in_(uuids(documents)), # type: ignore[type-var] - Assignment.id_collection == collection.id, + Assignment.uuid_collection == collection.uuid, ) ) assignments = { @@ -591,7 +591,7 @@ def _document( select(Assignment) .join(Collection) .where( - Assignment.id_document == document.id, + Assignment.uuid_document == document.uuid, Collection.uuid.in_(uuid_collections), ) ) diff --git a/src/captura/schemas.py b/src/captura/schemas.py index a15bae2..547ee99 100644 --- a/src/captura/schemas.py +++ b/src/captura/schemas.py @@ -201,7 +201,6 @@ class BaseSecondarySchema(BaseSchema): ... class BasePrimaryTableExtraSchema(BaseSchema): - id: fields.FieldID deleted: fields.FieldDeleted @@ -450,9 +449,6 @@ def enum_as_name(item: enum.Enum): # type: ignore # Metadata uuid_parent: Optional[fields.FieldUUID] = None - uuid_user_granter: Optional[fields.FieldUUID] = ( - None # should it reeally be optional - ) class GrantExtraSchema(GrantSchema): diff --git a/src/captura/util.py b/src/captura/util.py index 2cd0232..ec7c63b 100644 --- a/src/captura/util.py +++ b/src/captura/util.py @@ -49,7 +49,6 @@ def test_assets(cls, v: str) -> str: @classmethod def simulatus_assets(cls, v: str) -> str: o = path.join(PATH_SIMULATUS_ASSETS, v) - print(o) return o @classmethod diff --git a/src/captura/views/assignments.py b/src/captura/views/assignments.py index 93ef73e..0e21fb3 100644 --- a/src/captura/views/assignments.py +++ b/src/captura/views/assignments.py @@ -163,7 +163,7 @@ def get_assignments_document( select(Collection) .join(Assignment) .where( - Assignment.id_document == document.id, + Assignment.uuid_document == document.uuid, Assignment.deleted == false(), Collection.deleted == false(), ) @@ -288,7 +288,7 @@ def get_assignments_collection( .where( Document.deleted == false(), Assignment.deleted == false(), - Assignment.id_collection == collection.id, + Assignment.uuid_collection == collection.uuid, ) ) if uuid_document is not None: diff --git a/src/captura/views/documents.py b/src/captura/views/documents.py index 5d28078..0394fcb 100644 --- a/src/captura/views/documents.py +++ b/src/captura/views/documents.py @@ -105,7 +105,7 @@ def post_document( (document,) = data_create.data.documents grant, *_ = data_create.data.token_user_grants.values() - grant.id_document = document.id + grant.uuid_document = document.uuid create.session.add(grant) create.session.commit() diff --git a/src/simulatus/__init__.py b/src/simulatus/__init__.py index 7c7b32d..2f76527 100644 --- a/src/simulatus/__init__.py +++ b/src/simulatus/__init__.py @@ -633,7 +633,7 @@ def get_collections_retry_callback(self): session = self.session logger.warning("Calling `get_collections_retry_callback`.") - collection = Mk.collection(id_user=self.user.uuid) + collection = Mk.collection(uuid_user=self.user.uuid) session.add(collection) session.commit() session.refresh(collection) @@ -666,7 +666,7 @@ def callback(q): if order_by_document_count: q_ids = ( - select(Collection.uuid.label("id_collection")) + select(Collection.uuid.label("uuid_collection")) .join(Assignment) .group_by(Collection.uuid) .having(func.count(Assignment.uuid_document) > 0) @@ -912,7 +912,7 @@ def get_data_secondary( # NOTE: Get assocs. Assocs are always labeled by their model_assoc = resolve_model(Resolved.kind_assoc) # type: ignore - uuid_source_name = f"id_{Resolved._attr_name_source}" + uuid_source_name = f"uuid_{Resolved._attr_name_source}" uuid_target_name = f"uuid_{Resolved.kind_target.name}" q = ( diff --git a/src/simulatus/reports.py b/src/simulatus/reports.py index 12c93f0..79680fe 100644 --- a/src/simulatus/reports.py +++ b/src/simulatus/reports.py @@ -245,7 +245,7 @@ def content(self, v: Any) -> None: @classmethod def q_flat(cls, *additional_fields): return select( - User.id.label("id_user"), + User.uuid.label("id_user"), cls.uuid.label("uuid"), cls.uuid_parent.label("uuid_parent"), cls.uuid_user.label("uuid_user"), @@ -271,16 +271,16 @@ def q_content_data_count(cls, user: User | None = None): q_assignment = select(func.count(Assignment.uuid)) if user is not None: - q_document = select(Grant.id_document).where( + q_document = select(Grant.uuid_document).where( Grant.pending_from == fields.PendingFrom.created, - Grant.id_user == user.id, + Grant.uuid_user == user.uuid, ) q_document = select(func.count()).select_from(q_document.subquery()) q_collection = q_collection.join(User).where(User.uuid == user.uuid) q_assignment = q_assignment.join(Collection).where( - Collection.id_user == user.id + Collection.uuid_user == user.uuid ) - q_grant = q_grant.where(Grant.id_user == user.id) + q_grant = q_grant.where(Grant.uuid_user == user.uuid) q_event = select(func.count(Event.uuid)).where(Event.uuid_user == user.uuid) return select( @@ -335,7 +335,7 @@ def q_select(cls, user: User | None = None): .group_by(User.uuid, *_grant_agg) ) if user is not None: - q_reports_grants = q_reports_grants.where(Grant.id_user == user.id) + q_reports_grants = q_reports_grants.where(Grant.uuid_user == user.uuid) count_per_user: Any = literal_column("count_per_user") res_columns: Tuple[Any, ...] = ( diff --git a/tests/test_controllers/test_access.py b/tests/test_controllers/test_access.py index d31cb53..1086f9a 100644 --- a/tests/test_controllers/test_access.py +++ b/tests/test_controllers/test_access.py @@ -249,8 +249,8 @@ def test_d_fn(self) -> None: # quser = ( # select(Document.uuid) # .select_from(Document) -# .join(Grant, onclause=Grant.id_document == Document.id) -# .join(User, onclause=User.id == Grant.id_user) +# .join(Grant, onclause=Grant.uuid_document == Document.uuid) +# .join(User, onclause=User.uuid == Grant.uuid_user) # .where( # User.uuid == "000-000-000", # Grant.level >= level.value, @@ -528,7 +528,7 @@ def test_overloads(self, dummy: DummyProvider, count): def test_private(self, dummy: DummyProvider, count): (collection,) = dummy.get_collections(1) (collection_other,) = dummy.get_collections(1, other=True) - assert collection_other.id_user != dummy.user.id + assert collection_other.uuid_user != dummy.user.uuid collection.deleted, collection.public = False, False collection_other.deleted, collection_other.public = False, False @@ -560,7 +560,7 @@ def test_private(self, dummy: DummyProvider, count): # NOTE: User can access their own private collection res = access.collection(collection.uuid) - assert res.id_user == access.token_user.id + assert res.uuid_user == access.token_user.uuid assert collection.uuid == res.uuid # TODO: Private users cannot have public collections. How to resolve? @@ -662,7 +662,7 @@ def test_modify(self, dummy: DummyProvider, count): # Can when owner, impersonate owner. collection_res = access.collection(collection.uuid) assert collection_res.uuid == collection.uuid - assert collection.id_user == dummy.user.id + assert collection.uuid_user == dummy.user.uuid class TestAccessDocument(BaseTestAccess): @@ -675,8 +675,8 @@ def test_document_other(self, dummy: DummyProvider): for document in dummy.get_documents(25, other=True): n_grants = dummy.session.scalar( select(func.count(Grant.uuid)).where( - Grant.id_user == dummy.user.id, - Grant.id_document == document.id, + Grant.uuid_user == dummy.user.uuid, + Grant.uuid_document == document.uuid, ) ) assert not n_grants diff --git a/tests/test_controllers/test_assoc.py b/tests/test_controllers/test_assoc.py index ce58c4c..1620dd0 100644 --- a/tests/test_controllers/test_assoc.py +++ b/tests/test_controllers/test_assoc.py @@ -37,7 +37,7 @@ def test_split_assocs(self, dummy: DummyProvider, count: int): assoc := data.data.assoc.get(uuid_assoc) ) is not None, "All assocs should be in data." assert assoc.deleted is True - assert assoc.id_document == data.data.document.id + assert assoc.uuid_document == data.data.document.uuid uuid_target_deleted.add(assoc.uuid_collection) uuid_target_active = set() @@ -55,7 +55,7 @@ def test_split_assocs(self, dummy: DummyProvider, count: int): select(func.count(Assignment.uuid)) .join(Collection) .where( - Assignment.id_document == data.data.document.id, + Assignment.uuid_document == data.data.document.uuid, Collection.uuid == uuid_target, ) ) @@ -214,7 +214,7 @@ def test_grant_document(self, dummy: DummyProvider, count: int): .join(Document) .where( User.uuid.in_(data.data.uuid_users), - Document.id == data.data.document.id, + Document.uuid == data.data.document.uuid, ) ) assert session.scalar(q) == 0 diff --git a/tests/test_dummy.py b/tests/test_dummy.py index a77f969..1542629 100644 --- a/tests/test_dummy.py +++ b/tests/test_dummy.py @@ -43,7 +43,7 @@ def test_mk(self, dummy: DummyProvider, session: Session, count: int): # NOTE: Verify that collections exist. q = select(func.count(Collection.uuid)).where( - Collection.id_user == dummy.user.id + Collection.uuid_user == dummy.user.uuid ) assert (n := session.scalar(q)) is not None and n > 0 @@ -52,20 +52,20 @@ def test_mk(self, dummy: DummyProvider, session: Session, count: int): # items. (3) q = select(func.count(Grant.uuid)).where( - Grant.id_user == dummy.user.id, + Grant.uuid_user == dummy.user.uuid, Grant.pending_from == PendingFrom.created, ) assert (n := session.scalar(q)) is not None and n > 0 q = select(func.count(Grant.pending_from.distinct())) q = q.where( - Grant.id_user == dummy.user.id, + Grant.uuid_user == dummy.user.uuid, Grant.pending_from != PendingFrom.created, ) assert (n := session.scalar(q)) is not None and n > 0 q = select(func.count(Grant.level.distinct())) - q = q.where(Grant.id_user == dummy.user.id) + q = q.where(Grant.uuid_user == dummy.user.uuid) assert session.scalar(q) == 3 q = select(func.count(Grant.pending.distinct())) @@ -207,7 +207,7 @@ def test_get_documents(self, dummy: DummyProvider, count: int): select(Grant) .join(Document) .where( - Grant.id_user == dummy.user.id, + Grant.uuid_user == dummy.user.uuid, Document.uuid.in_(uuid_documents), ) ) @@ -239,7 +239,7 @@ def test_get_documents(self, dummy: DummyProvider, count: int): .join(Document) .where( Document.uuid.in_(uuid_documents), - Grant.id_user == dummy.user.id, + Grant.uuid_user == dummy.user.uuid, ) ) n_grants = dummy.session.scalar(q_grants) @@ -426,17 +426,17 @@ def test_get_data_grant_document(self, dummy: DummyProvider, count: int): # have one grant, the grant to this document. assert len(token_user_grants := data.data.token_user_grants) == 1 assert (gg := token_user_grants.get(dummy.user.uuid)) is not None - assert data.data.document.id == gg.id_document + assert data.data.document.uuid == gg.uuid_document # NOTE: There is not necessarily a grant for every user. Grants should # be indexed using user uuids. grants = data.data.grants - id_document = data.data.document.id + id_document = data.data.document.uuid uuid_user = uuids(data.data.users) uuid_user_has_grants = set(grants) assert uuid_user.issuperset(uuid_user_has_grants) - assert all(gg.id_document == id_document for gg in grants.values()) + assert all(gg.uuid_document == id_document for gg in grants.values()) def test_get_data_grant_user(self, dummy: DummyProvider, count: int): data = dummy.get_data_grant_user() @@ -451,7 +451,7 @@ def test_get_data_grant_user(self, dummy: DummyProvider, count: int): assert set(gg.uuid_document for gg in token_user_grants).issubset( uuids(data.data.documents) ) - assert all(gg.id_user == dummy.user.id for gg in token_user_grants) + assert all(gg.uuid_user == dummy.user.uuid for gg in token_user_grants) # NOTE: For now, grants and token user grants are always the same as # the data provided will always have a document owned by @@ -469,7 +469,9 @@ def test_get_data_assignment_collection(self, dummy: DummyProvider, count: int): assert set(aa.uuid_document for aa in assignments).issubset( uuids(data.data.documents) ) - assert all(aa.id_collection == data.data.collection.id for aa in assignments) + assert all( + aa.uuid_collection == data.data.collection.uuid for aa in assignments + ) def test_get_data_assignment_document(self, dummy: DummyProvider, count: int): data = dummy.get_data_assignment_document() @@ -480,7 +482,7 @@ def test_get_data_assignment_document(self, dummy: DummyProvider, count: int): assert set(aa.uuid_collection for aa in assignments).issubset( uuids(data.data.collections) ) - assert all(aa.id_document == data.data.document.id for aa in assignments) + assert all(aa.uuid_document == data.data.document.uuid for aa in assignments) # NOTE: Test passing of kwargs. data = dummy.get_data_assignment_document( @@ -513,7 +515,7 @@ def test_get_primary_retry(self, dummy: DummyProvider, count: int): """Verify that ``get_primary`` is robust.""" # NOTE: Delete dummy collections. - q_rm = delete(Collection).where(Collection.id_user == dummy.user.id) + q_rm = delete(Collection).where(Collection.uuid_user == dummy.user.uuid) session = dummy.session session.execute(q_rm) @@ -532,7 +534,7 @@ def test_get_primary_retry(self, dummy: DummyProvider, count: int): # NOTE: Delete dummy documents where the user is designated as the # ``creator`` and grants on remaining documents. q_documents_created = select(Document).where( - Grant.id_user == dummy.user.id, + Grant.uuid_user == dummy.user.uuid, Grant.pending_from == PendingFrom.created, ) for doc in session.scalars(q_documents_created): @@ -540,11 +542,11 @@ def test_get_primary_retry(self, dummy: DummyProvider, count: int): session.commit() - session.execute(delete(Grant).where(Grant.id_user == dummy.user.id)) + session.execute(delete(Grant).where(Grant.uuid_user == dummy.user.uuid)) session.commit() # NOTE: Confirm document and grant removal with db and `get_documents`. - q = select(func.count(Grant.uuid)).where(Grant.id_user == dummy.user.id) + q = select(func.count(Grant.uuid)).where(Grant.uuid_user == dummy.user.uuid) assert not session.scalar(q), "No grants should remain for dummy user." kwargs = GetPrimaryKwargs( diff --git a/tests/test_models.py b/tests/test_models.py index b7a0b6a..87e3ec3 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -178,7 +178,7 @@ def test_document_deletion(self, dummy_disposable: DummyProvider, count: int): ) # NOTE: Because there are not dummies. - # q_edit_uuids = select(Edit.uuid).where(Edit.id_document == document.id) + # q_edit_uuids = select(Edit.uuid).where(Edit.uuid_document == document.uuid) # uuid_edit = set(session.scalars(q_edit_uuids)) # --------------------------------------------------------------- # @@ -278,7 +278,7 @@ def test_user_deletion_collections( user = dummy.user uuid_collections = set( session.scalars( - select(Collection.uuid).where(Collection.id_user == user.id) + select(Collection.uuid).where(Collection.uuid_user == user.uuid) ) ) if not len(uuid_collections): @@ -309,7 +309,7 @@ def test_user_deletion_collections( # user = dummy.user # # uuid_edits = set( - # session.scalars(select(Edit.uuid).where(Edit.id_user == user.id)) + # session.scalars(select(Edit.uuid).where(Edit.uuid_user == user.uuid)) # ) # if not (n_edits := len(uuid_edits)): # n_no_edits += 1 @@ -353,7 +353,7 @@ def test_user_deletion_collections( # # NOTE: Get collections and edits. Collections should be deleted, # # edits should not be deleted unless they belong to one of the # # above documents. - # q_uuid_edit = select(Edit.uuid).where(Edit.id_user == user.id) + # q_uuid_edit = select(Edit.uuid).where(Edit.uuid_user == user.uuid) # uuid_edit = set(session.scalars(q_uuid_edit)) # # q_uuid_edit_uniq = q_uuid_edit.join(Document).where( @@ -361,7 +361,7 @@ def test_user_deletion_collections( # ) # uuid_edit_uniq = set(session.scalars(q_uuid_edit_uniq)) # - # q_uuid_collection = select(Collection.uuid).where(Collection.id_user == user.id) + # q_uuid_collection = select(Collection.uuid).where(Collection.uuid_user == user.uuid) # uuid_collection = set(session.scalars(q_uuid_collection)) # # session.delete(user) @@ -383,7 +383,7 @@ def test_q_select_documents( def get_grants(docs: Resolvable[Document]) -> Tuple[Grant, ...]: uuid_document = Document.resolve_uuid(session, docs) q = select(Grant).join(Document) - q = q.where(Document.uuid.in_(uuid_document), Grant.id_user == user.id) + q = q.where(Document.uuid.in_(uuid_document), Grant.uuid_user == user.uuid) return tuple(session.scalars(q)) def uuids(docs) -> Set[str]: @@ -542,8 +542,8 @@ def uuids(docs) -> Set[str]: pending_from=PendingFrom.created, pending=False, deleted=False, - id_user=dummy.user.id, - id_document=doc.id, + uuid_user=dummy.user.uuid, + uuid_document=doc.uuid, ) session.add(grant) diff --git a/tests/test_views/test_assignments_collections_unit.py b/tests/test_views/test_assignments_collections_unit.py index f840098..3b37151 100644 --- a/tests/test_views/test_assignments_collections_unit.py +++ b/tests/test_views/test_assignments_collections_unit.py @@ -93,7 +93,7 @@ async def test_forbidden_403( (collection,) = dummy.get_collections(1, GetPrimaryKwargs(deleted=False)) uuid_document = [secrets.token_urlsafe(9)] - collection.id_user = user_other.id + collection.uuid_user = user_other.uuid if self.method == H.GET: collection.public = False msg = ErrAccessCollection._msg_private @@ -181,7 +181,7 @@ async def test_success_200( select(Assignment) .join(Document) .where( - Assignment.id_collection == collection.id, + Assignment.uuid_collection == collection.uuid, Assignment.deleted == false(), Document.deleted == false(), ) @@ -366,13 +366,13 @@ async def test_success_200( (collection,) = dummy.get_collections(1) documents = dummy.get_documents(9, GetPrimaryKwargs(deleted=False), other=True) uuid_document_list = list(dd.uuid for dd in documents) - id_document_list = [dd.id for dd in documents] + id_document_list = [dd.uuid for dd in documents] assert (n_documents := len(uuid_document_list)) > 1 session.execute( delete(Assignment).where( - Assignment.id_document.in_(id_document_list), - Assignment.id_collection == collection.id, + Assignment.uuid_document.in_(id_document_list), + Assignment.uuid_collection == collection.uuid, ) ) session.commit() @@ -434,8 +434,8 @@ async def test_success_200( update(Assignment) .values(deleted=True) .where( - Assignment.id_document.in_(id_document_list[: n_documents - 2]), - Assignment.id_collection == collection.id, + Assignment.uuid_document.in_(id_document_list[: n_documents - 2]), + Assignment.uuid_collection == collection.uuid, ) ) session.commit() diff --git a/tests/test_views/test_assignments_documents_unit.py b/tests/test_views/test_assignments_documents_unit.py index fce1eec..1bbb91b 100644 --- a/tests/test_views/test_assignments_documents_unit.py +++ b/tests/test_views/test_assignments_documents_unit.py @@ -104,7 +104,7 @@ async def test_forbidden_403( session, level = dummy.session, Level.view (document,) = dummy.get_documents(level=level, n=1) (collection,) = dummy.get_collections(1) - session.merge(Assignment(id_document=document.id, id_collection=collection.id)) + session.merge(Assignment(uuid_document=document.uuid, uuid_collection=collection.uuid)) session.commit() grant = dummy.get_document_grant(document) @@ -146,7 +146,7 @@ async def test_forbidden_403( _ = session.add(document) assignment = session.scalar( - select(Assignment).where(Assignment.id_document == document.id).limit(1) + select(Assignment).where(Assignment.uuid_document == document.uuid).limit(1) ) assert assignment is not None @@ -179,7 +179,7 @@ async def test_success_200( (document,) = dummy.get_documents(level=Level.view, n=1) assignments = ( - Assignment(id_document=document.id, id_collection=cc.id) + Assignment(uuid_document=document.uuid, uuid_collection=cc.uuid) for cc in dummy.get_collections(10) ) tuple(map(session.merge, assignments)) @@ -196,7 +196,7 @@ async def test_success_200( select(Assignment.uuid) .join(Collection) .where( - Assignment.id_document == document.id, + Assignment.uuid_document == document.uuid, Assignment.deleted == false(), Collection.deleted == false(), ) @@ -268,7 +268,7 @@ async def test_success_200( assert len(collections) assignments = tuple( - Assignment(id_document=document.id, id_collection=cc.id, deleted=False) + Assignment(uuid_document=document.uuid, uuid_collection=cc.uuid, deleted=False) for cc in collections ) tuple(map(session.merge, assignments)) @@ -277,8 +277,8 @@ async def test_success_200( n_created = session.scalar( q := select(func.count(Assignment.uuid)).where( - Assignment.id_collection.in_([cc.id for cc in collections]), - Assignment.id_document == document.id, + Assignment.uuid_collection.in_([cc.uuid for cc in collections]), + Assignment.uuid_document == document.uuid, ) ) assert n_created == n_collections @@ -369,7 +369,7 @@ async def test_success_200( (document,) = dummy.get_documents(n=1, level=Level.own) # NOTE: Delete all assignments for this document. - q = delete(Assignment).where(Assignment.id_document == document.id) + q = delete(Assignment).where(Assignment.uuid_document == document.uuid) session.execute(q) session.commit() diff --git a/tests/test_views/test_collections_unit.py b/tests/test_views/test_collections_unit.py index 65d07dd..7052abb 100644 --- a/tests/test_views/test_collections_unit.py +++ b/tests/test_views/test_collections_unit.py @@ -115,7 +115,7 @@ async def test_forbidden_403( (collection,) = dummy.get_collections(n=1) collection.public = True collection.deleted = False - collection.id_user = user_other.id + collection.uuid_user = user_other.uuid session.add(collection) session.commit() @@ -199,8 +199,8 @@ async def test_success_200( # Test reading a public collection not ownend collection.public = True - collection.id_user = next( - uu.id for uu in dummy.get_users(2) if uu.uuid != dummy.user.uuid + collection.uuid_user = next( + uu.uuid for uu in dummy.get_users(2) if uu.uuid != dummy.user.uuid ) session.add(collection) session.commit() @@ -360,7 +360,7 @@ async def test_success_200( assert data.data.uuid_user == user.uuid # For next test. # NOTE: Transfer ownership. - user_other = next((uu for uu in dummy.get_users(2) if uu.id != user.id)) + user_other = next((uu for uu in dummy.get_users(2) if uu.uuid != user.uuid)) res = await fn(collection.uuid, uuid_user=user_other.uuid) if err := self.check_status(requests, res): raise err @@ -405,7 +405,7 @@ async def test_success_200( ): (collection,), session = dummy.get_collections(1), dummy.session assert not collection.deleted - assert collection.id_user == dummy.user.id + assert collection.uuid_user == dummy.user.uuid fn, fn_read = self.fn(requests), requests.collections.read fn_read_assignments = requests.assignments.collections.read @@ -415,7 +415,7 @@ async def test_success_200( .join(Collection) .join(Document) .where( - Collection.id == collection.id, + Collection.uuid == collection.uuid, Document.deleted == false(), Collection.deleted == false(), ) diff --git a/tests/test_views/test_grants_documents_unit.py b/tests/test_views/test_grants_documents_unit.py index 5be8166..af30d63 100644 --- a/tests/test_views/test_grants_documents_unit.py +++ b/tests/test_views/test_grants_documents_unit.py @@ -268,8 +268,8 @@ async def test_deleted_410( session.refresh(document) grant = Grant( - id_document=document.id, - id_user=dummy.user.id, + uuid_document=document.uuid, + uuid_user=dummy.user.uuid, level=Level.own, pending=False, deleted=False, @@ -284,7 +284,7 @@ async def test_deleted_410( # users = dummy.get_users(n=3) # uuid_user = uuids(users) - # grants = tuple(Grant(id_document=document.id, id_user=uu.id) for uu in users) + # grants = tuple(Grant(id_document=document.uuid, uuid_user=uu.uuid) for uu in users) # tuple(map(session.merge, grants)) errhttp = mwargs( @@ -395,8 +395,8 @@ async def test_success_200_pending( session.refresh(document) grant = Grant( - id_document=document.id, - id_user=dummy.user.id, + uuid_document=document.uuid, + uuid_user=dummy.user.uuid, level=Level.own, pending=False, deleted=False, @@ -405,8 +405,8 @@ async def test_success_200_pending( users = dummy.get_users(10, other=True) grants = [ Grant( - id_document=document.id, - id_user=user.id, + uuid_document=document.uuid, + uuid_user=user.uuid, level=Level.view, pending=index % 2, deleted=False, @@ -716,8 +716,8 @@ async def test_forbidden_403_cannot_reject_other_owner( users = dummy.get_users(other=True, n=5) session.add( grant := Grant( - id_user=dummy.user.id, - id_document=document.id, + uuid_user=dummy.user.uuid, + uuid_document=document.uuid, level=Level.own, pending=False, deleted=False, @@ -725,8 +725,8 @@ async def test_forbidden_403_cannot_reject_other_owner( children=( grants := list( Grant( - id_user=user.id, - id_document=document.id, + uuid_user=user.uuid, + uuid_document=document.uuid, level=Level.own, pending=False, deleted=False, @@ -789,8 +789,8 @@ async def test_forbidden_403_pending_from( uuid_user = [user_other.uuid] session.add(user_other) q_grant_other = select(Grant).where( - Grant.id_document == document.id, - Grant.id_user == user_other.id, + Grant.uuid_document == document.uuid, + Grant.uuid_user == user_other.uuid, ) grant_other_init = session.scalar(q_grant_other) if grant_other_init is not None: @@ -799,8 +799,8 @@ async def test_forbidden_403_pending_from( session.add( grant_other := Grant( - id_user=user_other.id, - id_document=document.id, + uuid_user=user_other.uuid, + uuid_document=document.uuid, level=Level.view, pending=True, deleted=False, @@ -866,8 +866,8 @@ async def test_success_200( session.add( Grant( - id_user=dummy.user.id, - id_document=document.id, + uuid_user=dummy.user.uuid, + uuid_document=document.uuid, level=Level.own, pending=False, pending_from=PendingFrom.created, diff --git a/tests/test_views/test_grants_users_unit.py b/tests/test_views/test_grants_users_unit.py index d03795b..05e69a4 100644 --- a/tests/test_views/test_grants_users_unit.py +++ b/tests/test_views/test_grants_users_unit.py @@ -283,8 +283,8 @@ async def test_bad_request_400( documents = dummy.get_documents(other=True, n=5) grants = tuple( Grant( - id_document=document.id, - id_user=dummy.user.id, + uuid_document=document.uuid, + uuid_user=dummy.user.uuid, level=Level.view, deleted=True, pending=False,