async def test_update_collection(database): async with database.transaction(force_rollback=True): update = CollectionIn( name = "updated", title = "Another title", public = True, ) await update_collection( database, test_test_col.id, value = update, ) collection = await get_collection( database, test_user, user_id = test_user.id, collection_name = update.name, ) expected = Collection( **test_test_col.dict(exclude={"name", "title", "public"}), **update.dict(), user_id = test_user.id, can_edit = True, ) assert collection == expected
async def test_get_all_collections(database): collections = await get_collections( database, test_user, user_id = test_user.id, only_owned = False, ) expected = [ Collection( **admin_shared_col.dict(), user_id = test_user.id, can_edit = False, ), Collection( **admin_shared_edit_col.dict(), user_id = test_user.id, can_edit = True, ), Collection( **test_public_col.dict(), user_id = test_user.id, can_edit = True, ), Collection( **test_test_col.dict(), user_id = test_user.id, can_edit = True, ), ] assert collections == expected
async def test_get_owned_private_collection(database): collection = await get_collection( database, test_user, user_id = test_user.id, collection_name = test_test_col.name, ) expected = Collection( **test_test_col.dict(), user_id = test_user.id, can_edit = True, ) assert collection == expected
def test_get_other_private_collection_as_admin(client, admin_headers): response = client.get( "/users/test/collections/test", headers = admin_headers, ) expected = dict( **test_test_col.dict(include={ "id", "owner", "name", "title", "public", "deleted", }), can_edit = True, ) assert response.status_code == 200 assert response.json() == expected
async def test_get_other_private_collection_include_private(database): collection = await get_collection( database, admin_user, user_id = test_user.id, collection_name = test_test_col.name, include_private = True, ) expected = Collection( **test_test_col.dict(), user_id = admin_user.id, can_edit = True, ) assert collection == expected
def test_get_owned_collections(client, user_headers): response = client.get( "/users/test/collections", headers = user_headers, ) expected = [ dict( **test_public_col.dict(), can_edit = True, ), dict( **test_test_col.dict(), can_edit = True, ), ] assert response.status_code == 200 assert response.json() == expected