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

service PUT api 수정 (suspend 필드 업데이트 추가), 테스트 코드 추가 #177

Merged
merged 1 commit into from
Jan 9, 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Meta:
"service_period",
"basic_price",
"max_price",
"suspended",
]
extra_kwargs = {
"service_title": {"required": False},
Expand All @@ -21,6 +22,7 @@ class Meta:
"service_period": {"required": False},
"basic_price": {"required": False},
"max_price": {"required": False},
"suspended": {"required": False},
}

def validate(self, attrs):
Expand Down Expand Up @@ -68,5 +70,6 @@ def update(self, instance, validated_data):
instance.service_period = validated_data.get(
"service_period", instance.service_period
)
instance.suspended = validated_data.get("suspended", instance.suspended)
instance.save()
return instance
41 changes: 40 additions & 1 deletion market/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ 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 @@ -323,6 +322,46 @@ def test_get_service_list(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 10)

def test_service_update_suspend_field(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. 해당 마켓에 대한 서비스 생성
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)
service_uuid = response.data.get("service_uuid", None)
self.assertNotEqual(service_uuid, None)

service: Suspended = Service.objects.filter(service_uuid=service_uuid).first()
self.assertEqual(service.suspended, False)

# 3. 서비스 suspended 업데이트 시도
response = self.client.put(
path=f"/api/market/{market_uuid}/service/{service_uuid}",
data={"suspended": True},
format="json",
)
self.assertEqual(response.status_code, 200)
updated_service: Service = Service.objects.filter(
service_uuid=service_uuid
).first()
self.assertNotEqual(service.suspended, updated_service.suspended)

def tearDown(self):
Service.objects.all().delete()
Market.objects.all().delete()
Expand Down
Loading