]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
trivial: Don't use non-Pythonic names
authorStephen Finucane <stephenfinucane@hotmail.com>
Fri, 9 Sep 2016 16:00:51 +0000 (17:00 +0100)
committerStephen Finucane <stephenfinucane@hotmail.com>
Sat, 24 Sep 2016 23:00:20 +0000 (00:00 +0100)
Signed-off-by: Stephen Finucane <stephenfinucane@hotmail.com>
Reviewed-by: Daniel Axtens <dja@axtens.net>
patchwork/admin.py
patchwork/fields.py
patchwork/forms.py
patchwork/tests/test_list.py
patchwork/tests/test_registration.py
patchwork/tests/test_rest_api.py
patchwork/views/mail.py
patchwork/views/user.py

index 0f217d71d397f17b53aad34edf3298c638e3cc08..85ffecfc768d09c5a7940310ec7a6b116ce3ad9a 100644 (file)
@@ -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):
index 6c000c0f682bbae744d93e89cd560ec3d19f3d50..086a9df2e32578c047856b3fe9b76f768ec74d05 100644 (file)
@@ -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
 
index 1897093cee8a3ea0eae1e59e0545533c058abccf..8f73f8ba512fb0984251e1c12e77ee489ba88bff 100644 (file)
@@ -254,6 +254,3 @@ class MultiplePatchForm(forms.Form):
 
 class EmailForm(forms.Form):
     email = forms.EmailField(max_length=200)
-
-UserPersonLinkForm = EmailForm
-OptinoutRequestForm = EmailForm
index 73b2b78f995d90439c891052651c797c7aadd817..4a54001871e6810c6c0d9b063db563c481783c59 100644 (file)
@@ -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', 'AlxMyjOsx@nRbqkQV.wBw',
-         d(2014, 3, 16, 13, 4, 50, 155643)),
+         dt(2014, 3, 16, 13, 4, 50, 155643)),
         ('MMZnrcDjT', 'MMmnrcDjT@qGaIfOl.tbk',
-         d(2014, 1, 25, 13, 4, 50, 162814)),
+         dt(2014, 1, 25, 13, 4, 50, 162814)),
         ('WGirwRXgK', 'WGSrwRXgK@TriIETY.GhE',
-         d(2014, 2, 14, 13, 4, 50, 169305)),
+         dt(2014, 2, 14, 13, 4, 50, 169305)),
         ('isjNIuiAc', 'issNIuiAc@OsEirYx.EJh',
-         d(2014, 3, 15, 13, 4, 50, 176264)),
+         dt(2014, 3, 15, 13, 4, 50, 176264)),
         ('XkAQpYGws', 'XkFQpYGws@hzntTcm.JSE',
-         d(2014, 1, 18, 13, 4, 50, 182493)),
+         dt(2014, 1, 18, 13, 4, 50, 182493)),
         ('uJuCPWMvi', 'uJACPWMvi@AVRBOBl.ecy',
-         d(2014, 3, 12, 13, 4, 50, 189554)),
+         dt(2014, 3, 12, 13, 4, 50, 189554)),
         ('TyQmWtcbg', 'TylmWtcbg@DzrNeNH.JuB',
-         d(2014, 2, 3, 13, 4, 50, 195685)),
+         dt(2014, 2, 3, 13, 4, 50, 195685)),
         ('FpvAhWRdX', 'FpKAhWRdX@agxnCAI.wFO',
-         d(2014, 3, 15, 13, 4, 50, 201398)),
+         dt(2014, 3, 15, 13, 4, 50, 201398)),
         ('bmoYvnyWa', 'bmdYvnyWa@aeoPnlX.juy',
-         d(2014, 3, 4, 13, 4, 50, 206800)),
+         dt(2014, 3, 4, 13, 4, 50, 206800)),
         ('CiReUQsAq', 'CiieUQsAq@DnOYRuf.TTI',
-         d(2014, 3, 28, 13, 4, 50, 212169)),
+         dt(2014, 3, 28, 13, 4, 50, 212169)),
     ]
 
     def setUp(self):
index 998dd6fdc1d6486e92952c3b77e71891f0c28da7..3f210d34b0042b60b0736a8cd056b7064d47b5b8 100644 (file)
@@ -34,6 +34,7 @@ def _confirmation_url(conf):
 class TestUser(object):
     firstname = 'Test'
     lastname = 'User'
+    fullname = ' '.join([firstname, lastname])
     username = 'testuser'
     email = 'test@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
@@ -196,14 +195,12 @@ class RegistrationConfirmationTest(TestCase):
 
         person = Person.objects.get(email=self.user.email)
 
-        self.assertEqual(person.name, fullname)
-
-    def testRegistrationExistingPersonUnmodified(self):
-        """ Check that an unconfirmed registration can't modify an existing
-            Person object"""
+        self.assertEqual(person.name, self.user.fullname)
 
-        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
@@ -214,4 +211,5 @@ class RegistrationConfirmationTest(TestCase):
         response = self.client.post('/register/', data)
         self.assertEqual(response.status_code, 200)
 
-        self.assertEqual(Person.objects.get(pk=person.pk).name, fullname)
+        self.assertEqual(Person.objects.get(pk=person.pk).name,
+                         self.user.fullname)
index fce83fbec856fd8ea58af8ef0eb4bcb970fc8a0f..44a28599734b17ad8df8269d7337e5b952d089e4 100644 (file)
@@ -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')
index 8744d79b59720b02514c1a702b0bc3d41b2e1deb..0875d34cd4e6ee70053bdb05dd53d29853e59a44 100644 (file)
@@ -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)
index b82636f085facc3fb347d42f14ae9f98ad971bc3..84896bd9f87b88f538e43efe7a5210c13afcecc9 100644 (file)
@@ -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