From 2f7b0e77f254a267cd8cc7aa546343ad889b912d Mon Sep 17 00:00:00 2001 From: riroan Date: Sun, 25 Aug 2024 00:56:15 +0900 Subject: [PATCH] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BB=A4?= =?UTF-8?q?=EB=B2=84=EB=A6=AC=EC=A7=80=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db.py | 2 +- tests/conftest.py | 6 ++++++ tests/e2e/test_like.py | 40 +++++++++++++++++++++++++++++++++++++++ tests/e2e/test_product.py | 19 +++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/db.py b/db.py index c6a260b..c563351 100644 --- a/db.py +++ b/db.py @@ -1,4 +1,4 @@ -from sqlalchemy import URL, create_engine +from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy.orm.session import Session diff --git a/tests/conftest.py b/tests/conftest.py index 0e8969f..3bc82a5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -96,6 +96,12 @@ async def like(): is_like=LikeStatus.DISLIKE, user_id=1, product_id=1 + ), + Like( + id=2, + is_like=LikeStatus.LIKE, + user_id=2, + product_id=2 ) ] diff --git a/tests/e2e/test_like.py b/tests/e2e/test_like.py index 3936473..f8ad69e 100644 --- a/tests/e2e/test_like.py +++ b/tests/e2e/test_like.py @@ -41,3 +41,43 @@ async def test_dislike_returns_201( } ) assert response.status_code == status.HTTP_201_CREATED + + +@pytest.mark.asyncio +async def test_like_returns_201_when_update( + test_fastapi_app, bootstrap +): + async with AsyncClient( + transport=ASGITransport(app=test_fastapi_app), base_url="http://test" + ) as client: + response = await client.post( + "/like", + headers={ + "Content-Type": "application/json" + }, + json={ + "user_id": 1, + "product_id": 1 + } + ) + assert response.status_code == status.HTTP_201_CREATED + + +@pytest.mark.asyncio +async def test_dislike_returns_201_when_update( + test_fastapi_app, bootstrap +): + async with AsyncClient( + transport=ASGITransport(app=test_fastapi_app), base_url="http://test" + ) as client: + response = await client.post( + "/dislike", + headers={ + "Content-Type": "application/json" + }, + json={ + "user_id": 2, + "product_id": 2 + } + ) + assert response.status_code == status.HTTP_201_CREATED diff --git a/tests/e2e/test_product.py b/tests/e2e/test_product.py index 6782856..2ae757c 100644 --- a/tests/e2e/test_product.py +++ b/tests/e2e/test_product.py @@ -24,6 +24,25 @@ async def test_show_product_detail_returns_200( assert result["image_path"] == helper.TEST_PRODUCT_IMAGE_PATH_1 +@pytest.mark.asyncio +async def test_show_product_detail_returns_200_when_last_id( + test_fastapi_app, bootstrap +): + async with AsyncClient( + transport=ASGITransport(app=test_fastapi_app), base_url="http://test" + ) as client: + response = await client.get("/product/100/1") + + assert response.status_code == status.HTTP_200_OK + + result = response.json() + + assert result["name"] == helper.TEST_PRODUCT_NAME_1 + assert result["price"] == helper.TEST_PRODUCT_PRICE_1 + assert result["summary"] == helper.TEST_PRODUCT_SUMMARY_1 + assert result["image_path"] == helper.TEST_PRODUCT_IMAGE_PATH_1 + + @pytest.mark.asyncio async def test_list_product_returns_200( test_fastapi_app, bootstrap, product