self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/mail-settings.html')
self.assertEquals(response.context['is_optout'], False)
- self.assertTrue('<strong>may</strong>' in response.content)
+ self.assertContains(response, '<strong>may</strong>')
optout_url = reverse('patchwork.views.mail.optout')
- self.assertTrue(('action="%s"' % optout_url) in response.content)
+ self.assertContains(response, ('action="%s"' % optout_url))
def testMailSettingsPOSTOptedOut(self):
email = u'foo@example.com'
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/mail-settings.html')
self.assertEquals(response.context['is_optout'], True)
- self.assertTrue('<strong>may not</strong>' in response.content)
+ self.assertContains(response, '<strong>may not</strong>')
optin_url = reverse('patchwork.views.mail.optin')
- self.assertTrue(('action="%s"' % optin_url) in response.content)
+ self.assertContains(response, ('action="%s"' % optin_url))
class OptoutRequestTest(TestCase):
# check confirmation page
self.assertEquals(response.status_code, 200)
self.assertEquals(response.context['confirmation'], conf)
- self.assertTrue(email in response.content)
+ self.assertContains(response, email)
# check email
url = reverse('patchwork.views.confirm', kwargs = {'key': conf.key})
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/optout.html')
- self.assertTrue(self.email in response.content)
+ self.assertContains(response, self.email)
# check that we've got an optout in the list
self.assertEquals(EmailOptout.objects.count(), 1)
# check confirmation page
self.assertEquals(response.status_code, 200)
self.assertEquals(response.context['confirmation'], conf)
- self.assertTrue(self.email in response.content)
+ self.assertContains(response, self.email)
# check email
url = reverse('patchwork.views.confirm', kwargs = {'key': conf.key})
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/optin.html')
- self.assertTrue(self.email in response.content)
+ self.assertContains(response, self.email)
# check that there's no optout remaining
self.assertEquals(EmailOptout.objects.count(), 0)
# check for an error message
self.assertEquals(response.status_code, 200)
self.assertTrue(bool(response.context['error']))
- self.assertTrue('not on the patchwork opt-out list' in response.content)
+ self.assertContains(response, 'not on the patchwork opt-out list')
class UserProfileOptoutFormTest(TestCase):
"""Test that the correct optin/optout forms appear on the user profile
form_re = self._form_re(self.optout_url, self.user.email)
response = self.client.get(self.url)
self.assertEquals(response.status_code, 200)
- self.assertTrue(form_re.search(response.content) is not None)
+ self.assertTrue(form_re.search(response.content.decode()) is not None)
def testMainEmailOptinForm(self):
EmailOptout(email = self.user.email).save()
form_re = self._form_re(self.optin_url, self.user.email)
response = self.client.get(self.url)
self.assertEquals(response.status_code, 200)
- self.assertTrue(form_re.search(response.content) is not None)
+ self.assertTrue(form_re.search(response.content.decode()) is not None)
def testSecondaryEmailOptoutForm(self):
p = Person(email = self.secondary_email, user = self.user)
p.save()
-
form_re = self._form_re(self.optout_url, p.email)
response = self.client.get(self.url)
self.assertEquals(response.status_code, 200)
- self.assertTrue(form_re.search(response.content) is not None)
+ self.assertTrue(form_re.search(response.content.decode()) is not None)
def testSecondaryEmailOptinForm(self):
p = Person(email = self.secondary_email, user = self.user)
form_re = self._form_re(self.optin_url, p.email)
response = self.client.get(self.url)
self.assertEquals(response.status_code, 200)
- self.assertTrue(form_re.search(response.content) is not None)
+ self.assertTrue(form_re.search(response.content.decode()) is not None)
def testNameComplete(self):
response = self.client.get('/submitter/', {'q': 'name'})
self.assertEquals(response.status_code, 200)
- data = json.loads(response.content)
+ data = json.loads(response.content.decode())
self.assertEquals(len(data), 1)
self.assertEquals(data[0]['name'], 'Test Name')
def testEmailComplete(self):
response = self.client.get('/submitter/', {'q': 'test2'})
self.assertEquals(response.status_code, 200)
- data = json.loads(response.content)
+ data = json.loads(response.content.decode())
self.assertEquals(len(data), 1)
self.assertEquals(data[0]['email'], 'test2@example.com')
person.save()
response = self.client.get('/submitter/', {'q': 'test', 'l': 5})
self.assertEquals(response.status_code, 200)
- data = json.loads(response.content)
+ data = json.loads(response.content.decode())
self.assertEquals(len(data), 5)
from django.http import HttpResponse, HttpResponseForbidden
from django.shortcuts import render_to_response, get_object_or_404
+from django.utils import six
from patchwork.forms import PatchForm, CreateBundleForm
from patchwork.models import Patch, Project, Bundle
def mbox(request, patch_id):
patch = get_object_or_404(Patch, id=patch_id)
response = HttpResponse(content_type="text/plain")
- response.write(patch_to_mbox(patch).as_string(True))
+ # NOTE(stephenfin) http://stackoverflow.com/a/28584090/613428
+ if six.PY3:
+ response.write(patch_to_mbox(patch).as_bytes(True).decode())
+ else:
+ response.write(patch_to_mbox(patch).as_string(True))
response['Content-Disposition'] = 'attachment; filename=' + \
patch.filename().replace(';', '').replace('\n', '')
return response