From patchwork Mon Jun 29 13:46:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 489584 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CAB311402C4 for ; Tue, 30 Jun 2015 18:51:59 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id B0D551A1F2C for ; Tue, 30 Jun 2015 18:51:59 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lists.ozlabs.org (Postfix) with ESMTP id E2EB21A019D for ; Mon, 29 Jun 2015 23:46:30 +1000 (AEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 29 Jun 2015 06:46:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,698,1427785200"; d="scan'208";a="752504470" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga002.fm.intel.com with ESMTP; 29 Jun 2015 06:46:29 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t5TDkSXL018095; Mon, 29 Jun 2015 14:46:28 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id t5TDkSWe030622; Mon, 29 Jun 2015 14:46:28 +0100 Received: (from sfinucan@localhost) by sivswdev01.ir.intel.com with id t5TDkSdM030617; Mon, 29 Jun 2015 14:46:28 +0100 From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH 07/11] tests: Move 'reverse' calls inside 'setUp' Date: Mon, 29 Jun 2015 14:46:07 +0100 Message-Id: <1435585571-25252-8-git-send-email-stephen.finucane@intel.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1435585571-25252-1-git-send-email-stephen.finucane@intel.com> References: <1435585571-25252-1-git-send-email-stephen.finucane@intel.com> X-Mailman-Approved-At: Tue, 30 Jun 2015 18:51:03 +1000 X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stephen Finucane MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Django creates test databases after it loads tests. If operations that access the database occur at class level, these will be executed before the test database has been created. Fix this by moving these calls into the relevant 'setUp' functions for each test. In addition to these changes, remove some obviously dead imports. Signed-off-by: Stephen Finucane --- patchwork/tests/test_confirm.py | 1 - patchwork/tests/test_mail_settings.py | 41 ++++++++++++++++------------------- patchwork/tests/test_notifications.py | 4 +--- patchwork/tests/test_user.py | 13 ++++++----- 4 files changed, 28 insertions(+), 31 deletions(-) diff --git a/patchwork/tests/test_confirm.py b/patchwork/tests/test_confirm.py index fad5125..9fe938e 100644 --- a/patchwork/tests/test_confirm.py +++ b/patchwork/tests/test_confirm.py @@ -17,7 +17,6 @@ # along with Patchwork; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -import unittest from django.test import TestCase from django.contrib.auth.models import User from django.core.urlresolvers import reverse diff --git a/patchwork/tests/test_mail_settings.py b/patchwork/tests/test_mail_settings.py index a193c97..477f39f 100644 --- a/patchwork/tests/test_mail_settings.py +++ b/patchwork/tests/test_mail_settings.py @@ -17,19 +17,17 @@ # along with Patchwork; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -import unittest import re from django.test import TestCase -from django.test.client import Client from django.core import mail from django.core.urlresolvers import reverse -from django.contrib.auth.models import User from patchwork.models import EmailOptout, EmailConfirmation, Person from patchwork.tests.utils import create_user, error_strings class MailSettingsTest(TestCase): - view = 'patchwork.views.mail.settings' - url = reverse(view) + + def setUp(self): + self.url = reverse('patchwork.views.mail.settings') def testMailSettingsGET(self): response = self.client.get(self.url) @@ -78,8 +76,9 @@ class MailSettingsTest(TestCase): self.assertTrue(('action="%s"' % optin_url) in response.content) class OptoutRequestTest(TestCase): - view = 'patchwork.views.mail.optout' - url = reverse(view) + + def setUp(self): + self.url = reverse('patchwork.views.mail.optout') def testOptOutRequestGET(self): response = self.client.get(self.url) @@ -124,10 +123,9 @@ class OptoutRequestTest(TestCase): self.assertEquals(len(mail.outbox), 0) class OptoutTest(TestCase): - view = 'patchwork.views.mail.optout' - url = reverse(view) def setUp(self): + self.url = reverse('patchwork.views.mail.optout') self.email = u'foo@example.com' self.conf = EmailConfirmation(type = 'optout', email = self.email) self.conf.save() @@ -157,10 +155,9 @@ class OptoutPreexistingTest(OptoutTest): EmailOptout(email = self.email).save() class OptinRequestTest(TestCase): - view = 'patchwork.views.mail.optin' - url = reverse(view) def setUp(self): + self.url = reverse('patchwork.views.mail.optin') self.email = u'foo@example.com' EmailOptout(email = self.email).save() @@ -232,8 +229,9 @@ class OptinTest(TestCase): class OptinWithoutOptoutTest(TestCase): """Test an opt-in with no existing opt-out""" - view = 'patchwork.views.mail.optin' - url = reverse(view) + + def setUp(self): + self.url = reverse('patchwork.views.mail.optin') def testOptInWithoutOptout(self): email = u'foo@example.com' @@ -248,16 +246,15 @@ class UserProfileOptoutFormTest(TestCase): """Test that the correct optin/optout forms appear on the user profile page, for logged-in users""" - view = 'patchwork.views.user.profile' - url = reverse(view) - optout_url = reverse('patchwork.views.mail.optout') - optin_url = reverse('patchwork.views.mail.optin') - form_re_template = (']*action="%(url)s"[^>]*>' - '.*?]*value="%(email)s"[^>]*>.*?' - '') - secondary_email = 'test2@example.com' - def setUp(self): + self.url = reverse('patchwork.views.user.profile') + self.optout_url = reverse('patchwork.views.mail.optout') + self.optin_url = reverse('patchwork.views.mail.optin') + self.form_re_template = (']*action="%(url)s"[^>]*>' + '.*?]*value="%(email)s"[^>]*>.*?' + '') + self.secondary_email = 'test2@example.com' + self.user = create_user() self.client.login(username = self.user.username, password = self.user.username) diff --git a/patchwork/tests/test_notifications.py b/patchwork/tests/test_notifications.py index c46af61..37adb8d 100644 --- a/patchwork/tests/test_notifications.py +++ b/patchwork/tests/test_notifications.py @@ -19,12 +19,10 @@ import datetime from django.test import TestCase -from django.core.urlresolvers import reverse from django.core import mail from django.conf import settings -from django.db.utils import IntegrityError from patchwork.models import Patch, State, PatchChangeNotification, EmailOptout -from patchwork.tests.utils import defaults, create_maintainer +from patchwork.tests.utils import defaults from patchwork.utils import send_notifications class PatchNotificationModelTest(TestCase): diff --git a/patchwork/tests/test_user.py b/patchwork/tests/test_user.py index 0faa970..d9aef7e 100644 --- a/patchwork/tests/test_user.py +++ b/patchwork/tests/test_user.py @@ -17,9 +17,7 @@ # along with Patchwork; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -import unittest from django.test import TestCase -from django.test.client import Client from django.core import mail from django.core.urlresolvers import reverse from django.conf import settings @@ -27,6 +25,7 @@ from django.contrib.auth.models import User from patchwork.models import EmailConfirmation, Person, Bundle from patchwork.tests.utils import defaults, error_strings + def _confirmation_url(conf): return reverse('patchwork.views.confirm', kwargs = {'key': conf.key}) @@ -121,7 +120,7 @@ class UserPersonConfirmTest(TestCase): self.assertEquals(conf.active, False) class UserLoginRedirectTest(TestCase): - + def testUserLoginRedirect(self): url = '/user/' response = self.client.get(url) @@ -157,8 +156,12 @@ class UserProfileTest(TestCase): self.assertContains(response, bundle.get_absolute_url()) class UserPasswordChangeTest(TestCase): - form_url = reverse('django.contrib.auth.views.password_change') - done_url = reverse('django.contrib.auth.views.password_change_done') + user = None + + def setUp(self): + self.form_url = reverse('django.contrib.auth.views.password_change') + self.done_url = reverse( + 'django.contrib.auth.views.password_change_done') def testPasswordChangeForm(self): self.user = TestUser()