Ejemplo n.º 1
0
def test_find_all(orm_drink_repository):
    actual = orm_drink_repository.find_all(query_param=QueryParam(
        type=DrinkType.from_str("soju"),
        filter=FilterType.from_str("review"),
        order=OrderType.from_str("descending"),
    ))
    expected = [
        Drink(
            id=DrinkId.build(drink_name="soju2", created_at=1234),
            name="soju2",
            image_url="soju_image2",
            type=DrinkType.from_str("soju"),
            avg_rating=DrinkRating(value=5),
            num_of_reviews=1,
            num_of_wish=1,
        ),
        Drink(
            id=DrinkId.build(drink_name="soju1", created_at=1234),
            name="soju1",
            image_url="soju_image1",
            type=DrinkType.from_str("soju"),
            avg_rating=DrinkRating(),
            num_of_reviews=0,
            num_of_wish=0,
        ),
    ]
    assert actual == expected
Ejemplo n.º 2
0
def test_add(orm_drink_repository):
    drink = Drink(
        id=DrinkId.build(drink_name="wine", created_at=1234),
        name="wine",
        image_url="wine_image",
        type=DrinkType.from_str("wine"),
        avg_rating=DrinkRating(value=3),
        num_of_reviews=1,
        num_of_wish=1,
    )
    orm_drink_repository.add(drink)

    actual = orm_drink_repository.find_by_drink_id(
        drink_id=DrinkId.build(drink_name="wine", created_at=1234))
    expected = Drink(
        id=DrinkId.build(drink_name="wine", created_at=1234),
        name="wine",
        image_url="wine_image",
        type=DrinkType.from_str("wine"),
        avg_rating=DrinkRating(value=3),
        num_of_reviews=1,
        num_of_wish=1,
    )

    assert actual == expected

    with pytest.raises(ResourceAlreadyExistError):
        orm_drink_repository.add(drink)
Ejemplo n.º 3
0
def test_find_by_review_id(orm_drink_repository):
    with pytest.raises(ResourceNotFoundError):
        orm_drink_repository.find_by_drink_id(
            DrinkId.from_str("35a05a4b-d9ba-5122-af75-7c0022b8bbd8"))

    a = DrinkOrm.from_drink(
        Drink(
            id=DrinkId.build(drink_name="soju1", created_at=1234),
            name="soju1",
            image_url="soju_image1",
            type=DrinkType.SOJU,
            avg_rating=DrinkRating(),
            num_of_reviews=0,
            num_of_wish=0,
        ))

    actual = orm_drink_repository.find_by_drink_id(
        drink_id=DrinkId.build(drink_name="soju1", created_at=1234))
    expected = Drink(
        id=DrinkId.build(drink_name="soju1", created_at=1234),
        name="soju1",
        image_url="soju_image1",
        type=DrinkType.from_str("soju"),
        avg_rating=DrinkRating(),
        num_of_reviews=0,
        num_of_wish=0,
    )
    assert actual == expected
Ejemplo n.º 4
0
def test_delete(orm_drink_repository):
    orm_drink_repository.find_by_drink_id(
        drink_id=DrinkId.build(drink_name="soju1", created_at=1234))

    orm_drink_repository.delete_by_drink_id(
        drink_id=DrinkId.build(drink_name="soju1", created_at=1234))

    with pytest.raises(ResourceNotFoundError):
        orm_drink_repository.delete_by_drink_id(
            drink_id=DrinkId.build(drink_name="soju1", created_at=1234))
def drink_no_review():
    return Drink(
        id=DrinkId.build(drink_name="soju1", created_at=1234),
        name="soju1",
        image_url="soju_image1",
        type=DrinkType.from_str("soju"),
        avg_rating=DrinkRating(),
        num_of_reviews=0,
        num_of_wish=0,
    )
def drink_two_reviews():
    return Drink(
        id=DrinkId.build(drink_name="soju3", created_at=1234),
        name="soju3",
        image_url="soju_image3",
        type=DrinkType.from_str("soju"),
        avg_rating=DrinkRating(value=4.5),
        num_of_reviews=2,
        num_of_wish=2,
    )
def drink_one_review():
    return Drink(
        id=DrinkId.build(drink_name="soju2", created_at=1234),
        name="soju2",
        image_url="soju_image2",
        type=DrinkType.from_str("soju"),
        avg_rating=DrinkRating(value=5),
        num_of_reviews=1,
        num_of_wish=1,
    )
Ejemplo n.º 8
0
def test_update(orm_drink_repository):
    old_drink = orm_drink_repository.find_by_drink_id(
        DrinkId.build(drink_name="soju1", created_at=1234))

    new_drink = Drink(
        id=old_drink.id,
        name=old_drink.name,
        image_url=old_drink.image_url,
        type=old_drink.type,
        avg_rating=DrinkRating(value=4.5),
        num_of_reviews=2,
        num_of_wish=1,
    )
    orm_drink_repository.update(new_drink)

    actual = orm_drink_repository.find_by_drink_id(
        DrinkId.build(drink_name="soju1", created_at=1234))
    expected = new_drink
    assert actual == expected
Ejemplo n.º 9
0
def setup(database):
    with database.session() as session:
        session.query(DrinkOrm).delete()
        session.add_all([
            DrinkOrm.from_drink(
                Drink(
                    id=DrinkId.build(drink_name="soju1", created_at=1234),
                    name="soju1",
                    image_url="soju_image1",
                    type=DrinkType.SOJU,
                    avg_rating=DrinkRating(),
                    num_of_reviews=0,
                    num_of_wish=0,
                )),
            DrinkOrm.from_drink(
                Drink(
                    id=DrinkId.build(drink_name="soju2", created_at=1234),
                    name="soju2",
                    image_url="soju_image2",
                    type=DrinkType.SOJU,
                    avg_rating=DrinkRating(value=5),
                    num_of_reviews=1,
                    num_of_wish=1,
                )),
            DrinkOrm.from_drink(
                Drink(
                    id=DrinkId.build(drink_name="beer", created_at=1234),
                    name="beer",
                    image_url="beer_image",
                    type=DrinkType.BEER,
                    avg_rating=DrinkRating(value=4.5),
                    num_of_reviews=2,
                    num_of_wish=2,
                )),
        ])
        session.commit()
Ejemplo n.º 10
0
    def create_drink(self, input_dto: CreateDrinkInputDto) -> Union[CreateDrinkOutputDto, FailedOutputDto]:
        try:
            drink = Drink(
                id=DrinkId.build(drink_name=input_dto.drink_name, created_at=time.time()),
                name=input_dto.drink_name,
                image_url=input_dto.drink_image_url,
                type=DrinkType.from_str(input_dto.drink_type),
            )

            self._drink_repository.add(drink)

            return CreateDrinkOutputDto()

        except ResourceAlreadyExistError as e:
            return FailedOutputDto.build_resource_conflict_error(message=str(e))
        except Exception as e:
            return FailedOutputDto.build_system_error(message=str(e))
from drinks.application.service import DrinkApplicationService
from drinks.domain.entities import Drink
from drinks.domain.repository import DrinkRepository
from drinks.domain.value_objects import DrinkRating, DrinkType
from shared_kernel.application.dtos import FailedOutputDto
from shared_kernel.domain.exceptions import ResourceNotFoundError, ResourceAlreadyExistError
from shared_kernel.domain.value_objects import DrinkId


@pytest.fixture(scope="function")
def drink_repository_mock():
    return mock.Mock(spec=DrinkRepository)


drink_data = [(
    DrinkId.build(drink_name="Cabernet", created_at=1234),
    "Cabernet",
    "wine_image_url",
    DrinkType.WINE,
)]


@pytest.mark.parametrize("drink_id, drink_name, drink_image_url, drink_type",
                         drink_data)
def test_find_drink_success(
    client,
    app,
    drink_repository_mock,
    drink_id,
    drink_name,
    drink_image_url,