|
3 | 3 | from rest_framework import status |
4 | 4 | from rest_framework.test import APIRequestFactory, force_authenticate |
5 | 5 |
|
6 | | - |
| 6 | +from .models import Problem |
7 | 7 | from .views import ProblemView, TagView |
8 | 8 | from account.models import User |
9 | 9 |
|
@@ -61,6 +61,31 @@ def testX_post_new_problem(self): |
61 | 61 | response = self.view(request) |
62 | 62 | self.assertEqual(response.status_code, status.HTTP_201_CREATED) |
63 | 63 |
|
| 64 | + def testW_change_problem(self): |
| 65 | + request_data = { |
| 66 | + "title": "Not Hard Problem", |
| 67 | + "description": "This is description", |
| 68 | + "pid": 8, |
| 69 | + "allow_html": True, |
| 70 | + "tags": [4, 3, 1] |
| 71 | + } |
| 72 | + |
| 73 | + ac_data = { |
| 74 | + "enabled": True |
| 75 | + } |
| 76 | + |
| 77 | + request = self.factory.patch(self.base_url, data=request_data) |
| 78 | + force_authenticate(request, User.objects.get(username="admin")) |
| 79 | + response = self.view(request, pid=5) |
| 80 | + self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) |
| 81 | + |
| 82 | + target = Problem.objects.get(pid=8) |
| 83 | + self.assertEqual(target.pid, request_data["pid"]) |
| 84 | + self.assertEqual(target.description, request_data["description"]) |
| 85 | + self.assertEqual(target.title, request_data["title"]) |
| 86 | + self.assertEqual(target.allow_html, request_data["allow_html"]) |
| 87 | + self.assertEqual(target.enabled, ac_data["enabled"]) |
| 88 | + |
64 | 89 |
|
65 | 90 | class TagViewTest(TestCase): |
66 | 91 | fixtures = ["testdatabase.yaml"] |
|
0 commit comments