def test_delete_drink_wish_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 = DeleteDrinkWishInputDto(drink_id=str(drink_id))
    actual = drink_application_service.delete_drink_wish(input_dto)
    expected = FailedOutputDto(type="Resource Not Found Error", message="")
    assert actual == expected

    drink_repository_mock.find_by_drink_id.return_value = None
    drink_repository_mock.update.side_effect = ResourceNotFoundError()
    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 = FailedOutputDto(type="Resource Not Found Error", message="")
    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
Ejemplo n.º 3
0
 def find_by_review_id(self, review_id: ReviewId) -> Optional[Review]:
     with self._session_factory() as session:
         review_orm = session.query(ReviewOrm).filter(
             ReviewOrm.id == str(review_id)).first()
         if review_orm is None:
             raise ResourceNotFoundError(f"{str(review_id)}의 리뷰를 찾지 못했습니다.")
         return review_orm.to_review()
Ejemplo n.º 4
0
 def update(self, user: User) -> None:
     with self._session_factory() as session:
         user_orm = session.query(UserOrm).filter(UserOrm.id == str(user.id)).first()
         if user_orm is None:
             raise ResourceNotFoundError(f"{str(user.id)}의 유저를 찾지 못했습니다.")
         user_orm.fetch_user(user)
         session.commit()
Ejemplo n.º 5
0
 def find_by_drink_id(self, drink_id: DrinkId) -> Optional[Drink]:
     with self._session_factory() as session:
         drink_orm = session.query(DrinkOrm).filter(
             DrinkOrm.id == str(drink_id)).first()
         if drink_orm is None:
             raise ResourceNotFoundError(f"{str(drink_id)}의 리뷰를 찾지 못했습니다.")
         return drink_orm.to_drink()
Ejemplo n.º 6
0
 def delete_by_user_id(self, user_id: UserId) -> None:
     with self._session_factory() as session:
         user_orm = session.query(UserOrm).filter(UserOrm.id == str(user_id)).first()
         if user_orm is None:
             raise ResourceNotFoundError(f"{str(user_id)}의 유저를 찾지 못했습니다.")
         session.delete(user_orm)
         session.commit()
def test_delete_review_fail(
    review_repository_mock,
    drink_application_service_mock,
    review_id,
    drink_id,
    user_id,
    rating,
    created_at,
):
    review_repository_mock.find_by_review_id.return_value = Review(
        id=review_id,
        drink_id=drink_id,
        user_id=UserId(value=user_id),
        rating=ReviewRating(value=rating),
        comment="hello",
        created_at=created_at,
        updated_at=created_at,
    )
    review_repository_mock.delete_by_review_id.side_effect = ResourceNotFoundError(
    )
    review_application_service = ReviewApplicationService(
        review_repository=review_repository_mock)

    drink_application_service_mock.delete_drink_review.return_value = DeleteDrinkReviewOutputDto(
    )

    input_dto = DeleteReviewInputDto(review_id=str(review_id))
    actual = review_application_service.delete_review(
        input_dto, drink_application_service_mock)
    expected = FailedOutputDto(type="Resource Not Found Error", message="")
    assert actual == expected
Ejemplo n.º 8
0
 def find(self, query_param: QueryParam) -> Wish:
     query_param = {attr: value for attr, value in query_param if value}
     with self._session_factory() as session:
         query = session.query(WishOrm)
         wish_orm = query.filter_by(**query_param).first()
         if wish_orm is None:
             raise ResourceNotFoundError(f"해당하는 위시를 찾지 못했습니다.")
         return wish_orm.to_wish()
Ejemplo n.º 9
0
 def update(self, review: Review) -> None:
     with self._session_factory() as session:
         review_orm = session.query(ReviewOrm).filter(
             ReviewOrm.id == str(review.id)).first()
         if review_orm is None:
             raise ResourceNotFoundError(f"{str(review.id)}의 리뷰를 찾지 못했습니다.")
         review_orm.fetch_review(review)
         session.commit()
Ejemplo n.º 10
0
 def delete_by_drink_id(self, drink_id: DrinkId) -> None:
     with self._session_factory() as session:
         drink_orm = session.query(DrinkOrm).filter(
             DrinkOrm.id == str(drink_id)).first()
         if drink_orm is None:
             raise ResourceNotFoundError(f"{str(drink_id)}의 리뷰를 찾지 못했습니다.")
         session.delete(drink_orm)
         session.commit()
Ejemplo n.º 11
0
 def delete_by_wish_id(self, wish_id: WishId) -> Wish:
     with self._session_factory() as session:
         wish_orm = session.query(WishOrm).filter(WishOrm.id == wish_id.uuid).first()
         if wish_orm is None:
             raise ResourceNotFoundError(f"{str(wish_id)}의 위시를 찾지 못했습니다.")
         session.delete(wish_orm)
         session.commit()
         return wish_orm.to_wish()
Ejemplo n.º 12
0
 def delete_by_review_id(self, review_id: ReviewId) -> None:
     with self._session_factory() as session:
         review_orm = session.query(ReviewOrm).filter(
             ReviewOrm.id == str(review_id)).first()
         if review_orm is None:
             raise ResourceNotFoundError(f"{str(review_id)}의 리뷰를 찾지 못했습니다.")
         session.delete(review_orm)
         session.commit()
def test_find_user_fail(user_repository_mock, user_id, user_name, password):
    user_repository_mock.find_by_user_id.side_effect = ResourceNotFoundError()
    user_application_service = UserApplicationService(
        user_repository=user_repository_mock)

    input_dto = FindUserInputDto(user_id="not exist user")
    actual = user_application_service.find_user(input_dto)
    expected = FailedOutputDto(type="Resource Not Found Error", message="")
    assert actual == expected
Ejemplo n.º 14
0
    def update(self, drink: Drink) -> None:
        with self._session_factory() as session:
            drink_orm = session.query(DrinkOrm).filter(
                DrinkOrm.id == str(drink.id)).first()

            if drink_orm is None:
                raise ResourceNotFoundError(f"{str(drink.id)}의 리뷰를 찾지 못했습니다.")

            drink_orm.fetch_drink(drink)
            session.commit()
def test_login_fail_with_wrong_id(user_repository_mock):
    wrong_user_id = "joon"
    user_repository_mock.find_by_user_id.side_effect = ResourceNotFoundError(
        f"{wrong_user_id}의 유저를 찾지 못했습니다.")
    user_application_service = UserApplicationService(
        user_repository=user_repository_mock)

    input_dto = LoginInputDto(user_id=wrong_user_id, password="******")
    actual = user_application_service.login(input_dto)
    expected = FailedOutputDto.build_resource_not_found_error(
        message=f"{str(input_dto.user_id)}의 유저를 찾지 못했습니다.")
    assert actual == expected
def test_update_user_fail(user_repository_mock, user_id, user_name, password):
    user_repository_mock.update.side_effect = ResourceNotFoundError()
    user_application_service = UserApplicationService(
        user_repository=user_repository_mock)

    input_dto = UpdateUserInputDto(user_id=user_id,
                                   user_name="heumsi",
                                   description="",
                                   password="******")
    actual = user_application_service.update_user(input_dto)
    expected = FailedOutputDto(type="Resource Not Found Error", message="")
    assert actual == expected
Ejemplo n.º 17
0
 def find(self, query_param: QueryParam) -> Review:
     if not query_param.user_id or not query_param.drink_id:
         raise InvalidParamInputError(
             f"drink_id: {query_param.drink_id} and user_id:{query_param.user_id}에 해당하는 값이 없습니다."
         )
     _query_param = {
         attr: value
         for attr, value in query_param
         if value and not isinstance(value, OrderType)
     }
     with self._session_factory() as session:
         query = session.query(ReviewOrm)
         review_orm = query.filter_by(**_query_param).first()
         if review_orm is None:
             raise ResourceNotFoundError(f"리뷰를 찾지 못했습니다.")
         return review_orm.to_review()
def test_find_drink_fail(
    client,
    app,
    drink_repository_mock,
    drink_id,
    drink_name,
    drink_image_url,
    drink_type,
):
    drink_repository_mock.find_by_drink_id.side_effect = ResourceNotFoundError(
    )
    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 = FailedOutputDto(type="Resource Not Found Error", message="")
    assert actual == expected
def test_find_review_fail(
    review_repository_mock,
    review_id,
    drink_id,
    user_id,
    rating,
    created_at,
):
    review_repository_mock.find_by_review_id.side_effect = ResourceNotFoundError(
    )
    review_application_service = ReviewApplicationService(
        review_repository=review_repository_mock)

    input_dto = FindReviewInputDto(review_id=str(review_id))
    actual = review_application_service.find_review(input_dto)
    expected = FailedOutputDto(type="Resource Not Found Error", message="")

    assert actual == expected
def test_update_drink_fail(
    drink_repository_mock,
    drink_id,
    drink_name,
    drink_image_url,
    drink_type,
):
    drink_repository_mock.update.side_effect = ResourceNotFoundError()
    drink_application_service = DrinkApplicationService(
        drink_repository=drink_repository_mock)

    input_dto = UpdateDrinkInputDto(
        drink_id=str(drink_id),
        drink_name="Tequila",
        drink_image_url="tequila image url",
        drink_type=DrinkType.LIQUOR.value,
        avg_rating=float(DrinkRating(value=3.65)),
        num_of_reviews=10,
        num_of_wish=20,
    )

    actual = drink_application_service.update_drink(input_dto)
    expected = FailedOutputDto(type="Resource Not Found Error", message="")
    assert actual == expected
Ejemplo n.º 21
0
 def find_by_user_id(self, user_id: UserId) -> User:
     with self._session_factory() as session:
         user_orm = session.query(UserOrm).filter(UserOrm.id == str(user_id)).first()
         if user_orm is None:
             raise ResourceNotFoundError(f"{str(user_id)}의 유저를 찾지 못했습니다.")
         return user_orm.to_user()