[PATCH 15/25] tests: Clean up 'test_person'

Stephen Finucane stephen.finucane at intel.com
Fri Jun 24 07:53:36 AEST 2016


* Don't use hardcode routes: use the reverse function instead
* Make use of 'create_' helper functions
* Include every import on its own line
* Use underscore_case, rather than camelCase

Signed-off-by: Stephen Finucane <stephen.finucane at intel.com>
---
 patchwork/tests/test_person.py |   38 +++++++++++++++++++-------------------
 1 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/patchwork/tests/test_person.py b/patchwork/tests/test_person.py
index ba00457..a07999a 100644
--- a/patchwork/tests/test_person.py
+++ b/patchwork/tests/test_person.py
@@ -20,40 +20,40 @@
 from __future__ import absolute_import
 
 import json
+
+from django.core.urlresolvers import reverse
 from django.test import TestCase
-from django.utils.six.moves import map, range
+from django.utils.six.moves import range
 
-from patchwork.models import Person
+from patchwork.tests.utils import create_person
 
 
 class SubmitterCompletionTest(TestCase):
 
-    def setUp(self):
-        self.people = [
-            Person(name="Test Name", email="test1 at example.com"),
-            Person(email="test2 at example.com"),
-        ]
-        list(map(lambda p: p.save(), self.people))
+    """Validate the 'submitter' autocomplete endpoint."""
 
-    def testNameComplete(self):
-        response = self.client.get('/submitter/', {'q': 'name'})
+    def test_name_complete(self):
+        people = [create_person(name='Test name'), create_person(name=None)]
+        response = self.client.get(reverse('api-submitters'), {'q': 'name'})
         self.assertEqual(response.status_code, 200)
         data = json.loads(response.content.decode())
         self.assertEqual(len(data), 1)
-        self.assertEqual(data[0]['name'], 'Test Name')
+        self.assertEqual(data[0]['name'], people[0].name)
 
-    def testEmailComplete(self):
-        response = self.client.get('/submitter/', {'q': 'test2'})
+    def test_email_complete(self):
+        people = [create_person(email='test1 at example.com'),
+                  create_person(email='test2 at example.com')]
+        response = self.client.get(reverse('api-submitters'), {'q': 'test2'})
         self.assertEqual(response.status_code, 200)
         data = json.loads(response.content.decode())
         self.assertEqual(len(data), 1)
-        self.assertEqual(data[0]['email'], 'test2 at example.com')
+        self.assertEqual(data[0]['email'], people[1].email)
 
-    def testCompleteLimit(self):
-        for i in range(3, 10):
-            person = Person(email='test%d at example.com' % i)
-            person.save()
-        response = self.client.get('/submitter/', {'q': 'test', 'l': 5})
+    def test_param_limit(self):
+        for i in range(10):
+            create_person()
+        response = self.client.get(reverse('api-submitters'),
+                                   {'q': 'test', 'l': 5})
         self.assertEqual(response.status_code, 200)
         data = json.loads(response.content.decode())
         self.assertEqual(len(data), 5)
-- 
1.7.4.1



More information about the Patchwork mailing list