Exemple #1
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
Exemple #2
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
Exemple #3
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)
def test_find_drink_success(
    client,
    app,
    drink_repository_mock,
    drink_id,
    drink_name,
    drink_image_url,
    drink_type,
):
    drink_repository_mock.find_by_drink_id.return_value = Drink(
        id=drink_id,
        name=drink_name,
        image_url=drink_image_url,
        type=drink_type)
    drink_application_service = DrinkApplicationService(
        drink_repository=drink_repository_mock)
    input_dto = FindDrinkInputDto(drink_id=str(drink_id))
    actual = drink_application_service.find_drink(input_dto)
    expected = FindDrinkOutputDto(
        drink_id=str(drink_id),
        drink_name=drink_name,
        drink_image_url=drink_image_url,
        drink_type=drink_type.value,
        avg_rating=float(DrinkRating()),
        num_of_reviews=0,
        num_of_wish=0,
    )
    assert actual == expected
def test_add_drink_review_fail(
    drink_repository_mock,
    drink_id,
    drink_name,
    drink_image_url,
    drink_type,
):
    drink_repository_mock.find_by_drink_id.side_effect = ResourceNotFoundError(
    )
    drink_repository_mock.update.return_value = None
    drink_application_service = DrinkApplicationService(
        drink_repository=drink_repository_mock)

    input_dto = AddDrinkReviewInputDto(drink_id=str(drink_id), drink_rating=5)

    actual = drink_application_service.add_drink_review(input_dto)
    expected = FailedOutputDto(type="Resource Not Found Error", message="")
    assert actual == expected

    drink_repository_mock.find_by_drink_id.return_value = Drink(
        id=drink_id,
        name=drink_name,
        image_url=drink_image_url,
        type=drink_type)
    drink_repository_mock.update.return_value = ResourceNotFoundError()
    drink_application_service = DrinkApplicationService(
        drink_repository=drink_repository_mock)

    input_dto = AddDrinkReviewInputDto(drink_id=str(drink_id), drink_rating=5)

    actual = drink_application_service.add_drink_review(input_dto)
    expected = FailedOutputDto(type="Resource Not Found Error", message="")
    assert actual == expected
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,
    )
Exemple #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()
Exemple #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))
Exemple #11
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
def test_delete_drink_wish_success(
    drink_repository_mock,
    drink_id,
    drink_name,
    drink_image_url,
    drink_type,
):
    drink_repository_mock.find_by_drink_id.return_value = Drink(
        id=drink_id,
        name=drink_name,
        image_url=drink_image_url,
        type=drink_type)
    drink_repository_mock.update.return_value = None
    drink_application_service = DrinkApplicationService(
        drink_repository=drink_repository_mock)

    input_dto = DeleteDrinkWishInputDto(drink_id=str(drink_id))
    actual = drink_application_service.delete_drink_wish(input_dto)
    expected = DeleteDrinkWishOutputDto()
    assert actual == expected
def test_add_drink_review_success(
    drink_repository_mock,
    drink_id,
    drink_name,
    drink_image_url,
    drink_type,
):
    drink_repository_mock.find_by_drink_id.return_value = Drink(
        id=drink_id,
        name=drink_name,
        image_url=drink_image_url,
        type=drink_type)
    drink_repository_mock.update.return_value = None
    drink_application_service = DrinkApplicationService(
        drink_repository=drink_repository_mock)

    input_dto = AddDrinkReviewInputDto(drink_id=str(drink_id), drink_rating=5)

    actual = drink_application_service.add_drink_review(input_dto)
    expected = AddDrinkReviewOutputDto()
    assert actual == expected
Exemple #14
0
    def update_drink(self, input_dto: UpdateDrinkInputDto) -> Union[UpdateDrinkOutputDto, FailedOutputDto]:
        try:
            drink_id = DrinkId.from_str(input_dto.drink_id)
            if self._drink_repository.find_by_drink_id(drink_id) is None:
                return FailedOutputDto.build_resource_not_found_error(f"{str(drink_id)}의 술을 찾을 수 없습니다.")

            drink = Drink(
                id=drink_id,
                name=input_dto.drink_name,
                image_url=input_dto.drink_image_url,
                type=input_dto.drink_type,
                avg_rating=DrinkRating(value=input_dto.avg_rating),
                num_of_reviews=input_dto.num_of_reviews,
                num_of_wish=input_dto.num_of_wish,
            )
            self._drink_repository.update(drink)

            return UpdateDrinkOutputDto()

        except ResourceNotFoundError as e:
            return FailedOutputDto.build_resource_not_found_error(message=str(e))
        except Exception as e:
            return FailedOutputDto.build_system_error(message=str(e))