Commit d557242d authored by Stephen Finucane's avatar Stephen Finucane Committed by Damien Lespiau

py3: Remove all deprecated UnitTest calls

Remove the likes of 'failUnlessEqual' and 'assertEquals', which have
been deprecated and cause warnings in Django 1.6 with Python 3.4.

https://docs.python.org/2/library/unittest.html#deprecated-aliases

This allows us to remove an item from the TODO list.

v2: Port to fdo's patchwork (Damien)
Signed-off-by: default avatarStephen Finucane <stephen.finucane@intel.com>
Signed-off-by: default avatarDamien Lespiau <damien.lespiau@intel.com>
parent 521d387f
...@@ -14,5 +14,3 @@ ...@@ -14,5 +14,3 @@
* pwclient: add example scripts (eg, git post-commit hook) to online help * pwclient: add example scripts (eg, git post-commit hook) to online help
* pwclient: case-insensitive searches for author and project name * pwclient: case-insensitive searches for author and project name
* changing primary email addresses for accounts * changing primary email addresses for accounts
* sed -i -e "s/\(assertEqual\)s/\1/g" $(git grep -l assertEquals)
and all in: https://docs.python.org/2/library/unittest.html#deprecated-aliases
...@@ -42,8 +42,8 @@ class BundleListTest(TestCase): ...@@ -42,8 +42,8 @@ class BundleListTest(TestCase):
def testNoBundles(self): def testNoBundles(self):
response = self.client.get('/user/bundles/') response = self.client.get('/user/bundles/')
self.failUnlessEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.failUnlessEqual( self.assertEqual(
len(find_in_context(response.context, 'bundles')), 0) len(find_in_context(response.context, 'bundles')), 0)
def testSingleBundle(self): def testSingleBundle(self):
...@@ -51,8 +51,8 @@ class BundleListTest(TestCase): ...@@ -51,8 +51,8 @@ class BundleListTest(TestCase):
bundle = Bundle(owner = self.user, project = defaults.project) bundle = Bundle(owner = self.user, project = defaults.project)
bundle.save() bundle.save()
response = self.client.get('/user/bundles/') response = self.client.get('/user/bundles/')
self.failUnlessEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.failUnlessEqual( self.assertEqual(
len(find_in_context(response.context, 'bundles')), 1) len(find_in_context(response.context, 'bundles')), 1)
def tearDown(self): def tearDown(self):
...@@ -89,17 +89,17 @@ class BundleViewTest(BundleTestBase): ...@@ -89,17 +89,17 @@ class BundleViewTest(BundleTestBase):
def testEmptyBundle(self): def testEmptyBundle(self):
response = self.client.get(bundle_url(self.bundle)) response = self.client.get(bundle_url(self.bundle))
self.failUnlessEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
page = find_in_context(response.context, 'page') page = find_in_context(response.context, 'page')
self.failUnlessEqual(len(page.object_list), 0) self.assertEqual(len(page.object_list), 0)
def testNonEmptyBundle(self): def testNonEmptyBundle(self):
self.bundle.append_patch(self.patches[0]) self.bundle.append_patch(self.patches[0])
response = self.client.get(bundle_url(self.bundle)) response = self.client.get(bundle_url(self.bundle))
self.failUnlessEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
page = find_in_context(response.context, 'page') page = find_in_context(response.context, 'page')
self.failUnlessEqual(len(page.object_list), 1) self.assertEqual(len(page.object_list), 1)
def testBundleOrder(self): def testBundleOrder(self):
for patch in self.patches: for patch in self.patches:
...@@ -111,7 +111,7 @@ class BundleViewTest(BundleTestBase): ...@@ -111,7 +111,7 @@ class BundleViewTest(BundleTestBase):
for patch in self.patches: for patch in self.patches:
next_pos = response.content.decode().find(patch.name) next_pos = response.content.decode().find(patch.name)
# ensure that this patch is after the previous # ensure that this patch is after the previous
self.failUnless(next_pos > pos) self.assertTrue(next_pos > pos)
pos = next_pos pos = next_pos
# reorder and recheck # reorder and recheck
...@@ -128,7 +128,7 @@ class BundleViewTest(BundleTestBase): ...@@ -128,7 +128,7 @@ class BundleViewTest(BundleTestBase):
for patch in self.patches: for patch in self.patches:
next_pos = response.content.decode().find(patch.name) next_pos = response.content.decode().find(patch.name)
# ensure that this patch is now *before* the previous # ensure that this patch is now *before* the previous
self.failUnless(next_pos < pos) self.assertTrue(next_pos < pos)
pos = next_pos pos = next_pos
class BundleUpdateTest(BundleTestBase): class BundleUpdateTest(BundleTestBase):
...@@ -144,7 +144,7 @@ class BundleUpdateTest(BundleTestBase): ...@@ -144,7 +144,7 @@ class BundleUpdateTest(BundleTestBase):
form = response.context[formname] form = response.context[formname]
if not form: if not form:
return return
self.assertEquals(form.errors, {}) self.assertEqual(form.errors, {})
def publicString(self, public): def publicString(self, public):
if public: if public:
...@@ -308,8 +308,8 @@ class BundleCreateFromListTest(BundleTestBase): ...@@ -308,8 +308,8 @@ class BundleCreateFromListTest(BundleTestBase):
count = 1) count = 1)
bundle = Bundle.objects.get(name = newbundlename) bundle = Bundle.objects.get(name = newbundlename)
self.failUnlessEqual(bundle.patches.count(), 1) self.assertEqual(bundle.patches.count(), 1)
self.failUnlessEqual(bundle.patches.all()[0], patch) self.assertEqual(bundle.patches.all()[0], patch)
def testCreateNonEmptyBundleEmptyName(self): def testCreateNonEmptyBundleEmptyName(self):
newbundlename = 'testbundle-new' newbundlename = 'testbundle-new'
...@@ -331,7 +331,7 @@ class BundleCreateFromListTest(BundleTestBase): ...@@ -331,7 +331,7 @@ class BundleCreateFromListTest(BundleTestBase):
status_code = 200) status_code = 200)
# test that no new bundles are present # test that no new bundles are present
self.failUnlessEqual(n_bundles, Bundle.objects.count()) self.assertEqual(n_bundles, Bundle.objects.count())
def testCreateDuplicateName(self): def testCreateDuplicateName(self):
newbundlename = 'testbundle-dup' newbundlename = 'testbundle-dup'
...@@ -353,8 +353,8 @@ class BundleCreateFromListTest(BundleTestBase): ...@@ -353,8 +353,8 @@ class BundleCreateFromListTest(BundleTestBase):
count = 1) count = 1)
bundle = Bundle.objects.get(name = newbundlename) bundle = Bundle.objects.get(name = newbundlename)
self.failUnlessEqual(bundle.patches.count(), 1) self.assertEqual(bundle.patches.count(), 1)
self.failUnlessEqual(bundle.patches.all()[0], patch) self.assertEqual(bundle.patches.all()[0], patch)
response = self.client.post( response = self.client.post(
'/project/%s/list/' % defaults.project.linkname, '/project/%s/list/' % defaults.project.linkname,
...@@ -379,8 +379,8 @@ class BundleCreateFromPatchTest(BundleTestBase): ...@@ -379,8 +379,8 @@ class BundleCreateFromPatchTest(BundleTestBase):
'Bundle %s created' % newbundlename) 'Bundle %s created' % newbundlename)
bundle = Bundle.objects.get(name = newbundlename) bundle = Bundle.objects.get(name = newbundlename)
self.failUnlessEqual(bundle.patches.count(), 1) self.assertEqual(bundle.patches.count(), 1)
self.failUnlessEqual(bundle.patches.all()[0], patch) self.assertEqual(bundle.patches.all()[0], patch)
def testCreateWithExistingName(self): def testCreateWithExistingName(self):
newbundlename = self.bundle.name newbundlename = self.bundle.name
...@@ -395,7 +395,7 @@ class BundleCreateFromPatchTest(BundleTestBase): ...@@ -395,7 +395,7 @@ class BundleCreateFromPatchTest(BundleTestBase):
'A bundle called %s already exists' % newbundlename) 'A bundle called %s already exists' % newbundlename)
count = Bundle.objects.count() count = Bundle.objects.count()
self.failUnlessEqual(Bundle.objects.count(), 1) self.assertEqual(Bundle.objects.count(), 1)
class BundleAddFromListTest(BundleTestBase): class BundleAddFromListTest(BundleTestBase):
def testAddToEmptyBundle(self): def testAddToEmptyBundle(self):
...@@ -413,8 +413,8 @@ class BundleAddFromListTest(BundleTestBase): ...@@ -413,8 +413,8 @@ class BundleAddFromListTest(BundleTestBase):
self.assertContains(response, 'added to bundle %s' % self.bundle.name, self.assertContains(response, 'added to bundle %s' % self.bundle.name,
count = 1) count = 1)
self.failUnlessEqual(self.bundle.patches.count(), 1) self.assertEqual(self.bundle.patches.count(), 1)
self.failUnlessEqual(self.bundle.patches.all()[0], patch) self.assertEqual(self.bundle.patches.all()[0], patch)
def testAddToNonEmptyBundle(self): def testAddToNonEmptyBundle(self):
self.bundle.append_patch(self.patches[0]) self.bundle.append_patch(self.patches[0])
...@@ -432,15 +432,15 @@ class BundleAddFromListTest(BundleTestBase): ...@@ -432,15 +432,15 @@ class BundleAddFromListTest(BundleTestBase):
self.assertContains(response, 'added to bundle %s' % self.bundle.name, self.assertContains(response, 'added to bundle %s' % self.bundle.name,
count = 1) count = 1)
self.failUnlessEqual(self.bundle.patches.count(), 2) self.assertEqual(self.bundle.patches.count(), 2)
self.failUnless(self.patches[0] in self.bundle.patches.all()) self.assertIn(self.patches[0], self.bundle.patches.all())
self.failUnless(self.patches[1] in self.bundle.patches.all()) self.assertIn(self.patches[1], self.bundle.patches.all())
# check order # check order
bps = [ BundlePatch.objects.get(bundle = self.bundle, bps = [ BundlePatch.objects.get(bundle = self.bundle,
patch = self.patches[i]) \ patch = self.patches[i]) \
for i in [0, 1] ] for i in [0, 1] ]
self.failUnless(bps[0].order < bps[1].order) self.assertTrue(bps[0].order < bps[1].order)
def testAddDuplicate(self): def testAddDuplicate(self):
self.bundle.append_patch(self.patches[0]) self.bundle.append_patch(self.patches[0])
...@@ -460,7 +460,7 @@ class BundleAddFromListTest(BundleTestBase): ...@@ -460,7 +460,7 @@ class BundleAddFromListTest(BundleTestBase):
self.assertContains(response, 'Patch &#39;%s&#39; already in bundle' \ self.assertContains(response, 'Patch &#39;%s&#39; already in bundle' \
% patch.name, count = 1, status_code = 200) % patch.name, count = 1, status_code = 200)
self.assertEquals(count, self.bundle.patches.count()) self.assertEqual(count, self.bundle.patches.count())
def testAddNewAndDuplicate(self): def testAddNewAndDuplicate(self):
self.bundle.append_patch(self.patches[0]) self.bundle.append_patch(self.patches[0])
...@@ -483,7 +483,7 @@ class BundleAddFromListTest(BundleTestBase): ...@@ -483,7 +483,7 @@ class BundleAddFromListTest(BundleTestBase):
self.assertContains(response, 'Patch &#39;%s&#39; added to bundle' \ self.assertContains(response, 'Patch &#39;%s&#39; added to bundle' \
% self.patches[1].name, count = 1, % self.patches[1].name, count = 1,
status_code = 200) status_code = 200)
self.assertEquals(count + 1, self.bundle.patches.count()) self.assertEqual(count + 1, self.bundle.patches.count())
class BundleAddFromPatchTest(BundleTestBase): class BundleAddFromPatchTest(BundleTestBase):
def testAddToEmptyBundle(self): def testAddToEmptyBundle(self):
...@@ -497,8 +497,8 @@ class BundleAddFromPatchTest(BundleTestBase): ...@@ -497,8 +497,8 @@ class BundleAddFromPatchTest(BundleTestBase):
'added to bundle &quot;%s&quot;' % self.bundle.name, 'added to bundle &quot;%s&quot;' % self.bundle.name,
count = 1) count = 1)
self.failUnlessEqual(self.bundle.patches.count(), 1) self.assertEqual(self.bundle.patches.count(), 1)
self.failUnlessEqual(self.bundle.patches.all()[0], patch) self.assertEqual(self.bundle.patches.all()[0], patch)
def testAddToNonEmptyBundle(self): def testAddToNonEmptyBundle(self):
self.bundle.append_patch(self.patches[0]) self.bundle.append_patch(self.patches[0])
...@@ -512,15 +512,15 @@ class BundleAddFromPatchTest(BundleTestBase): ...@@ -512,15 +512,15 @@ class BundleAddFromPatchTest(BundleTestBase):
'added to bundle &quot;%s&quot;' % self.bundle.name, 'added to bundle &quot;%s&quot;' % self.bundle.name,
count = 1) count = 1)
self.failUnlessEqual(self.bundle.patches.count(), 2) self.assertEqual(self.bundle.patches.count(), 2)
self.failUnless(self.patches[0] in self.bundle.patches.all()) self.assertIn(self.patches[0], self.bundle.patches.all())
self.failUnless(self.patches[1] in self.bundle.patches.all()) self.assertIn(self.patches[1], self.bundle.patches.all())
# check order # check order
bps = [ BundlePatch.objects.get(bundle = self.bundle, bps = [ BundlePatch.objects.get(bundle = self.bundle,
patch = self.patches[i]) \ patch = self.patches[i]) \
for i in [0, 1] ] for i in [0, 1] ]
self.failUnless(bps[0].order < bps[1].order) self.assertTrue(bps[0].order < bps[1].order)
class BundleInitialOrderTest(BundleTestBase): class BundleInitialOrderTest(BundleTestBase):
"""When creating bundles from a patch list, ensure that the patches in the """When creating bundles from a patch list, ensure that the patches in the
...@@ -601,19 +601,19 @@ class BundleReorderTest(BundleTestBase): ...@@ -601,19 +601,19 @@ class BundleReorderTest(BundleTestBase):
response = self.client.post(bundle_url(self.bundle), params) response = self.client.post(bundle_url(self.bundle), params)
self.failUnlessEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
bps = BundlePatch.objects.filter(bundle = self.bundle) \ bps = BundlePatch.objects.filter(bundle = self.bundle) \
.order_by('order') .order_by('order')
# check if patch IDs are in the expected order: # check if patch IDs are in the expected order:
bundle_ids = [ bp.patch.id for bp in bps ] bundle_ids = [ bp.patch.id for bp in bps ]
self.failUnlessEqual(neworder_ids, bundle_ids) self.assertEqual(neworder_ids, bundle_ids)
# check if order field is still sequential: # check if order field is still sequential:
order_numbers = [ bp.order for bp in bps ] order_numbers = [ bp.order for bp in bps ]
expected_order = list(range(1, len(neworder)+1)) # [1 ... len(neworder)] expected_order = list(range(1, len(neworder)+1)) # [1 ... len(neworder)]
self.failUnlessEqual(order_numbers, expected_order) self.assertEqual(order_numbers, expected_order)
def testBundleReorderAll(self): def testBundleReorderAll(self):
# reorder all patches: # reorder all patches:
......
...@@ -52,7 +52,7 @@ class InvalidConfirmationTest(TestCase): ...@@ -52,7 +52,7 @@ class InvalidConfirmationTest(TestCase):
self.conf.active = False self.conf.active = False
self.conf.save() self.conf.save()
response = self.client.get(_confirmation_url(self.conf)) response = self.client.get(_confirmation_url(self.conf))
self.assertEquals(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/confirm-error.html') self.assertTemplateUsed(response, 'patchwork/confirm-error.html')
self.assertEqual(response.context['error'], 'inactive') self.assertEqual(response.context['error'], 'inactive')
self.assertEqual(response.context['conf'], self.conf) self.assertEqual(response.context['conf'], self.conf)
...@@ -61,7 +61,7 @@ class InvalidConfirmationTest(TestCase): ...@@ -61,7 +61,7 @@ class InvalidConfirmationTest(TestCase):
self.conf.date -= self.conf.validity self.conf.date -= self.conf.validity
self.conf.save() self.conf.save()
response = self.client.get(_confirmation_url(self.conf)) response = self.client.get(_confirmation_url(self.conf))
self.assertEquals(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/confirm-error.html') self.assertTemplateUsed(response, 'patchwork/confirm-error.html')
self.assertEqual(response.context['error'], 'expired') self.assertEqual(response.context['error'], 'expired')
self.assertEqual(response.context['conf'], self.conf) self.assertEqual(response.context['conf'], self.conf)
......
...@@ -51,14 +51,14 @@ class UTF8PatchViewTest(TestCase): ...@@ -51,14 +51,14 @@ class UTF8PatchViewTest(TestCase):
def testMboxView(self): def testMboxView(self):
response = self.client.get('/patch/%d/mbox/' % self.patch.id) response = self.client.get('/patch/%d/mbox/' % self.patch.id)
self.assertEquals(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTrue(self.patch.content in \ self.assertTrue(self.patch.content in \
response.content.decode(self.patch_encoding)) response.content.decode(self.patch_encoding))
def testRawView(self): def testRawView(self):
response = self.client.get('/patch/%d/raw/' % self.patch.id) response = self.client.get('/patch/%d/raw/' % self.patch.id)
self.assertEquals(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEquals(response.content.decode(self.patch_encoding), self.assertEqual(response.content.decode(self.patch_encoding),
self.patch.content) self.patch.content)
def tearDown(self): def tearDown(self):
......
...@@ -34,7 +34,7 @@ class FilterQueryStringTest(TestCase): ...@@ -34,7 +34,7 @@ class FilterQueryStringTest(TestCase):
defaults.project.save() defaults.project.save()
url = '/project/%s/list/?submitter=a%%26b=c' % project.linkname url = '/project/%s/list/?submitter=a%%26b=c' % project.linkname
response = self.client.get(url) response = self.client.get(url)
self.failUnlessEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertNotContains(response, 'submitter=a&amp;b=c') self.assertNotContains(response, 'submitter=a&amp;b=c')
self.assertNotContains(response, 'submitter=a&b=c') self.assertNotContains(response, 'submitter=a&b=c')
...@@ -45,4 +45,4 @@ class FilterQueryStringTest(TestCase): ...@@ -45,4 +45,4 @@ class FilterQueryStringTest(TestCase):
defaults.project.save() defaults.project.save()
url = '/project/%s/list/?submitter=%%E2%%98%%83' % project.linkname url = '/project/%s/list/?submitter=%%E2%%98%%83' % project.linkname
response = self.client.get(url) response = self.client.get(url)
self.failUnlessEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
...@@ -34,35 +34,35 @@ class MailSettingsTest(TestCase): ...@@ -34,35 +34,35 @@ class MailSettingsTest(TestCase):
def testMailSettingsGET(self): def testMailSettingsGET(self):
response = self.client.get(self.url) response = self.client.get(self.url)
self.assertEquals(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTrue(response.context['form']) self.assertTrue(response.context['form'])
def testMailSettingsPOST(self): def testMailSettingsPOST(self):
email = u'foo@example.com' email = u'foo@example.com'
response = self.client.post(self.url, {'email': email}) response = self.client.post(self.url, {'email': email})
self.assertEquals(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/mail-settings.html') self.assertTemplateUsed(response, 'patchwork/mail-settings.html')
self.assertEquals(response.context['email'], email) self.assertEqual(response.context['email'], email)
def testMailSettingsPOSTEmpty(self): def testMailSettingsPOSTEmpty(self):
response = self.client.post(self.url, {'email': ''}) response = self.client.post(self.url, {'email': ''})
self.assertEquals(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/mail-form.html') self.assertTemplateUsed(response, 'patchwork/mail-form.html')
self.assertFormError(response, 'form', 'email', self.assertFormError(response, 'form', 'email',
'This field is required.') 'This field is required.')
def testMailSettingsPOSTInvalid(self): def testMailSettingsPOSTInvalid(self):
response = self.client.post(self.url, {'email': 'foo'}) response = self.client.post(self.url, {'email': 'foo'})
self.assertEquals(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/mail-form.html') self.assertTemplateUsed(response, 'patchwork/mail-form.html')
self.assertFormError(response, 'form', 'email', error_strings['email']) self.assertFormError(response, 'form', 'email', error_strings['email'])
def testMailSettingsPOSTOptedIn(self): def testMailSettingsPOSTOptedIn(self):
email = u'foo@example.com' email = u'foo@example.com'
response = self.client.post(self.url, {'email': email}) response = self.client.post(self.url, {'email': email})
self.assertEquals(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/mail-settings.html') self.assertTemplateUsed(response, 'patchwork/mail-settings.html')
self.assertEquals(response.context['is_optout'], False) self.assertEqual(response.context['is_optout'], False)
self.assertContains(response, '<strong>may</strong>') self.assertContains(response, '<strong>may</strong>')
optout_url = reverse('patchwork.views.mail.optout') optout_url = reverse('patchwork.views.mail.optout')
self.assertContains(response, ('action="%s"' % optout_url)) self.assertContains(response, ('action="%s"' % optout_url))
...@@ -71,9 +71,9 @@ class MailSettingsTest(TestCase): ...@@ -71,9 +71,9 @@ class MailSettingsTest(TestCase):
email = u'foo@example.com' email = u'foo@example.com'
EmailOptout(email = email).save() EmailOptout(email = email).save()
response = self.client.post(self.url, {'email': email}) response = self.client.post(self.url, {'email': email})
self.assertEquals(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/mail-settings.html') self.assertTemplateUsed(response, 'patchwork/mail-settings.html')
self.assertEquals(response.context['is_optout'], True) self.assertEqual(response.context['is_optout'], True)
self.assertContains(response, '<strong>may not</strong>') self.assertContains(response, '<strong>may not</strong>')
optin_url = reverse('patchwork.views.mail.optin') optin_url = reverse('patchwork.views.mail.optin')
self.assertContains(response, ('action="%s"' % optin_url)) self.assertContains(response, ('action="%s"' % optin_url))
...@@ -92,38 +92,38 @@ class OptoutRequestTest(TestCase): ...@@ -92,38 +92,38 @@ class OptoutRequestTest(TestCase):
response = self.client.post(self.url, {'email': email}) response = self.client.post(self.url, {'email': email})
# check for a confirmation object # check for a confirmation object
self.assertEquals(EmailConfirmation.objects.count(), 1) self.assertEqual(EmailConfirmation.objects.count(), 1)
conf = EmailConfirmation.objects.get(email = email) conf = EmailConfirmation.objects.get(email = email)
# check confirmation page # check confirmation page
self.assertEquals(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEquals(response.context['confirmation'], conf) self.assertEqual(response.context['confirmation'], conf)
self.assertContains(response, email) self.assertContains(response, email)
# check email # check email
url = reverse('patchwork.views.confirm', kwargs = {'key': conf.key}) url = reverse('patchwork.views.confirm', kwargs = {'key': conf.key})
self.assertEquals(len(mail.outbox), 1) self.assertEqual(len(mail.outbox), 1)
msg = mail.outbox[0] msg = mail.outbox[0]
self.assertEquals(msg.to, [email]) self.assertEqual(msg.to, [email])
self.assertEquals(msg.subject, 'Patchwork opt-out confirmation') self.assertEqual(msg.subject, 'Patchwork opt-out confirmation')
self.assertTrue(url in msg.body) self.assertIn(url, msg.body)
def testOptoutRequestInvalidPOSTEmpty(self): def testOptoutRequestInvalidPOSTEmpty(self):
response = self.client.post(self.url, {'email': ''}) response = self.client.post(self.url, {'email': ''})
self.assertEquals(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertFormError(response, 'form', 'email', self.assertFormError(response, 'form', 'email',
'This field is required.') 'This field is required.')
self.assertTrue(response.context['error']) self.assertTrue(response.context['error'])
self.assertTrue('email_sent' not in response.context) self.assertNotIn('email_sent', response.context)
self.assertEquals(len(mail.outbox), 0) self.assertEqual(len(mail.outbox), 0)
def testOptoutRequestInvalidPOSTNonEmail(self): def testOptoutRequestInvalidPOSTNonEmail(self):
response = self.client.post(self.url, {'email': 'foo'}) response = self.client.post(self.url, {'email': 'foo'})
self.assertEquals(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertFormError(response, 'form', 'email', error_strings['email']) self.assertFormError(response, 'form', 'email', error_strings['email'])
self.assertTrue(response.context['error']) self.assertTrue(response.context['error'])
self.assertTrue('email_sent' not in response.context) self.assertNotIn('email_sent', response.context)
self.assertEquals(len(mail.outbox), 0) self.assertEqual(len(mail.outbox), 0)
class OptoutTest(TestCase): class OptoutTest(TestCase):
...@@ -138,13 +138,13 @@ class OptoutTest(TestCase): ...@@ -138,13 +138,13 @@ class OptoutTest(TestCase):
kwargs = {'key': self.conf.key}) kwargs = {'key': self.conf.key})
response = self.client.get(url) response = self.client.get(url)
self.assertEquals(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/optout.html') self.assertTemplateUsed(response, 'patchwork/optout.html')
self.assertContains(response, self.email) self.assertContains(response, self.email)
# check that we've got an optout in the list # check that we've got an optout in the list
self.assertEquals(EmailOptout.objects.count(), 1) self.assertEqual(EmailOptout.objects.count(), 1)
self.assertEquals(EmailOptout.objects.all()[0].email, self.email) self.assertEqual(EmailOptout.objects.all()[0].email, self.email)
# check that the confirmation is now inactive # check that the confirmation is now inactive
self.assertFalse(EmailConfirmation.objects.get( self.assertFalse(EmailConfirmation.objects.get(
...@@ -172,38 +172,38 @@ class OptinRequestTest(TestCase): ...@@ -172,38 +172,38 @@ class OptinRequestTest(TestCase):
response = self.client.post(self.url, {'email': self.email}) response = self.client.post(self.url, {'email': self.email})
# check for a confirmation object # check for a confirmation object
self.assertEquals(EmailConfirmation.objects.count(), 1) self.assertEqual(EmailConfirmation.objects.count(), 1)
conf = EmailConfirmation.objects.get(email = self.email) conf = EmailConfirmation.objects.get(email = self.email)
# check confirmation page # check confirmation page
self.assertEquals(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEquals(response.context['confirmation'], conf) self.assertEqual(response.context['confirmation'], conf)