-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from tle-ko/hepheir/issue7
Problem Statistics API 동작하도록 수정했습니다
- Loading branch information
Showing
8 changed files
with
151 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[ | ||
{ | ||
"model": "activities.crewactivity", | ||
"pk": 1, | ||
"fields": { | ||
"crew": 1, | ||
"name": "1회차", | ||
"start_at": "2024-08-01T17:04:27", | ||
"end_at": "2024-08-31T17:04:31" | ||
} | ||
}, | ||
{ | ||
"model": "activities.crewactivityproblem", | ||
"pk": 1, | ||
"fields": { | ||
"crew": 1, | ||
"activity": 1, | ||
"problem": 1, | ||
"order": 1 | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,4 @@ class ProblemTagDTO: | |
name_en: str | ||
|
||
def __hash__(self) -> int: | ||
return self.key | ||
return hash(self.key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from django.test import TestCase | ||
from rest_framework import status | ||
|
||
from apps.problems.models import Problem | ||
from users.models import User | ||
|
||
|
||
class ProblemCreateAPIViewTest(TestCase): | ||
fixtures = ['sample.json'] | ||
maxDiff = None | ||
|
||
def setUp(self) -> None: | ||
self.user = User.objects.get(pk=1) | ||
self.client.force_login(self.user) | ||
self.sample_data = { | ||
"title": "Test Problem", | ||
"link": "https://boj.kr/1000", | ||
"description": "테스트용 문제입니다.", | ||
"input_description": "입력이 없습니다.", | ||
"output_description": "출력이 없습니다.", | ||
"memory_limit": 0, | ||
"time_limit": 0, | ||
} | ||
self.required_fields = [ | ||
"title", | ||
"description", | ||
"input_description", | ||
"output_description", | ||
"memory_limit", | ||
"time_limit", | ||
] | ||
|
||
def test_201_문제_생성(self): | ||
res = self.client.post("/api/v1/problem", self.sample_data) | ||
self.assertEqual(res.status_code, status.HTTP_201_CREATED) | ||
|
||
def test_401_비로그인_사용_불가(self): | ||
self.client.logout() | ||
res = self.client.post("/api/v1/problem", self.sample_data) | ||
self.assertEqual(res.status_code, status.HTTP_401_UNAUTHORIZED) | ||
|
||
def test_201_링크가_누락_되어도_문제_생성_가능(self): | ||
data = self.sample_data.copy() | ||
del data['link'] | ||
res = self.client.post("/api/v1/problem", data) | ||
self.assertEqual(res.status_code, status.HTTP_201_CREATED) | ||
|
||
def test_400_일부_필드_누락(self): | ||
for drop_field in self.required_fields: | ||
with self.subTest(drop_field=drop_field): | ||
res = self.client.post("/api/v1/problem", { | ||
field: self.sample_data[field] | ||
for field in self.required_fields if field != drop_field | ||
}) | ||
self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST) | ||
|
||
|
||
class ProblemDetailRetrieveAPIViewTest(TestCase): | ||
fixtures = ['sample.json'] | ||
maxDiff = None | ||
|
||
def setUp(self) -> None: | ||
self.user = User.objects.get(pk=1) | ||
self.client.force_login(self.user) | ||
|
||
def test_200_문제_정보_가져오기(self): | ||
problem = Problem.objects.get(pk=1) | ||
res = self.client.get(f"/api/v1/problem/{problem.pk}/detail") | ||
self.assertEqual(res.status_code, status.HTTP_200_OK) | ||
|
||
def test_404(self): | ||
res = self.client.get(f"/api/v1/problem/999/detail") | ||
self.assertEqual(res.status_code, status.HTTP_404_NOT_FOUND) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters