Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/market #171

Merged
merged 2 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions core/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.test import TestCase

# Create your tests here.
2 changes: 1 addition & 1 deletion market/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_service_queryset_by_market_uuid_with_temporary(
) -> QuerySet:
queryset: QuerySet = self.model.objects.filter(
market__market_uuid=market_uuid, temporary=temporary
).select_related("market")
).select_related("market", "market__reformer", "market__reformer__user")
if not queryset.exists():
raise ObjectDoesNotExist("Service not found")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ class ServiceRetrieveSerializer(serializers.ModelSerializer):
market_uuid = serializers.ReadOnlyField(
source="market.market_uuid"
) # https://www.django-rest-framework.org/api-guide/fields/#readonlyfield
reformer_nickname = serializers.ReadOnlyField(
source="market.reformer.user.nickname"
)

class Meta:
model = Service
fields = [
"reformer_nickname",
"market_uuid",
"service_uuid",
"service_title",
Expand Down
101 changes: 95 additions & 6 deletions market/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.test import override_settings
from rest_framework.test import APIClient, APITestCase

from market.models import Market
from market.models import Market, Service
from users.models.reformer import Reformer
from users.models.user import User

Expand All @@ -17,6 +17,47 @@ class MarketTestCase(APITestCase):
TEST_MARKET_NAME = "test market"
TEST_MARKET_INTRODUCE = "asdfasdfasdf"
TEST_MARKET_ADDRESS = "Seoul"
TEST_SERVICE_CREATE_DATA = {
"service_title": "reform service",
"service_content": "asdfadfgf",
"service_category": "category1",
"service_style": [
{
"style_name": "style 1"
},
{
"style_name": "style 2"
}
],
"service_period": 7,
"basic_price": 12345,
"max_price": 99999,
"service_option": [
{
"option_name": "option 1",
"option_content": "asdfasdfa",
"option_price": 123123
},
{
"option_name": "option 2",
"option_content": "asdfasdfa",
"option_price": 1256473123
},
{
"option_name": "option 3",
"option_content": "asdfasdfa",
"option_price": 12312543
}
],
"service_material": [
{
"material_name": "material 1"
},
{
"material_name": "material 2"
}
]
}

@classmethod
def setUpTestData(cls):
Expand All @@ -26,7 +67,7 @@ def setUpTestData(cls):
email=cls.TEST_CUSTOMER_EMAIL,
password=cls.TEST_PASSWORD,
phone="01012341234",
nickname="nickname",
nickname="test_customer",
introduce="hello, django",
role="customer",
is_active=True,
Expand All @@ -49,14 +90,16 @@ def setUp(self):
email=self.TEST_EMAIL,
password=self.TEST_PASSWORD,
phone="01012341234",
nickname="nickname",
nickname="test_user_hello",
introduce="hello, django",
role="reformer",
is_active=True,
agreement_terms=True,
)
self.reformer = Reformer.objects.create(
user=self.test_user, reformer_link="www.naver.com", reformer_area="Seoul"
user=self.test_user,
reformer_link="www.naver.com",
reformer_area="Seoul"
)
self.token = self.client.post(
path=f"/api/user/login",
Expand Down Expand Up @@ -88,7 +131,7 @@ def test_market_create_without_reformer(self):
path="/api/market",
data={
"market_name": "Invalid market",
"market_introduce": "SHOULD NOT CREATED",
"market_introduce": "SHOULD NOT BE CREATED",
"market_address": "ABC",
},
format="json",
Expand Down Expand Up @@ -127,7 +170,7 @@ def test_forbid_market_create_more_than_one(self):
self.assertEqual(invalid_response.status_code, 400)

def test_get_market_info(self):
# 마켓 정보 생성
# 마켓 정보 가져오기 테스트
self.client.post(
path="/api/market",
data={
Expand All @@ -140,6 +183,7 @@ def test_get_market_info(self):

# 마켓 정보 획득
response = self.client.get(path="/api/market", format="json")
print(response.data)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["market_name"], "test market")
self.assertEqual(response.data["market_introduce"], "Seoul")
Expand Down Expand Up @@ -253,7 +297,52 @@ def test_delete_market_info(self, mock_boto3_client: MagicMock):
# 마켓 정보가 삭제 되었는지 확인
self.assertEqual(Market.objects.filter(market_uuid=market_uuid).count(), 0)

def test_get_service_list(self):
# 서비스 리스트 가져오기 테스트

# 1. 테스트 마켓 생성
response = self.client.post(
path="/api/market",
data={
"market_name": self.TEST_MARKET_NAME,
"market_introduce": self.TEST_MARKET_INTRODUCE,
"market_address": self.TEST_MARKET_ADDRESS
},
format="json"
)
self.assertEqual(response.status_code, 201)
market_uuid = response.data.get("market_uuid", None)
self.assertIsNotNone(market_uuid, None)

# 2. 해당 마켓에 대한 서비스 10개 생성
for i in range(10):
response = self.client.post(
path=f"/api/market/{market_uuid}/service",
data=self.TEST_SERVICE_CREATE_DATA,
format="json"
)
self.assertEqual(response.status_code, 201)

# 3. DB에 존재하는 전체 서비스 리스트 가져오기 (10개 만들었으니까 총 10개 있어야 함)
response = self.client.get(
path=f"/api/market/services",
format="json"
)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data.get("results", None)), 10)

# 4. 특정 market에 속한 서비스 리스트 가져오기
# market_uuid에 10개 만들었으므로 10개 있어야함
response = self.client.get(
path=f"/api/market/{market_uuid}/service",
format="json"
)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 10)


def tearDown(self):
Service.objects.all().delete()
Market.objects.all().delete()
Reformer.objects.all().delete()
User.objects.all().delete()
2 changes: 1 addition & 1 deletion market/views/service_view/service_create_list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_permissions(self):
@view_exception_handler
def get(self, request, **kwargs):
"""
market uuid를 사용하여 서비스 리스트를 반환하는 메서드
마켓에 생성된 서비스 리스트를 반환하는 로직을 처리하는 View
"""
temporary_status = temporary_status_check(request)
queryset = self.get_queryset(
Expand Down
Loading
Loading