[PATCH 01/25] tests: Remove 'find_in_context'

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


The aformentioned function handled both dicts and lists in a request's
context field. Seeing as only dicts are ever returned, this is not
necessary.

Signed-off-by: Stephen Finucane <stephen.finucane at intel.com>
---
 patchwork/tests/test_bundles.py |   21 +++++++++++----------
 patchwork/tests/utils.py        |   12 ------------
 2 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/patchwork/tests/test_bundles.py b/patchwork/tests/test_bundles.py
index cbed216..e822fbe 100644
--- a/patchwork/tests/test_bundles.py
+++ b/patchwork/tests/test_bundles.py
@@ -25,11 +25,14 @@ import unittest
 from django.conf import settings
 from django.test import TestCase
 from django.utils.http import urlencode
-from django.utils.six.moves import range, zip
+from django.utils.six.moves import range
+from django.utils.six.moves import zip
 
-from patchwork.models import Bundle, BundlePatch
-from patchwork.tests.utils import (defaults, create_user, find_in_context,
-                                   create_patches)
+from patchwork.models import Bundle
+from patchwork.models import BundlePatch
+from patchwork.tests.utils import create_patches
+from patchwork.tests.utils import create_user
+from patchwork.tests.utils import defaults
 
 
 def bundle_url(bundle):
@@ -46,8 +49,7 @@ class BundleListTest(TestCase):
     def testNoBundles(self):
         response = self.client.get('/user/bundles/')
         self.assertEqual(response.status_code, 200)
-        self.assertEqual(
-            len(find_in_context(response.context, 'bundles')), 0)
+        self.assertEqual(len(response.context['bundles']), 0)
 
     def testSingleBundle(self):
         defaults.project.save()
@@ -55,8 +57,7 @@ class BundleListTest(TestCase):
         bundle.save()
         response = self.client.get('/user/bundles/')
         self.assertEqual(response.status_code, 200)
-        self.assertEqual(
-            len(find_in_context(response.context, 'bundles')), 1)
+        self.assertEqual(len(response.context['bundles']), 1)
 
     def tearDown(self):
         self.user.delete()
@@ -87,7 +88,7 @@ class BundleViewTest(BundleTestBase):
     def testEmptyBundle(self):
         response = self.client.get(bundle_url(self.bundle))
         self.assertEqual(response.status_code, 200)
-        page = find_in_context(response.context, 'page')
+        page = response.context['page']
         self.assertEqual(len(page.object_list), 0)
 
     def testNonEmptyBundle(self):
@@ -95,7 +96,7 @@ class BundleViewTest(BundleTestBase):
 
         response = self.client.get(bundle_url(self.bundle))
         self.assertEqual(response.status_code, 200)
-        page = find_in_context(response.context, 'page')
+        page = response.context['page']
         self.assertEqual(len(page.object_list), 1)
 
     def testBundleOrder(self):
diff --git a/patchwork/tests/utils.py b/patchwork/tests/utils.py
index 2608782..37478b6 100644
--- a/patchwork/tests/utils.py
+++ b/patchwork/tests/utils.py
@@ -126,18 +126,6 @@ def create_covers(count=1):
     return covers
 
 
-def find_in_context(context, key):
-    if isinstance(context, list):
-        for c in context:
-            v = find_in_context(c, key)
-            if v is not None:
-                return v
-    else:
-        if key in context:
-            return context[key]
-    return None
-
-
 def read_patch(filename, encoding=None):
     file_path = os.path.join(_test_patch_dir, filename)
     if encoding is not None:
-- 
1.7.4.1



More information about the Patchwork mailing list