Skip to content

Commit

Permalink
service PUT api 수정 (suspend 필드 업데이트 추가), 테스트 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Scanf-s committed Jan 9, 2025
1 parent e5beae7 commit b20e0ce
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
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

0 comments on commit b20e0ce

Please sign in to comment.