Skip to content

Commit 5ee94b5

Browse files
committed
tests: add tests for users declaring interest in a patch
Signed-off-by: andrepapoti <andrepapoti@gmail.com>
1 parent c6b54a4 commit 5ee94b5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

patchwork/tests/api/test_patch.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from rest_framework import status
1313

1414
from patchwork.models import Patch
15+
from patchwork.models import PatchReviewIntention
1516
from patchwork.tests.api import utils
1617
from patchwork.tests.utils import create_maintainer
1718
from patchwork.tests.utils import create_patch
@@ -456,3 +457,37 @@ def test_delete(self):
456457
self.client.authenticate(user=user)
457458
resp = self.client.delete(self.api_url(patch.id))
458459
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

Comments
 (0)