Skip to content

Commit 2e3da7b

Browse files
tests: update patch view tests
Signed-off-by: Victor Accarini <victor.accarini@profusion.mobi>
1 parent a4603b4 commit 2e3da7b

File tree

2 files changed

+138
-2
lines changed

2 files changed

+138
-2
lines changed

patchwork/tests/test_signals.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from django.test import TestCase
77

8-
from patchwork.models import Event
8+
from patchwork.models import Event, PatchAttentionSet
99
from patchwork.tests import utils
1010

1111
BASE_FIELDS = [
@@ -311,3 +311,19 @@ def test_patch_comment_created(self):
311311
)
312312
self.assertEqual(events[0].project, comment.patch.project)
313313
self.assertEventFields(events[0])
314+
315+
def test_comment_removes_user_from_attention_set(self):
316+
patch = utils.create_patch()
317+
user = utils.create_user()
318+
submitter = utils.create_person(user=user)
319+
interest = utils.create_attention_set(patch=patch, user=user)
320+
321+
# we have an active interest
322+
self.assertFalse(interest.removed)
323+
utils.create_patch_comment(patch=patch, submitter=submitter)
324+
325+
attention_set = PatchAttentionSet.raw_objects.filter(
326+
patch=patch, user=user
327+
).all()
328+
self.assertEqual(len(attention_set), 1)
329+
self.assertTrue(attention_set[0].removed)

patchwork/tests/views/test_patch.py

+121-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from patchwork.models import Check
1818
from patchwork.models import Patch
1919
from patchwork.models import State
20-
from patchwork.tests.utils import create_check
20+
from patchwork.tests.utils import create_attention_set, create_check
2121
from patchwork.tests.utils import create_maintainer
2222
from patchwork.tests.utils import create_patch
2323
from patchwork.tests.utils import create_patch_comment
@@ -205,6 +205,10 @@ def test_utf8_handling(self):
205205

206206

207207
class PatchViewTest(TestCase):
208+
def setUp(self):
209+
self.project = create_project()
210+
self.maintainer = create_maintainer(self.project)
211+
208212
def test_redirect(self):
209213
patch = create_patch()
210214

@@ -380,6 +384,122 @@ def test_patch_with_checks(self):
380384
),
381385
)
382386

387+
def test_patch_with_attention_set(self):
388+
user = create_user()
389+
patch = create_patch(project=self.project)
390+
create_attention_set(patch=patch, user=user)
391+
create_attention_set(patch=patch, user=self.maintainer)
392+
393+
self.client.login(
394+
username=self.maintainer.username,
395+
password=self.maintainer.username,
396+
)
397+
requested_url = reverse(
398+
'patch-detail',
399+
kwargs={
400+
'project_id': patch.project.linkname,
401+
'msgid': patch.encoded_msgid,
402+
},
403+
)
404+
response = self.client.get(requested_url)
405+
406+
# the response should contain attention set list
407+
self.assertContains(response, '<h2>Users pending actions</h2>')
408+
409+
# and it should show the existing users in the list
410+
self.assertEqual(
411+
response.content.decode().count(
412+
f'{self.maintainer.username} ({self.maintainer.email})'
413+
),
414+
1,
415+
)
416+
self.assertEqual(
417+
response.content.decode().count(f'{user.username} ({user.email})'),
418+
1,
419+
)
420+
421+
# should display remove button for all
422+
self.assertEqual(
423+
response.content.decode().count('glyphicon-trash'),
424+
2,
425+
)
426+
427+
def test_patch_with_anonymous_user_with_attention_list(self):
428+
# show not show a declare interest button nor remove buttons
429+
user = create_user()
430+
patch = create_patch(project=self.project)
431+
create_attention_set(patch=patch, user=user)
432+
create_attention_set(patch=patch, user=self.maintainer)
433+
434+
requested_url = reverse(
435+
'patch-detail',
436+
kwargs={
437+
'project_id': patch.project.linkname,
438+
'msgid': patch.encoded_msgid,
439+
},
440+
)
441+
response = self.client.get(requested_url)
442+
443+
self.assertEqual(
444+
response.content.decode().count('Declare interest'),
445+
0,
446+
)
447+
self.assertEqual(
448+
response.content.decode().count('glyphicon-trash'),
449+
0,
450+
)
451+
452+
def test_patch_with_user_not_in_attention_list(self):
453+
# a declare interest button should be displayed
454+
patch = create_patch(project=self.project)
455+
456+
self.client.login(
457+
username=self.maintainer.username,
458+
password=self.maintainer.username,
459+
)
460+
requested_url = reverse(
461+
'patch-detail',
462+
kwargs={
463+
'project_id': patch.project.linkname,
464+
'msgid': patch.encoded_msgid,
465+
},
466+
)
467+
response = self.client.get(requested_url)
468+
469+
self.assertEqual(
470+
response.content.decode().count('Declare interest'),
471+
1,
472+
)
473+
474+
def test_patch_with_user_in_attention_list(self):
475+
# a remove button should be displayed if he is authenticated
476+
# should not show option for other users
477+
user = create_user()
478+
patch = create_patch(project=self.project)
479+
create_attention_set(patch=patch, user=user)
480+
create_attention_set(patch=patch, user=self.maintainer)
481+
482+
self.client.login(
483+
username=user.username,
484+
password=user.username,
485+
)
486+
requested_url = reverse(
487+
'patch-detail',
488+
kwargs={
489+
'project_id': patch.project.linkname,
490+
'msgid': patch.encoded_msgid,
491+
},
492+
)
493+
response = self.client.get(requested_url)
494+
self.assertEqual(
495+
response.content.decode().count(f'{user.username} ({user.email})'),
496+
1,
497+
)
498+
self.assertEqual(
499+
response.content.decode().count('glyphicon-trash'),
500+
1,
501+
)
502+
383503

384504
class PatchUpdateTest(TestCase):
385505
properties_form_id = 'patch-form-properties'

0 commit comments

Comments
 (0)