from django.core.urlresolvers import reverse
from django.test import TestCase
from django.utils.http import urlencode
+from django.utils import six
from django.utils.six.moves import range
from django.utils.six.moves import zip
'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):
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, six.b(''))
+
+ 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, six.b(''))
+
+
class BundleUpdateTest(BundleTestBase):
def test_no_action(self):
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
if settings.ENABLE_REST_API:
from rest_framework.authentication import BasicAuthentication # noqa
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
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()])