Skip to content

Commit b170a82

Browse files
committed
models: Use parent model to get comment's 'list_archive_url'
We were attempting to retrieve the 'list_archive_url' attribute from the 'PatchComment' or 'CoverComment' instances, rather than the parent 'Patch' and 'Cover' object, respectively. Correct this and add plenty of tests to prevent this regressing. Conflicts: patchwork/models.py Changes: patchwork/tests/api/test_comment.py NOTE(stephenfin): Conflicts and changes are necessary to deal with the fact we have a single comment model instead of two comment models as in stable/3.0. Signed-off-by: Stephen Finucane <[email protected]> Fixes: 02ffb13 ("models: Add list archive lookup") Closes: #391 (cherry picked from commit 93ff4db) (cherry picked from commit 6c73a55)
1 parent 5c03cbe commit b170a82

File tree

5 files changed

+82
-4
lines changed

5 files changed

+82
-4
lines changed

patchwork/models.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,13 @@ class Submission(FilenameMixin, EmailMixin, models.Model):
380380
def list_archive_url(self):
381381
if not self.project.list_archive_url_format:
382382
return None
383+
383384
if not self.msgid:
384385
return None
386+
385387
return self.project.list_archive_url_format.format(
386-
self.url_msgid)
388+
self.url_msgid,
389+
)
387390

388391
# patchwork metadata
389392

@@ -640,10 +643,13 @@ class Comment(EmailMixin, models.Model):
640643
def list_archive_url(self):
641644
if not self.submission.project.list_archive_url_format:
642645
return None
646+
643647
if not self.msgid:
644648
return None
645-
return self.project.list_archive_url_format.format(
646-
self.url_msgid)
649+
650+
return self.submission.project.list_archive_url_format.format(
651+
self.url_msgid,
652+
)
647653

648654
def get_absolute_url(self):
649655
return reverse('comment-redirect', kwargs={'comment_id': self.id})

patchwork/tests/api/test_comment.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ def test_list(self):
5353
self.assertEqual(status.HTTP_200_OK, resp.status_code)
5454
self.assertEqual(1, len(resp.data))
5555
self.assertSerialized(comment, resp.data[0])
56+
self.assertIn('list_archive_url', resp.data[0])
57+
58+
def test_list_version_1_1(self):
59+
"""List cover letter comments using API v1.1."""
60+
cover = create_cover()
61+
comment = create_comment(submission=cover)
62+
63+
resp = self.client.get(self.api_url(cover, version='1.1'))
64+
self.assertEqual(status.HTTP_200_OK, resp.status_code)
65+
self.assertEqual(1, len(resp.data))
66+
self.assertSerialized(comment, resp.data[0])
67+
self.assertNotIn('list_archive_url', resp.data[0])
5668

5769
def test_list_version_1_0(self):
5870
"""List cover letter comments using API v1.0."""
@@ -104,6 +116,18 @@ def test_list(self):
104116
self.assertEqual(status.HTTP_200_OK, resp.status_code)
105117
self.assertEqual(1, len(resp.data))
106118
self.assertSerialized(comment, resp.data[0])
119+
self.assertIn('list_archive_url', resp.data[0])
120+
121+
def test_list_version_1_1(self):
122+
"""List patch comments using API v1.1."""
123+
patch = create_patch()
124+
comment = create_comment(submission=patch)
125+
126+
resp = self.client.get(self.api_url(patch, version='1.1'))
127+
self.assertEqual(status.HTTP_200_OK, resp.status_code)
128+
self.assertEqual(1, len(resp.data))
129+
self.assertSerialized(comment, resp.data[0])
130+
self.assertNotIn('list_archive_url', resp.data[0])
107131

108132
def test_list_version_1_0(self):
109133
"""List patch comments using API v1.0."""

patchwork/tests/api/test_project.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ def test_list_authenticated(self):
7171
self.assertEqual(status.HTTP_200_OK, resp.status_code)
7272
self.assertEqual(1, len(resp.data))
7373
self.assertSerialized(project, resp.data[0])
74+
self.assertIn('subject_match', resp.data[0])
75+
self.assertIn('list_archive_url', resp.data[0])
76+
self.assertIn('list_archive_url_format', resp.data[0])
77+
self.assertIn('commit_url_format', resp.data[0])
78+
79+
@utils.store_samples('project-list-1.1')
80+
def test_list_version_1_1(self):
81+
"""List projects using API v1.1.
82+
83+
Validate that newer fields are dropped for older API versions.
84+
"""
85+
create_project()
86+
87+
resp = self.client.get(self.api_url(version='1.1'))
88+
self.assertEqual(status.HTTP_200_OK, resp.status_code)
89+
self.assertEqual(1, len(resp.data))
90+
self.assertIn('subject_match', resp.data[0])
91+
self.assertNotIn('list_archive_url', resp.data[0])
92+
self.assertNotIn('list_archive_url_format', resp.data[0])
93+
self.assertNotIn('commit_url_format', resp.data[0])
7494

7595
@utils.store_samples('project-list-1.0')
7696
def test_list_version_1_0(self):
@@ -86,7 +106,7 @@ def test_list_version_1_0(self):
86106
self.assertNotIn('subject_match', resp.data[0])
87107

88108
@utils.store_samples('project-detail')
89-
def test_detail_by_id(self):
109+
def test_detail(self):
90110
"""Show project using ID lookup.
91111
92112
Validate that it's possible to filter by pk.
@@ -96,6 +116,10 @@ def test_detail_by_id(self):
96116
resp = self.client.get(self.api_url(project.pk))
97117
self.assertEqual(status.HTTP_200_OK, resp.status_code)
98118
self.assertSerialized(project, resp.data)
119+
self.assertIn('subject_match', resp.data)
120+
self.assertIn('list_archive_url', resp.data)
121+
self.assertIn('list_archive_url_format', resp.data)
122+
self.assertIn('commit_url_format', resp.data)
99123

100124
def test_detail_by_linkname(self):
101125
"""Show project using linkname lookup.
@@ -119,6 +143,22 @@ def test_detail_by_numeric_linkname(self):
119143
self.assertEqual(status.HTTP_200_OK, resp.status_code)
120144
self.assertSerialized(project, resp.data)
121145

146+
@utils.store_samples('project-detail-1.1')
147+
def test_detail_version_1_1(self):
148+
"""Show project using API v1.1.
149+
150+
Validate that newer fields are dropped for older API versions.
151+
"""
152+
project = create_project()
153+
154+
resp = self.client.get(self.api_url(project.pk, version='1.1'))
155+
self.assertEqual(status.HTTP_200_OK, resp.status_code)
156+
self.assertIn('name', resp.data)
157+
self.assertIn('subject_match', resp.data)
158+
self.assertNotIn('list_archive_url', resp.data)
159+
self.assertNotIn('list_archive_url_format', resp.data)
160+
self.assertNotIn('commit_url_format', resp.data)
161+
122162
@utils.store_samples('project-detail-1.0')
123163
def test_detail_version_1_0(self):
124164
"""Show project using API v1.0.

patchwork/tests/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def create_project(**kwargs):
6060
'listid': 'test%d.example.com' % num,
6161
'listemail': 'test%[email protected]' % num,
6262
'subject_match': '',
63+
'list_archive_url': 'https://lists.example.com/',
64+
'list_archive_url_format': 'https://lists.example.com/mail/{}',
6365
}
6466
values.update(kwargs)
6567

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
api:
3+
- |
4+
The ``list_archive_url`` field will now be correctly shown for patch
5+
comments and cover letter comments.
6+
(`#391 <https://github.com/getpatchwork/patchwork/issues/391>`__)

0 commit comments

Comments
 (0)