Ejemplo n.º 1
0
def create_random_item(user: User, collection: Collection) -> Item:
    geometry = Point(random.random(), random.random())
    properties = {"name": random_lower_string()}
    item_in = ItemCreate(geometry=geometry, properties=properties)
    item = services.item.create_collection_item(InternalUserDTO(**user.dict()),
                                                collection.uuid,
                                                item_in.to_dto())
    return Item.from_dto(item)
Ejemplo n.º 2
0
def test_create_item(db: Session) -> None:
    geometry = Point(0.0, 0.0)
    properties = {"name": "test-name1"}
    item_in = ItemCreate(geometry=geometry, properties=properties)
    user = create_random_user(db)
    collection = create_random_collection(user)
    item = services.item.create_collection_item(InternalUserDTO(**user.dict()),
                                                collection.uuid,
                                                item_in.to_dto())
    assert to_shape(item.geometry) == geometry
    assert item.properties == properties
    assert item.collection_uuid == collection.uuid
Ejemplo n.º 3
0
def create_user_item(db: Session, item: itemschema.ItemCreate,
                     owner_id: int) -> itemschema.Item:
    db_item = models.Item(**item.dict(), owner_id=owner_id)
    db.add(db_item)
    db.commit()
    db.refresh(db_item)
    return db_item
Ejemplo n.º 4
0
def item() -> Item:
    title = random_lower_string()
    priority = 123
    user_id = "C@234"
    user_name = "user.name"
    item_in = ItemCreate(title=title, priority=priority, user_id=user_id, user_name=user_name)
    return crud.item.create(db_session=db_session, obj_in=item_in)
Ejemplo n.º 5
0
def create_random_item(db: Session, *, owner_id: Optional[int] = None) -> models.Item:
    if owner_id is None:
        user = create_random_user(db)
        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_with_owner(db=db, obj_in=item_in, owner_id=owner_id)
Ejemplo n.º 6
0
def _create_schema_for_item(itemtype_id: int, category_id: int,
                            payment_id: int) -> ItemCreate:
    return ItemCreate(description=DESCRIPTION,
                      amount=AMOUNT,
                      date=DATE,
                      category_id=category_id,
                      payment_id=payment_id,
                      itemtype_id=itemtype_id)
Ejemplo n.º 7
0
def test_create_item_description_with_invalid_contraints(
        db: Session, test_category, test_payment, invalid_length):
    description = random_string(length=invalid_length)
    with pytest.raises(ValidationError):
        ItemCreate(description=description,
                   amount=4.22,
                   date="01.01.2020",
                   category_id=test_category.id,
                   payment_id=test_payment.id)
Ejemplo n.º 8
0
def test_create_item(db: Session) -> None:
    title = random_lower_string()
    description = random_lower_string()
    item_in = ItemCreate(title=title, description=description)
    user = create_random_user(db)
    item = crud.item.create_with_owner(db=db, obj_in=item_in, owner_id=user.id)
    assert item.title == title
    assert item.description == description
    assert item.owner_id == user.id
Ejemplo n.º 9
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_with_owner(db_session=db_session,
                                       obj_in=item_in,
                                       owner_id=owner_id)
Ejemplo n.º 10
0
async def test_get_item(db: AsyncSession) -> None:
    title = random_lower_string()
    description = random_lower_string()
    item_in = ItemCreate(title=title, description=description)
    user = await create_random_user(db)
    item = await crud.item.create_with_owner(db=db, obj_in=item_in, owner_id=user.id)
    stored_item = await crud.item.get(db=db, id=item.id)
    assert stored_item
    assert item.id == stored_item.id
    assert item.title == stored_item.title
    assert item.description == stored_item.description
    assert item.owner_id == stored_item.owner_id
def test_get_item():
    title = random_lower_string()
    description = random_lower_string()
    item_in = ItemCreate(title=title, description=description)
    user = create_random_user()
    item = crud.item.create_with_owner(db_session=db_session,
                                       obj_in=item_in,
                                       owner_id=user.id)
    stored_item = crud.item.get(db_session=db_session, id=item.id)
    assert item.id == stored_item.id
    assert item.title == stored_item.title
    assert item.description == stored_item.description
    assert item.owner_id == stored_item.owner_id
Ejemplo n.º 12
0
def test_update_item(db: Session) -> None:
    title = random_lower_string()
    description = random_lower_string()
    item_in = ItemCreate(title=title, description=description)
    user = create_random_user(db)
    item = crud.item.create_with_owner(db=db, obj_in=item_in, owner_id=user.id)
    description2 = random_lower_string()
    item_update = ItemUpdate(description=description2)
    item2 = crud.item.update(db=db, db_obj=item, obj_in=item_update)
    assert item.id == item2.id
    assert item.title == item2.title
    assert item2.description == description2
    assert item.owner_id == item2.owner_id
Ejemplo n.º 13
0
async def test_delete_item(db: AsyncSession) -> None:
    title = random_lower_string()
    description = random_lower_string()
    item_in = ItemCreate(title=title, description=description)
    user = await create_random_user(db)
    item = await crud.item.create_with_owner(db=db, obj_in=item_in, owner_id=user.id)
    item2 = await crud.item.remove(db=db, id=item.id)
    item3 = await crud.item.get(db=db, 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
Ejemplo n.º 14
0
def test_create_item():
    title = random_lower_string()
    priority = 123
    user_id = "C@234"
    user_name = "user.name"
    item_in = ItemCreate(title=title,
                         priority=priority,
                         user_id=user_id,
                         user_name=user_name)
    item = crud.item.create(db_session=db_session, obj_in=item_in)
    assert item.title == title
    assert item.priority == priority
    assert item.user_id == user_id
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_with_owner(db_session=db_session,
                                       obj_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
Ejemplo n.º 16
0
def test_category_items_field_is_propagated_by_items(db: Session, test_payment) -> None:
    name = random_string(length=randint(3, 30))
    itemtype = mock.MagicMock()
    category = _create_category(db, name=name, itemtype_id=itemtype.id)
    assert category.title_en == name
    assert category.items == []

    user = create_random_user(db)
    item_in = ItemCreate(description="test_description", amount="12.20", date="01.01.2020",
                         category_id=category.id, payment_id=test_payment.id, itemtype_id=itemtype.id)
    item = crud.item.create_with_owner(db=db, obj_in=item_in, owner_id=user.id)
    assert category.items == [item]

    crud.item.remove(db=db, id=item.id)
    assert category.items == []
Ejemplo n.º 17
0
def create_random_item(db: Session, itemtype_id: int, category_id: int,
                       payment_id: int) -> models.Item:
    user = create_random_user(db)
    owner_id = user.id
    description = random_string()
    amount = random_float()
    date = random_date()
    item_in = ItemCreate(description=description,
                         amount=amount,
                         date=date,
                         itemtype_id=itemtype_id,
                         category_id=category_id,
                         payment_id=payment_id)
    return crud.item.create_with_owner(db=db,
                                       obj_in=item_in,
                                       owner_id=owner_id)