44from rest_framework .test import APIRequestFactory , force_authenticate
55
66from .models import Problem
7- from .views import ProblemView , TagView , TagListView
7+ from .views import ProblemView , ProblemDescriptionView , TagView , TagListView
88from account .models import User
99
1010# Create your tests here.
@@ -21,7 +21,6 @@ def setUp(self):
2121 def testZ_get_problem (self ):
2222 ac_data = {
2323 "title" : "Simple Problem" ,
24- "description" : "This is description" ,
2524 "pid" : 5 ,
2625 "allow_html" : False ,
2726 "enabled" : True ,
@@ -38,7 +37,6 @@ def testZ_get_problem(self):
3837 self .assertIsNotNone (data )
3938
4039 self .assertEqual (data .get ("title" ), ac_data ["title" ])
41- self .assertEqual (data .get ("description" ), ac_data ["description" ])
4240 self .assertEqual (data .get ("pid" ), ac_data ["pid" ])
4341 self .assertEqual (data .get ("allow_html" ), ac_data ["allow_html" ])
4442 self .assertEqual (data .get ("enabled" ), ac_data ["enabled" ])
@@ -87,6 +85,28 @@ def testW_change_problem(self):
8785 self .assertEqual (target .enabled , ac_data ["enabled" ])
8886
8987
88+ class ProblemDescriptionViewTest (TestCase ):
89+ fixtures = ["testdatabase.yaml" ]
90+
91+ def setUp (self ):
92+ self .base_url = "/api/problem/{pid}/description"
93+ self .factory = APIRequestFactory ()
94+ self .view = ProblemDescriptionView .as_view ()
95+
96+ def testZ_get_problem_description (self ):
97+ ac_data = {
98+ "description" : "This is description"
99+ }
100+
101+ request = self .factory .get (self .base_url .format (pid = 5 ))
102+ response = self .view (request , pid = 5 )
103+ self .assertEqual (response .status_code , status .HTTP_200_OK )
104+
105+ data = response .data .get ("res" )
106+ self .assertIsNotNone (data )
107+ self .assertEqual (data .get ("description" ), ac_data ["description" ])
108+
109+
90110class TagViewTest (TestCase ):
91111 fixtures = ["testdatabase.yaml" ]
92112
0 commit comments