def test_update_item():
    title = random_lower_string()
    description = random_lower_string()
    id = crud.utils.generate_new_id()
    item_in = ItemCreate(title=title, description=description)
    bucket = get_default_bucket()
    user = create_random_user()
    item = crud.item.upsert(bucket=bucket,
                            id=id,
                            doc_in=item_in,
                            owner_username=user.username,
                            persist_to=1)
    description2 = random_lower_string()
    item_update = ItemUpdate(description=description2)
    item2 = crud.item.update(
        bucket=bucket,
        id=id,
        doc_in=item_update,
        owner_username=item.owner_username,
        persist_to=1,
    )
    assert item.id == item2.id
    assert item.title == item2.title
    assert item.description == description
    assert item2.description == description2
    assert item.owner_username == item2.owner_username
예제 #2
0
def create_random_item(owner_id: int = None):
    if owner_id is None:
        user = create_random_user()
        owner_id = user.id
    title = random_lower_string()
    description = random_lower_string()
    item_in = ItemCreate(title=title, description=description, id=id)
    return crud.item.create(
        db_session=db_session, item_in=item_in, owner_id=owner_id
    )
예제 #3
0
def test_create_item():
    title = random_lower_string()
    description = random_lower_string()
    item_in = ItemCreate(title=title, description=description)
    user = create_random_user()
    item = crud.item.create(db_session=db_session,
                            item_in=item_in,
                            owner_id=user.id)
    assert item.title == title
    assert item.description == description
    assert item.owner_id == user.id
예제 #4
0
def test_delete_item():
    title = random_lower_string()
    description = random_lower_string()
    item_in = ItemCreate(title=title, description=description)
    user = create_random_user()
    item = crud.item.create(db_session=db_session,
                            item_in=item_in,
                            owner_id=user.id)
    item2 = crud.item.remove(db_session=db_session, id=item.id)
    item3 = crud.item.get(db_session=db_session, id=item.id)
    assert item3 is None
    assert item2.id == item.id
    assert item2.title == title
    assert item2.description == description
    assert item2.owner_id == user.id
def upsert(
    bucket: Bucket,
    *,
    id: str,
    doc_in: ItemCreate,
    owner_username: str,
    persist_to=0,
    ttl=0,
):
    doc_id = get_doc_id(id)
    doc = ItemInDB(**doc_in.dict(), id=id, owner_username=owner_username)
    return utils.upsert(bucket=bucket,
                        doc_id=doc_id,
                        doc_in=doc,
                        persist_to=persist_to,
                        ttl=ttl)
def create_random_item(owner_username: str = None):
    if owner_username is None:
        user = create_random_user()
        owner_username = user.username
    title = random_lower_string()
    description = random_lower_string()
    id = crud.utils.generate_new_id()
    item_in = ItemCreate(title=title, description=description, id=id)
    bucket = get_default_bucket()
    return crud.item.upsert(
        bucket=bucket,
        id=id,
        doc_in=item_in,
        owner_username=owner_username,
        persist_to=1,
    )
def test_create_item():
    title = random_lower_string()
    description = random_lower_string()
    id = crud.utils.generate_new_id()
    item_in = ItemCreate(title=title, description=description)
    bucket = get_default_bucket()
    user = create_random_user()
    item = crud.item.upsert(bucket=bucket,
                            id=id,
                            doc_in=item_in,
                            owner_username=user.username,
                            persist_to=1)
    assert item.id == id
    assert item.type == ITEM_DOC_TYPE
    assert item.title == title
    assert item.description == description
    assert item.owner_username == user.username
예제 #8
0
def test_update_item():
    title = random_lower_string()
    description = random_lower_string()
    item_in = ItemCreate(title=title, description=description)
    user = create_random_user()
    item = crud.item.create(db_session=db_session,
                            item_in=item_in,
                            owner_id=user.id)
    description2 = random_lower_string()
    item_update = ItemUpdate(description=description2)
    item2 = crud.item.update(db_session=db_session,
                             item=item,
                             item_in=item_update)
    assert item.id == item2.id
    assert item.title == item2.title
    assert item2.description == description2
    assert item.owner_id == item2.owner_id
def test_delete_item():
    title = random_lower_string()
    description = random_lower_string()
    id = crud.utils.generate_new_id()
    item_in = ItemCreate(title=title, description=description)
    bucket = get_default_bucket()
    user = create_random_user()
    item = crud.item.upsert(bucket=bucket,
                            id=id,
                            doc_in=item_in,
                            owner_username=user.username,
                            persist_to=1)
    item2 = crud.item.remove(bucket=bucket, id=id, persist_to=1)
    item3 = crud.item.get(bucket=bucket, id=id)
    assert item3 is None
    assert item2.id == id
    assert item2.title == title
    assert item2.description == description
    assert item2.owner_username == user.username