Signed-off-by: Stephen Finucane <stephenfinuc...@hotmail.com> --- patchwork/admin.py | 5 +--- patchwork/fields.py | 3 +- patchwork/forms.py | 3 -- patchwork/tests/test_list.py | 23 ++++++++------- patchwork/tests/test_registration.py | 55 +++++++++++++++++------------------- patchwork/tests/test_rest_api.py | 2 +- patchwork/views/mail.py | 7 +++-- patchwork/views/user.py | 19 ++++++++----- 8 files changed, 57 insertions(+), 60 deletions(-)
diff --git a/patchwork/admin.py b/patchwork/admin.py index 0f217d7..85ffecf 100644 --- a/patchwork/admin.py +++ b/patchwork/admin.py @@ -68,10 +68,7 @@ class SubmissionAdmin(admin.ModelAdmin): search_fields = ('name', 'submitter__name', 'submitter__email') date_hierarchy = 'date' admin.site.register(Submission, SubmissionAdmin) - - -CoverLetterAdmin = SubmissionAdmin -admin.site.register(CoverLetter, CoverLetterAdmin) +admin.site.register(CoverLetter, SubmissionAdmin) class PatchAdmin(admin.ModelAdmin): diff --git a/patchwork/fields.py b/patchwork/fields.py index c0a1b4d..c9d7f66 100644 --- a/patchwork/fields.py +++ b/patchwork/fields.py @@ -28,7 +28,8 @@ from django.utils import six if django.VERSION < (1, 8): - HashFieldBase = six.with_metaclass(models.SubfieldBase, models.CharField) + HashFieldBase = six.with_metaclass(models.SubfieldBase, + models.CharField) # noqa else: HashFieldBase = models.CharField diff --git a/patchwork/forms.py b/patchwork/forms.py index 1897093..8f73f8b 100644 --- a/patchwork/forms.py +++ b/patchwork/forms.py @@ -254,6 +254,3 @@ class MultiplePatchForm(forms.Form): class EmailForm(forms.Form): email = forms.EmailField(max_length=200) - -UserPersonLinkForm = EmailForm -OptinoutRequestForm = EmailForm diff --git a/patchwork/tests/test_list.py b/patchwork/tests/test_list.py index 73b2b78..4a54001 100644 --- a/patchwork/tests/test_list.py +++ b/patchwork/tests/test_list.py @@ -19,7 +19,7 @@ from __future__ import absolute_import -import datetime +from datetime import datetime as dt import re from django.core.urlresolvers import reverse @@ -44,28 +44,27 @@ class EmptyPatchListTest(TestCase): class PatchOrderTest(TestCase): - d = datetime.datetime patchmeta = [ ('AlCMyjOsx', 'alxmyj...@nrbqkqv.wbw', - d(2014, 3, 16, 13, 4, 50, 155643)), + dt(2014, 3, 16, 13, 4, 50, 155643)), ('MMZnrcDjT', 'mmmnrc...@qgaifol.tbk', - d(2014, 1, 25, 13, 4, 50, 162814)), + dt(2014, 1, 25, 13, 4, 50, 162814)), ('WGirwRXgK', 'wgsrwr...@triiety.ghe', - d(2014, 2, 14, 13, 4, 50, 169305)), + dt(2014, 2, 14, 13, 4, 50, 169305)), ('isjNIuiAc', 'issniu...@oseiryx.ejh', - d(2014, 3, 15, 13, 4, 50, 176264)), + dt(2014, 3, 15, 13, 4, 50, 176264)), ('XkAQpYGws', 'xkfqpy...@hznttcm.jse', - d(2014, 1, 18, 13, 4, 50, 182493)), + dt(2014, 1, 18, 13, 4, 50, 182493)), ('uJuCPWMvi', 'ujacpw...@avrbobl.ecy', - d(2014, 3, 12, 13, 4, 50, 189554)), + dt(2014, 3, 12, 13, 4, 50, 189554)), ('TyQmWtcbg', 'tylmwt...@dzrnenh.jub', - d(2014, 2, 3, 13, 4, 50, 195685)), + dt(2014, 2, 3, 13, 4, 50, 195685)), ('FpvAhWRdX', 'fpkahw...@agxncai.wfo', - d(2014, 3, 15, 13, 4, 50, 201398)), + dt(2014, 3, 15, 13, 4, 50, 201398)), ('bmoYvnyWa', 'bmdyvn...@aeopnlx.juy', - d(2014, 3, 4, 13, 4, 50, 206800)), + dt(2014, 3, 4, 13, 4, 50, 206800)), ('CiReUQsAq', 'ciieuq...@dnoyruf.tti', - d(2014, 3, 28, 13, 4, 50, 212169)), + dt(2014, 3, 28, 13, 4, 50, 212169)), ] def setUp(self): diff --git a/patchwork/tests/test_registration.py b/patchwork/tests/test_registration.py index 998dd6f..96c4c98 100644 --- a/patchwork/tests/test_registration.py +++ b/patchwork/tests/test_registration.py @@ -34,6 +34,7 @@ def _confirmation_url(conf): class TestUser(object): firstname = 'Test' lastname = 'User' + fullname = ' '.join([firstname, lastname]) username = 'testuser' email = 't...@example.com' password = 'foobar' @@ -52,12 +53,12 @@ class RegistrationTest(TestCase): self.required_error = 'This field is required.' self.invalid_error = 'Enter a valid value.' - def testRegistrationForm(self): + def test_registration_form(self): response = self.client.get('/register/') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'patchwork/registration_form.html') - def testBlankFields(self): + def test_blank_fields(self): for field in ['username', 'email', 'password']: data = self.default_data.copy() del data[field] @@ -65,14 +66,14 @@ class RegistrationTest(TestCase): self.assertEqual(response.status_code, 200) self.assertFormError(response, 'form', field, self.required_error) - def testInvalidUsername(self): + def test_invalid_username(self): data = self.default_data.copy() data['username'] = 'invalid user' response = self.client.post('/register/', data) self.assertEqual(response.status_code, 200) self.assertFormError(response, 'form', 'username', self.invalid_error) - def testExistingUsername(self): + def test_existing_username(self): user = create_user() data = self.default_data.copy() data['username'] = user.username @@ -82,7 +83,7 @@ class RegistrationTest(TestCase): 'This username is already taken. Please choose ' 'another.') - def testExistingEmail(self): + def test_existing_email(self): user = create_user() data = self.default_data.copy() data['email'] = user.email @@ -92,7 +93,7 @@ class RegistrationTest(TestCase): 'This email address is already in use ' 'for the account "%s".\n' % user.username) - def testValidRegistration(self): + def test_valid_registration(self): response = self.client.post('/register/', self.default_data) self.assertEqual(response.status_code, 200) self.assertContains(response, 'confirmation email has been sent') @@ -128,13 +129,15 @@ class RegistrationConfirmationTest(TestCase): def setUp(self): self.user = TestUser() - self.default_data = {'username': self.user.username, - 'first_name': self.user.firstname, - 'last_name': self.user.lastname, - 'email': self.user.email, - 'password': self.user.password} - - def testRegistrationConfirmation(self): + self.default_data = { + 'username': self.user.username, + 'first_name': self.user.firstname, + 'last_name': self.user.lastname, + 'email': self.user.email, + 'password': self.user.password + } + + def test_valid(self): self.assertEqual(EmailConfirmation.objects.count(), 0) response = self.client.post('/register/', self.default_data) self.assertEqual(response.status_code, 200) @@ -154,10 +157,9 @@ class RegistrationConfirmationTest(TestCase): self.assertTrue(conf.user.is_active) self.assertFalse(conf.active) - def testRegistrationNewPersonSetup(self): - """ Check that the person object created after registration has the - correct details """ - + def test_new_person_setup(self): + """Check that the person object created after registration has the + correct details.""" # register self.assertEqual(EmailConfirmation.objects.count(), 0) response = self.client.post('/register/', self.default_data) @@ -173,15 +175,12 @@ class RegistrationConfirmationTest(TestCase): self.assertTrue(qs.exists()) person = Person.objects.get(email=self.user.email) - self.assertEqual(person.name, - self.user.firstname + ' ' + self.user.lastname) + self.assertEqual(person.name, self.user.fullname) - def testRegistrationExistingPersonSetup(self): + def test_existing_person_setup(self): """ Check that the person object created after registration has the correct details """ - - fullname = self.user.firstname + ' ' + self.user.lastname - person = Person(name=fullname, email=self.user.email) + person = Person(name=self.user.fullname, email=self.user.email) person.save() # register @@ -198,12 +197,10 @@ class RegistrationConfirmationTest(TestCase): self.assertEqual(person.name, fullname) - def testRegistrationExistingPersonUnmodified(self): - """ Check that an unconfirmed registration can't modify an existing - Person object""" - - fullname = self.user.firstname + ' ' + self.user.lastname - person = Person(name=fullname, email=self.user.email) + def test_existing_person_unmodified(self): + """Check that an unconfirmed registration can't modify an existing + Person object.""" + person = Person(name=self.user.fullname, email=self.user.email) person.save() # register diff --git a/patchwork/tests/test_rest_api.py b/patchwork/tests/test_rest_api.py index fce83fb..44a2859 100644 --- a/patchwork/tests/test_rest_api.py +++ b/patchwork/tests/test_rest_api.py @@ -39,7 +39,7 @@ if settings.ENABLE_REST_API: else: # stub out APITestCase from django.test import TestCase - APITestCase = TestCase + APITestCase = TestCase # noqa @unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API') diff --git a/patchwork/views/mail.py b/patchwork/views/mail.py index 8744d79..0875d34 100644 --- a/patchwork/views/mail.py +++ b/patchwork/views/mail.py @@ -26,8 +26,9 @@ from django.http import HttpResponseRedirect from django.shortcuts import render from patchwork.compat import render_to_string -from patchwork.forms import OptinoutRequestForm, EmailForm -from patchwork.models import EmailOptout, EmailConfirmation +from patchwork.forms import EmailForm +from patchwork.models import EmailConfirmation +from patchwork.models import EmailOptout def settings(request): @@ -88,7 +89,7 @@ def _optinout(request, action, description): if request.method != 'POST': return HttpResponseRedirect(reverse(settings)) - form = OptinoutRequestForm(data=request.POST) + form = EmailForm(data=request.POST) if not form.is_valid(): context['error'] = ('There was an error in the %s form. Please ' 'review the form and re-submit.' % description) diff --git a/patchwork/views/user.py b/patchwork/views/user.py index b82636f..84896bd 100644 --- a/patchwork/views/user.py +++ b/patchwork/views/user.py @@ -30,10 +30,15 @@ from django.shortcuts import render, get_object_or_404 from patchwork.compat import render_to_string from patchwork.filters import DelegateFilter -from patchwork.forms import (UserProfileForm, UserPersonLinkForm, - RegistrationForm) -from patchwork.models import (Project, Bundle, Person, EmailConfirmation, - State, EmailOptout) +from patchwork.forms import EmailForm +from patchwork.forms import RegistrationForm +from patchwork.forms import UserProfileForm +from patchwork.models import Bundle +from patchwork.models import EmailConfirmation +from patchwork.models import EmailOptout +from patchwork.models import Person +from patchwork.models import Project +from patchwork.models import State from patchwork.views import generic_list @@ -120,7 +125,7 @@ def profile(request): people = Person.objects.filter(user=request.user) \ .extra(select={'is_optout': optout_query}) context['linked_emails'] = people - context['linkform'] = UserPersonLinkForm() + context['linkform'] = EmailForm() return render(request, 'patchwork/profile.html', context) @@ -130,7 +135,7 @@ def link(request): context = {} if request.method == 'POST': - form = UserPersonLinkForm(request.POST) + form = EmailForm(request.POST) if form.is_valid(): conf = EmailConfirmation(type='userperson', user=request.user, @@ -150,7 +155,7 @@ def link(request): context['error'] = ('An error occurred during confirmation. ' 'Please try again later') else: - form = UserPersonLinkForm() + form = EmailForm() context['linkform'] = form -- 2.7.4 _______________________________________________ Patchwork mailing list Patchwork@lists.ozlabs.org https://lists.ozlabs.org/listinfo/patchwork