|
| 1 | +from django.contrib.auth import get_user_model |
1 | 2 | from django.test import TestCase |
| 3 | +from rest_framework.test import APIRequestFactory |
2 | 4 |
|
3 | | -# Create your tests here. |
| 5 | +from program.models import Proposal, ProgramCategory |
| 6 | +from program.viewsets import ProposalViewSet |
| 7 | + |
| 8 | +User = get_user_model() |
| 9 | + |
| 10 | + |
| 11 | +class ProgramTest(TestCase): |
| 12 | + user_name = ["park", "seo", "kim", "jung", "kang"] |
| 13 | + title = ["제목1", "제목2", "제목3", "제목4", "제목5"] |
| 14 | + brief = ["brief1", "brief2", "brief3", "brief4", "brief5"] |
| 15 | + desc = ["desc1", "desc2", "desc3", "desc4", "desc5"] |
| 16 | + difficulty = ["B", "I", "E", "B", "I"] |
| 17 | + duration = ["S", "L", "S", "L", "S"] |
| 18 | + |
| 19 | + def setUp(self) -> None: |
| 20 | + # 사용자 객체 생성 |
| 21 | + for i in range(len(self.user_name)): |
| 22 | + new_user = User() |
| 23 | + new_user.username = self.user_name[i] |
| 24 | + new_user.set_password(self.user_name[i]) |
| 25 | + new_user.save() |
| 26 | + |
| 27 | + # Category 생성 |
| 28 | + new_category = ProgramCategory() |
| 29 | + new_category.name = ["카테고리"] |
| 30 | + new_category.slug = ["category"] |
| 31 | + new_category.save() |
| 32 | + |
| 33 | + # Proposal 생성 |
| 34 | + target_user = User.objects.get(username=self.user_name[0]) |
| 35 | + |
| 36 | + for i in range(len(self.user_name)): |
| 37 | + new_proposal = Proposal() |
| 38 | + new_proposal.user = target_user |
| 39 | + new_proposal.title = self.title[i] |
| 40 | + new_proposal.brief = self.brief[i] |
| 41 | + new_proposal.desc = self.desc[i] |
| 42 | + new_proposal.difficulty = self.difficulty[i] |
| 43 | + new_proposal.duration = self.duration[i] |
| 44 | + new_proposal.category = new_category |
| 45 | + |
| 46 | + new_proposal.save() |
| 47 | + |
| 48 | + def test_ProposalViewSet(self): |
| 49 | + req_body = { |
| 50 | + } |
| 51 | + |
| 52 | + request = APIRequestFactory().get("/api/program/list", req_body) |
| 53 | + response = ProposalViewSet().list(request=request) |
| 54 | + |
| 55 | + self.assertEqual(len(response.data), len(self.user_name)) |
0 commit comments