[PATCH v2 5/9] utils: Add 'bundle_to_mbox' helper
Daniel Axtens
dja at axtens.net
Fri Feb 24 14:13:42 AEDT 2017
Stephen Finucane <stephen at that.guru> writes:
> This includes unit tests to validate correct behavior and prevent
> regressions.
>
> Signed-off-by: Stephen Finucane <stephen at that.guru>
> ---
> v2:
> - Move code to views/utils instead
> - Break out other refactoring work
Thanks!
Reviewed-by: Daniel Axtens <dja at axtens.net>
Regards,
Daniel
> ---
> patchwork/tests/test_bundles.py | 20 ++++++++++++++++++++
> patchwork/views/bundle.py | 5 ++---
> patchwork/views/utils.py | 12 ++++++++++++
> 3 files changed, 34 insertions(+), 3 deletions(-)
>
> diff --git a/patchwork/tests/test_bundles.py b/patchwork/tests/test_bundles.py
> index c185110..2e34174 100644
> --- a/patchwork/tests/test_bundles.py
> +++ b/patchwork/tests/test_bundles.py
> @@ -42,6 +42,11 @@ def bundle_url(bundle):
> 'username': bundle.owner.username, 'bundlename': bundle.name})
>
>
> +def bundle_mbox_url(bundle):
> + return reverse('bundle-mbox', kwargs={
> + 'username': bundle.owner.username, 'bundlename': bundle.name})
> +
> +
> class BundleListTest(TestCase):
>
> def setUp(self):
> @@ -120,6 +125,21 @@ class BundleViewTest(BundleTestBase):
> pos = next_pos
>
>
> +class BundleMboxTest(BundleTestBase):
> +
> + def test_empty_bundle(self):
> + response = self.client.get(bundle_mbox_url(self.bundle))
> + self.assertEqual(response.status_code, 200)
> + self.assertEqual(response.content, '')
> +
> + def test_non_empty_bundle(self):
> + self.bundle.append_patch(self.patches[0])
> +
> + response = self.client.get(bundle_mbox_url(self.bundle))
> + self.assertEqual(response.status_code, 200)
> + self.assertNotEqual(response.content, '')
> +
> +
> class BundleUpdateTest(BundleTestBase):
>
> def test_no_action(self):
> diff --git a/patchwork/views/bundle.py b/patchwork/views/bundle.py
> index 53e1b21..ef82c98 100644
> --- a/patchwork/views/bundle.py
> +++ b/patchwork/views/bundle.py
> @@ -32,7 +32,7 @@ from patchwork.models import Bundle
> from patchwork.models import BundlePatch
> from patchwork.models import Project
> from patchwork.views import generic_list
> -from patchwork.views.utils import patch_to_mbox
> +from patchwork.views.utils import bundle_to_mbox
>
>
> @login_required
> @@ -140,8 +140,7 @@ def bundle_mbox(request, username, bundlename):
> response = HttpResponse(content_type='text/plain')
> response['Content-Disposition'] = \
> 'attachment; filename=bundle-%d-%s.mbox' % (bundle.id, bundle.name)
> - response.write('\n'.join(
> - [patch_to_mbox(p) for p in bundle.ordered_patches()]))
> + response.write(bundle_to_mbox(bundle))
>
> return response
>
> diff --git a/patchwork/views/utils.py b/patchwork/views/utils.py
> index c998647..900480b 100644
> --- a/patchwork/views/utils.py
> +++ b/patchwork/views/utils.py
> @@ -104,3 +104,15 @@ def patch_to_mbox(patch):
> mail = mail.as_string(True)
>
> return mail
> +
> +
> +def bundle_to_mbox(bundle):
> + """Get an mbox representation of a bundle.
> +
> + Arguments:
> + patch: The Bundle object to convert.
> +
> + Returns:
> + A string for the mbox file.
> + """
> + return '\n'.join([patch_to_mbox(p) for p in bundle.ordered_patches()])
> --
> 2.9.3
>
> _______________________________________________
> Patchwork mailing list
> Patchwork at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork
More information about the Patchwork
mailing list