def test_unit__content_depot_file__ok__nominal_case( self, admin_user, session, content_type_list): """ Depot file access thought content property methods. """ workspace = Workspace(label="TEST_WORKSPACE_1", owner=admin_user) session.add(workspace) session.flush() content = Content( owner=admin_user, workspace=workspace, type=content_type_list.Page.slug, label="TEST_CONTENT_1", description="TEST_CONTENT_DESCRIPTION_1", revision_type=ActionDescription.CREATION, is_deleted=False, is_archived=False, ) session.add(content) session.flush() # tests uninitialized depot file assert content.depot_file is None # initializes depot file # which is able to behave like a python file object content.depot_file = b"test" # tests initialized depot file assert content.depot_file # tests type of initialized depot file assert type(content.depot_file) == UploadedFile # tests content of initialized depot file # using depot_file.file of type StoredFile to fetch content back assert content.depot_file.file.read() == b"test"
def test_unit__workspace_get_size(self, admin_user, session, content_type_list): """ Depot file access thought content property methods. """ workspace = Workspace(label="TEST_WORKSPACE_1", owner=admin_user) session.add(workspace) session.flush() content = Content( owner=admin_user, workspace=workspace, type=content_type_list.Page.slug, label="TEST_CONTENT_1", description="TEST_CONTENT_DESCRIPTION_1", revision_type=ActionDescription.CREATION, is_deleted=False, is_archived=False, ) content.depot_file = b"test" session.add(content) assert workspace.get_size() == 4 assert workspace.get_size(include_deleted=True) == 4 assert workspace.get_size(include_archived=True) == 4 with new_revision(session=session, tm=transaction.manager, content=content): content.is_deleted = True content.is_archived = False session.flush() transaction.commit() assert workspace.get_size() == 0 assert workspace.get_size(include_deleted=True) == 8 assert workspace.get_size(include_archived=True) == 0 with new_revision(session=session, tm=transaction.manager, content=content): content.is_deleted = False content.is_archived = True session.flush() transaction.commit() assert workspace.get_size() == 0 assert workspace.get_size(include_deleted=True) == 0 assert workspace.get_size(include_archived=True) == 12