From eb6c7bea070bfa1d123ab26b5551c4b157f6bcc3 Mon Sep 17 00:00:00 2001 From: Adrian Cederberg Date: Thu, 5 Sep 2024 12:30:57 -0600 Subject: [PATCH] wip(models): Removed id fields from models. ``simulatus apply`` and ``simulatus initialize`` work. Moving to uuids only since using autoincrement primary keys can result in race conditions. Removed ``uuid_*`` properties on ORM classes that had to populate it from ids. Crude updates of queries. Moved simulatus assets from ``./tests/assets`` to ``./src/simulatus/assets`` and added necessary path methods. --- src/captura/models.py | 130 ++++--------- src/captura/util.py | 12 +- src/legere/__init__.py | 2 +- src/simulatus/__init__.py | 87 ++++----- .../simulatus}/assets/assignment.yaml | 28 +-- .../simulatus}/assets/collection.yaml | 22 +-- {tests => src/simulatus}/assets/document.yaml | 9 +- {tests => src/simulatus}/assets/event.yaml | 0 {tests => src/simulatus}/assets/grant.yaml | 64 +++---- {tests => src/simulatus}/assets/user.yaml | 6 +- tests/assets/edit.yaml | 175 ------------------ 11 files changed, 148 insertions(+), 387 deletions(-) rename {tests => src/simulatus}/assets/assignment.yaml (50%) rename {tests => src/simulatus}/assets/collection.yaml (67%) rename {tests => src/simulatus}/assets/document.yaml (99%) rename {tests => src/simulatus}/assets/event.yaml (100%) rename {tests => src/simulatus}/assets/grant.yaml (73%) rename {tests => src/simulatus}/assets/user.yaml (95%) delete mode 100644 tests/assets/edit.yaml diff --git a/src/captura/models.py b/src/captura/models.py index 4be8a90..949e38d 100644 --- a/src/captura/models.py +++ b/src/captura/models.py @@ -109,8 +109,15 @@ index=True, unique=True, ) +_uuid_primary = mapped_column( + String(36), + default=lambda: str(uuid.uuid4()), + index=True, + primary_key=True, +) MappedColumnUUID = Annotated[str, _uuid] MappedColumnUUIDUnique = Annotated[str, _uuid_unique] +MappedColumnUUIDPrimary = Annotated[str, _uuid_primary] MappedColumnDeleted = Annotated[bool, mapped_column(default=False)] @@ -125,7 +132,7 @@ class KindSelect(str, enum.Enum): class Base(DeclarativeBase): - uuid: Mapped[MappedColumnUUIDUnique] + uuid: Mapped[MappedColumnUUIDPrimary] deleted: Mapped[MappedColumnDeleted] __kind__: ClassVar[KindObject] @@ -700,42 +707,22 @@ class AssocCollectionDocument(Base): # NOTE: Since this object supports soft deletion (for the deletion grace # period that will later be implemented) deleted is included. # deleted: Mapped[MappedColumnDeleted] - id_document: Mapped[int] = mapped_column( + uuid_document: Mapped[int] = mapped_column( ForeignKey( - "documents.id", + "documents.uuid", ondelete="CASCADE", ), primary_key=True, ) - id_collection: Mapped[int] = mapped_column( + uuid_collection: Mapped[int] = mapped_column( ForeignKey( - "collections.id", + "collections.uuid", ondelete="CASCADE", ), primary_key=True, ) - @property - def uuid_document(self) -> str: - session = self.get_session() - res = session.execute( - select(Document.uuid).where(Document.id == self.id_document) - ).scalar() - if res is None: - raise ValueError("Inconcievable!") - return res - - @property - def uuid_collection(self) -> str: - session = self.get_session() - res = session.execute( - select(Collection.uuid).where(Collection.id == self.id_collection) - ).scalar() - if res is None: - raise ValueError("Inconcievable!") - return res - @classmethod def resolve_target_kind( cls, @@ -809,16 +796,16 @@ class AssocUserDocument(Base): cascade="all, delete", ) - id_user: Mapped[int] = mapped_column( + uuid_user: Mapped[int] = mapped_column( ForeignKey( - "users.id", + "users.uuid", ondelete="CASCADE", ), key="a", ) - id_document: Mapped[int] = mapped_column( + uuid_document: Mapped[int] = mapped_column( ForeignKey( - "documents.id", + "documents.uuid", ondelete="CASCADE", ), key="b", @@ -831,29 +818,12 @@ class AssocUserDocument(Base): __table_args__ = (UniqueConstraint("a", "b", name="_grant_vector"),) - @property - def uuid_document(self) -> str: - session = self.get_session() - res = session.execute( - select(Document.uuid).where(Document.id == self.id_document) - ).scalar() - if res is None: - raise ValueError("Inconcievable!") - return res - - @property - def uuid_user(self) -> str: - session = self.get_session() - res = session.execute(select(User.uuid).where(User.id == self.id_user)).scalar() - if res is None: - raise ValueError("Inconcievable!") - return res @property def uuid_user_granter(self) -> str: session = self.get_session() res = session.execute( - select(User.uuid).where(User.id == self.id_user_granter) # type: ignore + select(User.uuid).where(User.uuid == self.uuid_user_granter) # type: ignore ).scalar() if res is None: raise ValueError("Inconcievable!") @@ -912,11 +882,6 @@ class User(SearchableTableMixins, Base): __tablename__ = "users" __kind__ = KindObject.user - id: Mapped[int] = mapped_column( - primary_key=True, - autoincrement=True, - ) - # NOTE: subject should be a sha256 of a token subject. For test tokens, # the subject should be the sha sum of their uuid. subject: Mapped[str | None] = mapped_column(String(64), unique=True, nullable=True) @@ -936,7 +901,7 @@ class User(SearchableTableMixins, Base): collections: Mapped[List["Collection"]] = relationship( cascade="all, delete", back_populates="user", - primaryjoin="User.id==Collection.id_user", + primaryjoin="User.uuid==Collection.uuid_user", passive_deletes=True, ) @@ -988,16 +953,16 @@ def q_conds_grants( ): cond = list() if n_owners is None: - cond.append(AssocUserDocument.id_user == self.id) + cond.append(AssocUserDocument.uuid_user == self.uuid) if exclude_deleted: cond.append(Grant.deleted == false()) cond.append(Document.deleted == false()) if document_uuids is not None: - q_ids = select(Document.id) + q_ids = select(Document.uuid) q_ids = q_ids.where(Document.uuid.in_(document_uuids)) - cond.append(AssocUserDocument.id_document.in_(q_ids)) + cond.append(AssocUserDocument.uuid_document.in_(q_ids)) if level is not None: level = Level.resolve(level) @@ -1035,18 +1000,6 @@ def q_select_grants( exclude_pending: bool = True, pending_from: PendingFrom | None = None, ) -> Select: - # NOTE: Attempting to make roughly the following query: - # - # .. code:: - # - # SELECT users.uuid, - # documents.uuid, - # _assocs_user_documents.level - # FROM users - # JOIN _assocs_user_documents - # ON _assocs_user_documents.id_user=users.id - # JOIN documents - # ON _assocs_user_documents.id_document = documents.id; q = select(Grant).select_from(User).join(AssocUserDocument).join(Document) conds = self.q_conds_grants( document_uuids, @@ -1101,16 +1054,16 @@ def q_select_documents( raise ValueError(msg.format(kind_select)) aq = aliased(selected, q.subquery()) - q = select(aq).join(Grant).where(Grant.id_user == self.id) + q = select(aq).join(Grant).where(Grant.uuid_user == self.uuid) - cond_count = func.count(Grant.id_user) + cond_count = func.count(Grant.uuid_user) cond_having: ColumnElement[bool] = ( (cond_count < n_owners) if not n_owners_levelsets else (cond_count == n_owners) ) - q = q.group_by(Document.id).having(cond_having) + q = q.group_by(Document.uuid).having(cond_having) return q @@ -1142,7 +1095,7 @@ def q_conds_collections( uuid_collection: Set[str] | None = None, exclude_deleted: bool = True, ): - conds = and_(Collection.id_user == User.id) + conds = and_(Collection.uuid_user == User.uuid) if uuid_collection is not None: conds = and_(conds, Collection.uuid.in_(uuid_collection)) if exclude_deleted: @@ -1278,11 +1231,10 @@ class Collection(SearchableTableMixins, Base): __tablename__ = "collections" __kind__ = KindObject.collection - id_user: Mapped[int] = mapped_column( - ForeignKey("users.id", ondelete="CASCADE"), + uuid_user: Mapped[int] = mapped_column( + ForeignKey("users.uuid", ondelete="CASCADE"), nullable=False, ) - id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) name: Mapped[str] = mapped_column(String(fields.LENGTH_NAME)) description: Mapped[str] = mapped_column( String(fields.LENGTH_DESCRIPTION), @@ -1293,7 +1245,7 @@ class Collection(SearchableTableMixins, Base): ) user: Mapped[User] = relationship( - primaryjoin="User.id==Collection.id_user", + primaryjoin="User.uuid==Collection.uuid_user", back_populates="collections", ) @@ -1305,15 +1257,6 @@ class Collection(SearchableTableMixins, Base): # cascade="all, delete", ) - @property - def uuid_user(self) -> str: - session = self.get_session() - q = select(User.uuid).where(User.id == self.id_user) - res = session.execute(q).scalar() - if res is None: - raise ValueError("Inconcievable!") - return res - def q_conds_assignment( self, document_uuids: Set[str] | None = None, @@ -1321,12 +1264,11 @@ def q_conds_assignment( ) -> ColumnElement[bool]: # NOTE: To add the conditions for document select (like level) use # `q_conds_assoc`. - cond = and_(AssocCollectionDocument.id_collection == self.id) + cond = and_(AssocCollectionDocument.uuid_collection == self.uuid) if exclude_deleted: cond = and_(cond, AssocCollectionDocument.deleted == false()) if document_uuids is not None: - document_ids = Document.q_select_ids(document_uuids) - cond = and_(cond, AssocCollectionDocument.id_document.in_(document_ids)) + cond = and_(cond, AssocCollectionDocument.uuid_document.in_(document_uuids)) # cond = and_(cond, self.q_conds(document_uuids, exclude_deleted)) return cond @@ -1380,7 +1322,6 @@ class Document(SearchableTableMixins, Base): __tablename__ = "documents" __kind__ = KindObject.document - id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) name: Mapped[str] = mapped_column(String(fields.LENGTH_NAME)) description: Mapped[str] = mapped_column( String(fields.LENGTH_DESCRIPTION), @@ -1421,7 +1362,7 @@ def q_conds_grants( :param exclude_pending: Specify if all grants should be returned regardless of their pending status. """ - cond = AssocUserDocument.id_document == self.id + cond = AssocUserDocument.uuid_document == self.uuid if exclude_deleted: cond = and_( cond, @@ -1431,8 +1372,8 @@ def q_conds_grants( if user_uuids is not None: cond = and_( cond, - AssocUserDocument.id_user.in_( - select(User.id).where(User.uuid.in_(user_uuids)) + AssocUserDocument.uuid_user.in_( + select(User.uuid).where(User.uuid.in_(user_uuids)) ), ) if level is not None: @@ -1515,15 +1456,14 @@ def q_conds_assignment( ) -> ColumnElement[bool]: # NOTE: To add the conditions for document select (like level) use # `q_conds_assoc`. - cond = and_(AssocCollectionDocument.id_document == self.id) + cond = and_(AssocCollectionDocument.uuid_document == self.uuid) if exclude_deleted: cond = and_( cond, AssocCollectionDocument.deleted == false(), ) if collection_uuids is not None: - collection_ids = Collection.q_select_ids(collection_uuids) - cond = and_(cond, AssocCollectionDocument.id_collection.in_(collection_ids)) + cond = and_(cond, AssocCollectionDocument.uuid_collection.in_(collection_uuids)) return cond diff --git a/src/captura/util.py b/src/captura/util.py index 37e2231..2cd0232 100644 --- a/src/captura/util.py +++ b/src/captura/util.py @@ -46,6 +46,12 @@ def tests(cls, v: str) -> str: def test_assets(cls, v: str) -> str: return path.join(PATH_TESTS_ASSETS, v) + @classmethod + def simulatus_assets(cls, v: str) -> str: + o = path.join(PATH_SIMULATUS_ASSETS, v) + print(o) + return o + @classmethod def docker(cls, v: str) -> str: return path.join(PATH_DOCKER, v) @@ -60,8 +66,10 @@ def plugins(cls, v: str) -> str: PATH_BASE: str = path.realpath(path.join(path.dirname(__file__), "..", "..")) -PATH_APP: str = path.join(PATH_BASE, "src/app") -PATH_CLIENT: str = path.join(PATH_BASE, "src/client") +PATH_APP: str = path.join(PATH_BASE, "src/captura") +PATH_SIMULATUS = path.join(PATH_BASE, "src/simulatus") +PATH_SIMULATUS_ASSETS = path.join(PATH_SIMULATUS, "assets") +PATH_CLIENT: str = path.join(PATH_BASE, "src/legere") PATH_CONFIG: str = path.join(PATH_BASE, "configs") PATH_DOCKER: str = path.join(PATH_BASE, "docker") PATH_PLUGINS: str = path.join(PATH_BASE, "plugins") diff --git a/src/legere/__init__.py b/src/legere/__init__.py index 11710e8..c68cce4 100644 --- a/src/legere/__init__.py +++ b/src/legere/__init__.py @@ -442,7 +442,7 @@ def db(cls, _context: typer.Context): console = context.console_handler.console client = docker.DockerClient() # type: ignore - if (container := client.containers.get("captura-db")) is None: + if (container := client.containers.get("captura-db-1")) is None: console.print("[red]Docker compose project is not running.") raise typer.Exit(1) diff --git a/src/simulatus/__init__.py b/src/simulatus/__init__.py index a203e09..7c7b32d 100644 --- a/src/simulatus/__init__.py +++ b/src/simulatus/__init__.py @@ -162,8 +162,8 @@ def mk_assignments( logger.debug("Making assignments...") assignments: Tuple[Assignment, ...] = tuple( Assignment( - id_document=document.id, - id_collection=collection.id, + uuid_document=document.uuid, + uuid_collection=collection.uuid, deleted=False, ) for collection in collections @@ -188,15 +188,15 @@ def mk_grants( # statement be emitted in addition to these queries. # # TLDR: Do not use ``session.merge``, just use ``DELETE`` or use - # options to avoid causing duplicate ``(id_user, id_document)`` + # options to avoid causing duplicate ``(uuid_user, uuid_document)`` # keys. if not exclude_grants_create: logger.debug("Making grants for documents created by self.") grants_created = tuple( Grant( level=Level.own, - id_user=self.user.id, - id_document=document.id, + uuid_user=self.user.uuid, + uuid_document=document.uuid, deleted=False, pending=False, pending_from=PendingFrom.created, @@ -212,17 +212,17 @@ def mk_grants( logger.debug("Making grants for `%s` on documents created by others.") a, b = dummies.grants.minimum_self, dummies.grants.maximum_self q_ids_has_grants = ( - select(Document.id) + select(Document.uuid) .join(Grant) - .group_by(Grant.id_document) - .having(func.count(Grant.id_user) > 0) - .where(Grant.id_user == self.user.id) + .group_by(Grant.uuid_document) + .having(func.count(Grant.uuid_user) > 0) + .where(Grant.uuid_user == self.user.uuid) ) q_grants_share = ( select(Grant) .join(Document) .where( - Document.id.not_in(q_ids_has_grants), + Document.uuid.not_in(q_ids_has_grants), Grant.pending_from == PendingFrom.created, ) .limit(b) @@ -240,8 +240,8 @@ def mk_grants( grants_self = tuple( Grant( uuid=secrets.token_urlsafe(8), - id_user=self.user.id, - id_document=grant.id_document, + uuid_user=self.user.uuid, + uuid_document=grant.uuid_document, uuid_parent=grant.uuid, **kwargs, ) @@ -257,8 +257,8 @@ def mk_grants( logger.debug("Making grants for others on documents created `%s`.") q_ids_users = ( - select(User.id) - .where(User.id != self.user.id) + select(User.uuid) + .where(User.uuid != self.user.uuid) .limit( randint( dummies.grants.minimum_other, @@ -266,7 +266,7 @@ def mk_grants( ) ) ) - id_users_other = set(self.session.scalars(q_ids_users)) + uuid_users_other = set(self.session.scalars(q_ids_users)) if not grants_created: grants_source = tuple(map(self.get_document_grant, documents)) @@ -278,15 +278,15 @@ def mk_grants( Grant( uuid=secrets.token_urlsafe(8), level=choice(list(Level)), - id_user=id_user, - id_document=grant.id_document, + uuid_user=uuid_user, + uuid_document=grant.uuid_document, uuid_parent=grant.uuid, deleted=bool(randint(0, 1)), pending=bool(randint(0, 1)), pending_from=choice((PendingFrom.grantee, PendingFrom.granter)), ) for grant in grants_source - for id_user in id_users_other + for uuid_user in uuid_users_other ) return grants_created + grants_self + grants_other @@ -392,7 +392,7 @@ def randomize_primary( def randomize_grants(self): logger.debug("Randomizing grants for `%s`.", self.user.uuid) q_uuids = select(Grant.uuid).where( - Grant.id_user == self.user.id, Grant.pending_from != PendingFrom.created + Grant.uuid_user == self.user.uuid, Grant.pending_from != PendingFrom.created ) uuids = self.session.scalars(q_uuids) @@ -479,7 +479,7 @@ def get_users( ) -> Tuple[User, ...]: callback = None if other: - callback = lambda q: q.where(User.id != self.user.id) # noqa: E731 + callback = lambda q: q.where(User.uuid != self.user.uuid) # noqa: E731 return self.get_primary( User, @@ -526,12 +526,12 @@ def callback(q): q = q.join(Grant).where(*conds) else: q_has_grants = ( - select(Grant.id_document) - .where(Grant.id_user == self.user.id) - .group_by(Grant.id_document) + select(Grant.uuid_document) + .where(Grant.uuid_user == self.user.uuid) + .group_by(Grant.uuid_document) .having(func.count(Grant.uuid) > 0) ) - q = q.where(Document.id.not_in(q_has_grants)) + q = q.where(Document.uuid.not_in(q_has_grants)) return q @@ -555,8 +555,8 @@ def get_documents_retry_callback(): self.session.add( Grant( uuid=secrets.token_urlsafe(8), - id_document=document.id, - id_user=self.user.id, + uuid_document=document.uuid, + uuid_user=self.user.uuid, level=level or Level.own, pending_from=PendingFrom.created, pending=kwargs.get("pending", False), @@ -570,8 +570,8 @@ def get_documents_retry_callback(): grants = tuple( Grant( uuid=secrets.token_urlsafe(8), - id_document=document.id, - id_user=self.user.id, + uuid_document=document.uuid, + uuid_user=self.user.uuid, level=level or Level.own, pending_from=PendingFrom.created, pending=kwargs.get("pending", False), @@ -601,7 +601,7 @@ def get_documents_data_callback( q_grants = ( select(Grant) .join(Document) - .where(Document.uuid.in_(uuid_documents), Grant.id_user == self.user.id) + .where(Document.uuid.in_(uuid_documents), Grant.uuid_user == self.user.uuid) ) data_raw["grants"] = { gg.uuid_document: gg for gg in self.session.scalars(q_grants) @@ -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.id) + collection = Mk.collection(id_user=self.user.uuid) session.add(collection) session.commit() session.refresh(collection) @@ -658,22 +658,22 @@ def get_collections( def callback(q): match other: case True: - cond_other = Collection.id_user != self.user.id + cond_other = Collection.uuid_user != self.user.uuid case False: - cond_other = Collection.id_user == self.user.id + cond_other = Collection.uuid_user == self.user.uuid case _: cond_other = true() if order_by_document_count: q_ids = ( - select(Collection.id.label("id_collection")) + select(Collection.uuid.label("id_collection")) .join(Assignment) - .group_by(Collection.id) - .having(func.count(Assignment.id_document) > 0) + .group_by(Collection.uuid) + .having(func.count(Assignment.uuid_document) > 0) .where(cond_other) - .order_by(desc(func.count(Assignment.id_document))) + .order_by(desc(func.count(Assignment.uuid_document))) ) - q = q.where(Collection.id.in_(q_ids)) + q = q.where(Collection.uuid.in_(q_ids)) return q @@ -699,7 +699,7 @@ def get_collections_data( def get_document_grant(self, document: Document) -> Grant: grant = self.session.scalar( select(Grant).where( - Grant.id_document == document.id, Grant.id_user == self.user.id + Grant.uuid_document == document.uuid, Grant.uuid_user == self.user.uuid ) ) if grant is None: @@ -912,14 +912,14 @@ def get_data_secondary( # NOTE: Get assocs. Assocs are always labeled by their model_assoc = resolve_model(Resolved.kind_assoc) # type: ignore - id_source_name = f"id_{Resolved._attr_name_source}" + uuid_source_name = f"id_{Resolved._attr_name_source}" uuid_target_name = f"uuid_{Resolved.kind_target.name}" q = ( select(model_assoc) .join(model_target) .where( - getattr(model_assoc, id_source_name) == source.id, + getattr(model_assoc, uuid_source_name) == source.uuid, model_target.uuid.in_(uuid_target := uuids(targets)), ) ) @@ -1047,7 +1047,8 @@ def __new__(cls, name, bases, namespace): if (dummies_file := namespace.get("dummies_file")) is None: kind = KindObject._value2member_map_[M.__tablename__] - dummies_file = util.Path.test_assets(f"{kind.name}.yaml") + dummies_file = util.Path.simulatus_assets(f"{kind.name}.yaml") + namespace["dummies_file"] = dummies_file T = super().__new__(cls, name, bases, namespace) @@ -1304,7 +1305,7 @@ def q_select( ): return ( select( - User.id, + User.uuid, User.uuid, func.JSON_VALUE(User.content, "$.dummy.used_by").label("used_by"), func.JSON_LENGTH(User.content, "$.dummy.used_by").label( @@ -1359,7 +1360,7 @@ def restore( ) -> Self: with self.sessionmaker() as session: logger.debug("Getting current user count.") - uuids_existing = list(session.scalars(select(User.id, User.uuid))) + uuids_existing = list(session.scalars(select(User.uuid, User.uuid))) n_users = len(uuids_existing) assert n_users is not None diff --git a/tests/assets/assignment.yaml b/src/simulatus/assets/assignment.yaml similarity index 50% rename from tests/assets/assignment.yaml rename to src/simulatus/assets/assignment.yaml index 5fdac82..dc65759 100644 --- a/tests/assets/assignment.yaml +++ b/src/simulatus/assets/assignment.yaml @@ -2,35 +2,35 @@ # Collection 5 - uuid: foobar--eee - id_collection: 4 - id_document: 7 + uuid_collection: eee-eee-eee + uuid_document: foobar-spam # --------------------------------------------------------------------------- # # Collection 6 - uuid: ex--foo-ool - id_document: 4 - id_collection: 5 + uuid_document: ex-parrot + uuid_collection: foo-ooo-ool - uuid: petshopfool - id_document: 6 - id_collection: 5 + uuid_document: petshoppe-- + uuid_collection: foo-ooo-ool - uuid: barspamfool - id_document: 7 - id_collection: 5 + uuid_document: foobar-spam + uuid_collection: foo-ooo-ool - uuid: draculafool - id_document: 8 - id_collection: 5 + uuid_document: draculaflow + uuid_collection: foo-ooo-ool # --------------------------------------------------------------------------- # # Document 5 - uuid: aaa-aaa-eee - id_document: 5 - id_collection: 4 + uuid_document: aaa-aaa-aaa + uuid_collection: eee-eee-eee - uuid: aaa-foo-ool - id_document: 5 - id_collection: 5 + uuid_document: aaa-aaa-aaa + uuid_collection: foo-ooo-ool diff --git a/tests/assets/collection.yaml b/src/simulatus/assets/collection.yaml similarity index 67% rename from tests/assets/collection.yaml rename to src/simulatus/assets/collection.yaml index 3505f07..992ee35 100644 --- a/tests/assets/collection.yaml +++ b/src/simulatus/assets/collection.yaml @@ -1,34 +1,32 @@ -- id_user: 1 - id: 1 +- uuid_user: 99d-99d-99d + uuid: collection1 name: foofoo description: The foofoo collection -- id_user: 1 - id: 2 +- uuid_user: 99d-99d-99d + uuid: collection2 name: Bar. description: The bar collection. -- id_user: 1 - id: 3 +- uuid_user: 99d-99d-99d + uuid: collection3 name: Spam and Etc. description: A collection about processed meat products. -- id_user: 2 - id: 4 +- uuid_user: 000-000-000 name: Chicharon. description: A collection about New Mexican food. uuid: 'eee-eee-eee' deleted: False -- id_user: 2 - id: 5 +- uuid_user: 000-000-000 name: Adovada and Chicharon. description: A collection about New Mexican food. uuid: 'foo-ooo-ool' deleted: False -- id_user: 2 - id: 6 +- uuid_user: 000-000-000 + uuid: 'ersomething' name: Mole and Tacos. description: A collection about Mexican food. diff --git a/tests/assets/document.yaml b/src/simulatus/assets/document.yaml similarity index 99% rename from tests/assets/document.yaml rename to src/simulatus/assets/document.yaml index 16b23f3..08bd24e 100644 --- a/tests/assets/document.yaml +++ b/src/simulatus/assets/document.yaml @@ -1,7 +1,6 @@ --- - uuid: ---0---0--- name: Lorm ipsum - id: 1 description: Lorem ipsum 1 content: text_format: md @@ -19,7 +18,6 @@ - uuid: -0---0---0- name: Lorm ipsum 2 - id: 2 description: Lorem ipsum 2 content: text_format: rst @@ -38,7 +36,7 @@ - name: Lorm ipsum 3 - id: 3 + uuid: lormipsum3 description: Lorem ipsum 3 content: text_format: md @@ -49,7 +47,6 @@ - uuid: ex-parrot name: Lorm ipsum 4 - id: 4 description: Lorem ipsum 4 content: text_format: md @@ -62,7 +59,6 @@ # NOTE: This document is important in tests and should be owned by user with uuid 00000000 - name: Lorem Ipsum 5 uuid: aaa-aaa-aaa - id: 5 description: Lorem ipsum 5 content: text_format: rst @@ -76,7 +72,6 @@ - uuid: petshoppe-- name: Lorem Ipsum 6 - id: 6 description: Lorem ipsum 6 content: text_format: md @@ -90,7 +85,6 @@ - uuid: foobar-spam name: Foo Document - id: 7 description: A document, foo. content: text_format: md @@ -112,7 +106,6 @@ - uuid: draculaflow name: Objectively a Banger - id: 8 description: A masterpiece. content: text_format: md diff --git a/tests/assets/event.yaml b/src/simulatus/assets/event.yaml similarity index 100% rename from tests/assets/event.yaml rename to src/simulatus/assets/event.yaml diff --git a/tests/assets/grant.yaml b/src/simulatus/assets/grant.yaml similarity index 73% rename from tests/assets/grant.yaml rename to src/simulatus/assets/grant.yaml index d23f356..c0c54cf 100644 --- a/tests/assets/grant.yaml +++ b/src/simulatus/assets/grant.yaml @@ -2,16 +2,16 @@ # Document 1 (---0---0---) - uuid: 1-111-111-1 - id_user: 1 - id_document: 1 + uuid_user: 99d-99d-99d + uuid_document: ---0---0--- level: own pending: False pending_from: created - uuid: a-aaa-aaa-a uuid_parent: 1-111-111-1 - id_user: 2 - id_document: 1 + uuid_user: 000-000-000 + uuid_document: ---0---0--- level: view pending: False pending_from: granter @@ -22,16 +22,16 @@ # NOTE: User 000-000-000 should have no grant! - uuid: 2-222-222-2 - id_user: 1 - id_document: 2 + uuid_user: 99d-99d-99d + uuid_document: -0---0---0- level: own pending: False pending_from: created # - uuid: b-bbb-bbb-b # uuid_parent: 2-222-222-2 -# id_user: 2 -# id_document: 2 +# uuid_user: 000-000-000 +# uuid_document: -0---0---0- # level: modify # pending: False # pending_from: grantee @@ -41,16 +41,16 @@ # Document 3 - uuid: 3-333-333-3 - id_user: 1 - id_document: 3 + uuid_user: 99d-99d-99d + uuid_document: lormipsum3 level: own pending: False pending_from: created - uuid: c-ccc-ccc-c uuid_parent: 3-333-333-3 - id_user: 2 - id_document: 3 + uuid_user: 000-000-000 + uuid_document: lormipsum3 level: modify pending: False pending_from: granter @@ -60,16 +60,16 @@ # Document 4 (ex-parrot) - uuid: 4-444-444-4 - id_user: 1 - id_document: 4 + uuid_user: 99d-99d-99d + uuid_document: ex-parrot level: own pending: False pending_from: created - uuid: d-ddd-ddd-d uuid_parent: 4-444-444-4 - id_user: 2 - id_document: 4 + uuid_user: 000-000-000 + uuid_document: ex-parrot level: modify pending: False pending_from: grantee @@ -79,16 +79,16 @@ # Document 5 (aaa-aaa-aaa) - uuid: 5-555-555-5 - id_user: 1 - id_document: 5 + uuid_user: 99d-99d-99d + uuid_document: aaa-aaa-aaa level: own pending: False pending_from: created - uuid: e-eee-eee-e uuid_parent: 5-555-555-5 - id_user: 2 - id_document: 5 + uuid_user: 000-000-000 + uuid_document: aaa-aaa-aaa level: own pending: False pending_from: granter @@ -98,24 +98,24 @@ # Document 6 (petshoppe--) - uuid: 6-666-666-6 - id_user: 2 - id_document: 6 + uuid_user: 000-000-000 + uuid_document: petshoppe-- level: own pending: False pending_from: created - uuid: f-fff-fff-f uuid_parent: 6-666-666-6 - id_user: 1 - id_document: 6 + uuid_user: 99d-99d-99d + uuid_document: petshoppe-- level: modify pending: False pending_from: grantee - uuid: -=-=-=-=-=- uuid_parent: 6-666-666-6 - id_user: 3 - id_document: 6 + uuid_user: 777-777-777 + uuid_document: petshoppe-- level: view pending: False pending_from: grantee @@ -125,16 +125,16 @@ # Document 7 (foobar-spam) - uuid: 7-777-777-7 - id_user: 1 - id_document: 7 + uuid_user: 99d-99d-99d + uuid_document: foobar-spam level: own pending: False pending_from: created - uuid: g-ggg-ggg-g uuid_parent: 7-777-777-7 - id_user: 2 - id_document: 7 + uuid_user: 000-000-000 + uuid_document: foobar-spam level: own pending: False pending_from: granter @@ -143,8 +143,8 @@ # Document 8 (draculaflow) - uuid: 888-888-888 - id_user: 2 - id_document: 8 + uuid_user: 000-000-000 + uuid_document: draculaflow level: own pending: False pending_from: created diff --git a/tests/assets/user.yaml b/src/simulatus/assets/user.yaml similarity index 95% rename from tests/assets/user.yaml rename to src/simulatus/assets/user.yaml index 136f3ca..d7b1306 100644 --- a/tests/assets/user.yaml +++ b/src/simulatus/assets/user.yaml @@ -1,5 +1,4 @@ -- id: 1 - uuid: 99d-99d-99d +- uuid: 99d-99d-99d subject: 721f1d63d7015cd2c54bcb441e923464f27768a89a1f46640088a5a839a5d186 name: you're mom description: The joke is that it is mispelled. @@ -13,7 +12,6 @@ # Because of tests not an admin - uuid: 000-000-000 subject: 9de6a6fa6734b71af099005fdeb709e73083fb6ce6d453f726da3e8aeb4c4595 - id: 2 admin: True name: acederberg description: maintainer of this project @@ -26,7 +24,6 @@ - uuid: 777-777-777 subject: b8494f0c413111c8a0a23372fd2a3cc4970e4a29478c22a6f60a122423edc0f4 - id: 3 name: Demo User description: Demo user email: demo@example.io @@ -38,7 +35,6 @@ - uuid: -0123456789 subject: e663ef439f4924a62ef50c7d2d3fee4e02b5e6fb46ad25191938eddd49681a9b - id: 4 name: Sum dood description: Whatever email: sumdood@whatever.org diff --git a/tests/assets/edit.yaml b/tests/assets/edit.yaml deleted file mode 100644 index f8ed01d..0000000 --- a/tests/assets/edit.yaml +++ /dev/null @@ -1,175 +0,0 @@ - -- id_document: 6 - id: 1 - id_user: 1 - content: | - - Rotton Possum - ============================ - - Odio aenean sed adipiscing diam donec adipiscing tristique risus. - Quis vel eros donec ac. - In ornare quam viverra orci sagittis eu volutpat odio. - Arcu risus quis varius quam quisque id diam vel quam. - Nibh ipsum consequat nisl vel pretium. - Elit duis tristique sollicitudin nibh sit amet commodo nulla facilisi. - Nulla pellentesque dignissim enim sit amet venenatis. - Gravida neque convallis a cras semper auctor. - Id faucibus nisl tincidunt eget nullam. - Nisi lacus sed viverra tellus. - -- id_document: 6 - id_user: 1 - id: 2 - content: | - - Rotton Possum - ============================ - - Odio aenean sed adipiscing diam donec adipiscing tristique risus. - Quis vel eros donec ac. - In ornare quam viverra orci sagittis eu volutpat odio. - Arcu risus quis varius quam quisque id diam vel quam. - Nibh ipsum consequat nisl vel pretium. - Elit duis tristique sollicitudin nibh sit amet commodo nulla facilisi. - Nulla pellentesque dignissim enim sit amet venenatis. - Gravida neque convallis a cras semper auctor. - Id faucibus nisl tincidunt eget nullam. - Nisi lacus sed viverra tellus. - Turpis egestas sed tempus urna et. - -- id_document: 6 - id_user: 1 - id: 3 - content: | - - Rotton Possum - ============================ - - Odio aenean sed adipiscing diam donec adipiscing tristique risus. - Quis vel eros donec ac. - In ornare quam viverra orci sagittis eu volutpat odio. - Arcu risus quis varius quam quisque id diam vel quam. - Nibh ipsum consequat nisl vel pretium. - Elit duis tristique sollicitudin nibh sit amet commodo nulla facilisi. - Nulla pellentesque dignissim enim sit amet venenatis. - Gravida neque convallis a cras semper auctor. - Id faucibus nisl tincidunt eget nullam. - Nisi lacus sed viverra tellus. - -- id_document: 6 - id_user: 1 - id: 4 - content: | - - Rotton Possum - ============================ - - Odio aenean sed adipiscing diam donec adipiscing tristique risus. - Quis vel eros donec ac. - In ornare quam viverra orci sagittis eu volutpat odio. - Arcu risus quis varius quam quisque id diam vel quam. - Nibh ipsum consequat nisl vel pretium. - Elit duis tristique sollicitudin nibh sit amet commodo nulla facilisi. - Nulla pellentesque dignissim enim sit amet venenatis. - Gravida neque convallis a cras semper auctor. - Id faucibus nisl tincidunt eget nullam. - -- id_document: 6 - id_user: 1 - id: 5 - content: | - - Rotton Possum - ============================ - - Odio aenean sed adipiscing diam donec adipiscing tristique risus. - Quis vel eros donec ac. - In ornare quam viverra orci sagittis eu volutpat odio. - Arcu risus quis varius quam quisque id diam vel quam. - Nibh ipsum consequat nisl vel pretium. - Elit duis tristique sollicitudin nibh sit amet commodo nulla facilisi. - Nulla pellentesque dignissim enim sit amet venenatis. - Gravida neque convallis a cras semper auctor. - -- id_document: 6 - id_user: 1 - id: 6 - content: | - - Rotton Possum - ============================ - - Odio aenean sed adipiscing diam donec adipiscing tristique risus. - Quis vel eros donec ac. - In ornare quam viverra orci sagittis eu volutpat odio. - Arcu risus quis varius quam quisque id diam vel quam. - Nibh ipsum consequat nisl vel pretium. - Elit duis tristique sollicitudin nibh sit amet commodo nulla facilisi. - Nulla pellentesque dignissim enim sit amet venenatis. - -- id_document: 6 - id_user: 1 - id: 7 - content: | - - Rotton Possum - ============================ - - Odio aenean sed adipiscing diam donec adipiscing tristique risus. - Quis vel eros donec ac. - In ornare quam viverra orci sagittis eu volutpat odio. - Arcu risus quis varius quam quisque id diam vel quam. - Nibh ipsum consequat nisl vel pretium. - Elit duis tristique sollicitudin nibh sit amet commodo nulla facilisi. - -- id_document: 6 - id_user: 1 - id: 8 - content: | - - Rotton Possum - ============================ - - Odio aenean sed adipiscing diam donec adipiscing tristique risus. - Quis vel eros donec ac. - In ornare quam viverra orci sagittis eu volutpat odio. - Arcu risus quis varius quam quisque id diam vel quam. - Nibh ipsum consequat nisl vel pretium. - -- id_document: 6 - id_user: 1 - id: 9 - content: | - - Rotton Possum - ============================ - - Odio aenean sed adipiscing diam donec adipiscing tristique risus. - Quis vel eros donec ac. - In ornare quam viverra orci sagittis eu volutpat odio. - Arcu risus quis varius quam quisque id diam vel quam. - -- id_document: 6 - id_user: 1 - id: 10 - content: | - - Rotton Possum - ============================ - - Odio aenean sed adipiscing diam donec adipiscing tristique risus. - Quis vel eros donec ac. - In ornare quam viverra orci sagittis eu volutpat odio. - -- id_document: 6 - id_user: 1 - id: 11 - content: | - - Rotton Possum - ============================ - - Odio aenean sed adipiscing diam donec adipiscing tristique risus. - Quis vel eros donec ac. -