|
12 | 12 | from rest_framework import status
|
13 | 13 |
|
14 | 14 | from patchwork.models import Patch
|
| 15 | +from patchwork.models import PatchReviewIntention |
15 | 16 | from patchwork.tests.api import utils
|
16 | 17 | from patchwork.tests.utils import create_maintainer
|
17 | 18 | from patchwork.tests.utils import create_patch
|
@@ -456,3 +457,37 @@ def test_delete(self):
|
456 | 457 | self.client.authenticate(user=user)
|
457 | 458 | resp = self.client.delete(self.api_url(patch.id))
|
458 | 459 | self.assertEqual(status.HTTP_405_METHOD_NOT_ALLOWED, resp.status_code)
|
| 460 | + |
| 461 | + def test_declare_review_intention(self): |
| 462 | + project = create_project() |
| 463 | + state = create_state() |
| 464 | + patch = create_patch(project=project, state=state) |
| 465 | + user = create_user() |
| 466 | + |
| 467 | + self.client.authenticate(user=user) |
| 468 | + resp = self.client.patch( |
| 469 | + self.api_url(patch.id), |
| 470 | + {'planning_to_review': [{'user': user.id, 'patch': patch.id}]}, |
| 471 | + ) |
| 472 | + |
| 473 | + self.assertEqual(resp.status_code, status.HTTP_200_OK) |
| 474 | + self.assertEqual(len(PatchReviewIntention.objects.all()), 1) |
| 475 | + self.assertEqual( |
| 476 | + len(PatchReviewIntention.objects.filter(user=user, patch=patch)), 1 |
| 477 | + ) |
| 478 | + |
| 479 | + def test_declare_review_intention_for_different_user(self): |
| 480 | + project = create_project() |
| 481 | + state = create_state() |
| 482 | + patch = create_patch(project=project, state=state) |
| 483 | + user_a = create_user() |
| 484 | + user_b = create_user() |
| 485 | + |
| 486 | + self.client.authenticate(user=user_a) |
| 487 | + resp = self.client.patch( |
| 488 | + self.api_url(patch.id), |
| 489 | + {'planning_to_review': [{'user': user_b.id, 'patch': patch.id}]}, |
| 490 | + ) |
| 491 | + |
| 492 | + self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN) |
| 493 | + self.assertEqual(len(PatchReviewIntention.objects.all()), 0) |
0 commit comments