Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tests: update patch view tests
Signed-off-by: Victor Accarini <victor.accarini@profusion.mobi>
  • Loading branch information
victor-accarini committed May 8, 2025
commit 748355a6a50b0054167a8c06f5571d04f8f8731c
18 changes: 17 additions & 1 deletion patchwork/tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from django.test import TestCase

from patchwork.models import Event
from patchwork.models import Event, PatchAttentionSet
from patchwork.tests import utils

BASE_FIELDS = [
Expand Down Expand Up @@ -311,3 +311,19 @@ def test_patch_comment_created(self):
)
self.assertEqual(events[0].project, comment.patch.project)
self.assertEventFields(events[0])

def test_comment_removes_user_from_attention_set(self):
patch = utils.create_patch()
user = utils.create_user()
submitter = utils.create_person(user=user)
interest = utils.create_attention_set(patch=patch, user=user)

# we have an active interest
self.assertFalse(interest.removed)
utils.create_patch_comment(patch=patch, submitter=submitter)

attention_set = PatchAttentionSet.raw_objects.filter(
patch=patch, user=user
).all()
self.assertEqual(len(attention_set), 1)
self.assertTrue(attention_set[0].removed)
122 changes: 121 additions & 1 deletion patchwork/tests/views/test_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from patchwork.models import Check
from patchwork.models import Patch
from patchwork.models import State
from patchwork.tests.utils import create_check
from patchwork.tests.utils import create_attention_set, create_check
from patchwork.tests.utils import create_maintainer
from patchwork.tests.utils import create_patch
from patchwork.tests.utils import create_patch_comment
Expand Down Expand Up @@ -205,6 +205,10 @@ def test_utf8_handling(self):


class PatchViewTest(TestCase):
def setUp(self):
self.project = create_project()
self.maintainer = create_maintainer(self.project)

def test_redirect(self):
patch = create_patch()

Expand Down Expand Up @@ -380,6 +384,122 @@ def test_patch_with_checks(self):
),
)

def test_patch_with_attention_set(self):
user = create_user()
patch = create_patch(project=self.project)
create_attention_set(patch=patch, user=user)
create_attention_set(patch=patch, user=self.maintainer)

self.client.login(
username=self.maintainer.username,
password=self.maintainer.username,
)
requested_url = reverse(
'patch-detail',
kwargs={
'project_id': patch.project.linkname,
'msgid': patch.encoded_msgid,
},
)
response = self.client.get(requested_url)

# the response should contain attention set list
self.assertContains(response, '<h2>Users pending actions</h2>')

# and it should show the existing users in the list
self.assertEqual(
response.content.decode().count(
f'{self.maintainer.username} ({self.maintainer.email})'
),
1,
)
self.assertEqual(
response.content.decode().count(f'{user.username} ({user.email})'),
1,
)

# should display remove button for all
self.assertEqual(
response.content.decode().count('glyphicon-trash'),
2,
)

def test_patch_with_anonymous_user_with_attention_list(self):
# show not show a declare interest button nor remove buttons
user = create_user()
patch = create_patch(project=self.project)
create_attention_set(patch=patch, user=user)
create_attention_set(patch=patch, user=self.maintainer)

requested_url = reverse(
'patch-detail',
kwargs={
'project_id': patch.project.linkname,
'msgid': patch.encoded_msgid,
},
)
response = self.client.get(requested_url)

self.assertEqual(
response.content.decode().count('Declare interest'),
0,
)
self.assertEqual(
response.content.decode().count('glyphicon-trash'),
0,
)

def test_patch_with_user_not_in_attention_list(self):
# a declare interest button should be displayed
patch = create_patch(project=self.project)

self.client.login(
username=self.maintainer.username,
password=self.maintainer.username,
)
requested_url = reverse(
'patch-detail',
kwargs={
'project_id': patch.project.linkname,
'msgid': patch.encoded_msgid,
},
)
response = self.client.get(requested_url)

self.assertEqual(
response.content.decode().count('Declare interest'),
1,
)

def test_patch_with_user_in_attention_list(self):
# a remove button should be displayed if he is authenticated
# should not show option for other users
user = create_user()
patch = create_patch(project=self.project)
create_attention_set(patch=patch, user=user)
create_attention_set(patch=patch, user=self.maintainer)

self.client.login(
username=user.username,
password=user.username,
)
requested_url = reverse(
'patch-detail',
kwargs={
'project_id': patch.project.linkname,
'msgid': patch.encoded_msgid,
},
)
response = self.client.get(requested_url)
self.assertEqual(
response.content.decode().count(f'{user.username} ({user.email})'),
1,
)
self.assertEqual(
response.content.decode().count('glyphicon-trash'),
1,
)


class PatchUpdateTest(TestCase):
properties_form_id = 'patch-form-properties'
Expand Down