Skip to content

Commit

Permalink
views: Add support for boolean 'series' parameters
Browse files Browse the repository at this point in the history
Previously, we allowed users to download patch mboxes with dependencies
included using a 'series' parameter. This accepted either a numeric ID,
corresponding to the ID of the patch series that dependencies should be
included from, or a wildcard value ('*').

    /patch/{patchID}/mbox/?series=123
    /patch/{patchID}/mbox/?series=*

With switch to a 1:N series-patch relationship, this is clearly
unnecessary now but must be retained to avoid breaking users. However,
that doesn't mean we can't things a little clearer. Add support for
boolean parameters, which make more sense for this kind of relationship:

  /patch/{patchID}/mbox/?series=true
  /patch/{patchID}/mbox/?series=1
  /patch/{patchID}/mbox/?series=false
  /patch/{patchID}/mbox/?series=0

Signed-off-by: Stephen Finucane <stephen@that.guru>
  • Loading branch information
stephenfin authored and veruu committed Sep 13, 2018
1 parent e32173b commit f0f8024
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions patchwork/tests/test_mboxviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,23 @@ def test_patch_with_numeric_series(self):
self.assertContains(response, patch_a.content)
self.assertContains(response, patch_b.content)

def test_patch_with_boolean_series(self):
_, patch_a, patch_b = self._create_patches()

for value in ('true', '1'):
response = self.client.get('%s?series=%s' % (
reverse('patch-mbox', args=[patch_b.id]), value))

self.assertContains(response, patch_a.content)
self.assertContains(response, patch_b.content)

for value in ('false', '0'):
response = self.client.get('%s?series=%s' % (
reverse('patch-mbox', args=[patch_b.id]), value))

self.assertNotContains(response, patch_a.content)
self.assertContains(response, patch_b.content)

def test_patch_with_invalid_series(self):
series, patch_a, patch_b = self._create_patches()

Expand Down
2 changes: 1 addition & 1 deletion patchwork/views/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def patch_mbox(request, patch_id):
series_id = request.GET.get('series')

response = HttpResponse(content_type='text/plain')
if series_id:
if series_id and series_id.lower() not in ('false', '0'):
if not patch.series:
raise Http404('Patch does not have an associated series. This is '
'because the patch was processed with an older '
Expand Down
2 changes: 1 addition & 1 deletion patchwork/views/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def series_patch_to_mbox(patch, series_id):
Returns:
A string for the mbox file.
"""
if series_id != '*':
if series_id.lower() not in ('*', 'true', '1'):
try:
series_id = int(series_id)
except ValueError:
Expand Down

0 comments on commit f0f8024

Please sign in to comment.