Skip to content

Commit

Permalink
테스트 커버리지 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
riroan committed Aug 24, 2024
1 parent e5eae78 commit 2f7b0e7
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion db.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
]

Expand Down
40 changes: 40 additions & 0 deletions tests/e2e/test_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 19 additions & 0 deletions tests/e2e/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2f7b0e7

Please sign in to comment.