Quellcode durchsuchen

Replace local patch_settings decorator with Django's override_settings

It didn't exist when I wrote patch_settings but now there's not point
having two versions of the same thing.
master
David Winterbottom vor 13 Jahren
Ursprung
Commit
d94fdf4e24

+ 0
- 14
oscar/test/__init__.py Datei anzeigen

@@ -1,5 +1,4 @@
1 1
 import httplib
2
-from contextlib import contextmanager
3 2
 
4 3
 from django.test import TestCase
5 4
 from django.test.client import Client
@@ -9,19 +8,6 @@ from django_webtest import WebTest
9 8
 from purl import URL
10 9
 
11 10
 
12
-@contextmanager
13
-def patch_settings(**kwargs):
14
-    from django.conf import settings
15
-    backup = {}
16
-    for key, value in kwargs.items():
17
-        if hasattr(settings, key):
18
-            backup[key] = getattr(settings, key)
19
-        setattr(settings, key, value)
20
-    yield
21
-    for key, value in backup.items():
22
-        setattr(settings, key, value)
23
-
24
-
25 11
 class ClientTestCase(TestCase):
26 12
     username = 'dummyuser'
27 13
     email = 'dummyuser@example.com'

+ 4
- 3
tests/functional/checkout_tests.py Datei anzeigen

@@ -4,9 +4,10 @@ import sys
4 4
 from django.core.urlresolvers import reverse
5 5
 from django.conf import settings
6 6
 from django.utils.importlib import import_module
7
+from django.test.utils import override_settings
7 8
 
8 9
 from oscar.test.helpers import create_product, create_voucher
9
-from oscar.test import ClientTestCase, patch_settings
10
+from oscar.test import ClientTestCase
10 11
 from oscar.apps.basket.models import Basket
11 12
 from oscar.apps.order.models import Order
12 13
 from oscar.apps.address.models import Country
@@ -92,14 +93,14 @@ class EnabledAnonymousCheckoutViewsTests(ClientTestCase, CheckoutMixin):
92 93
                                                  'quantity': 1})
93 94
 
94 95
     def test_shipping_address_does_require_session_email_address(self):
95
-        with patch_settings(OSCAR_ALLOW_ANON_CHECKOUT=True):
96
+        with override_settings(OSCAR_ALLOW_ANON_CHECKOUT=True):
96 97
             self.reload_urlconf()
97 98
             url = reverse('checkout:shipping-address')
98 99
             response = self.client.get(url)
99 100
             self.assertIsRedirect(response)
100 101
 
101 102
     def test_email_address_is_saved_with_order(self):
102
-        with patch_settings(OSCAR_ALLOW_ANON_CHECKOUT=True):
103
+        with override_settings(OSCAR_ALLOW_ANON_CHECKOUT=True):
103 104
             self.reload_urlconf()
104 105
             self.add_product_to_basket()
105 106
             self.complete_guest_email_form('barry@example.com')

+ 6
- 7
tests/unit/core_tests.py Datei anzeigen

@@ -1,15 +1,14 @@
1 1
 from django.test import TestCase
2 2
 from django.core.exceptions import ValidationError
3 3
 from django.conf import settings
4
-
5 4
 from django.contrib.flatpages.models import FlatPage
5
+from django.test.utils import override_settings
6 6
 
7 7
 import oscar
8 8
 from oscar.core.loading import import_module, AppNotFoundError, \
9 9
         get_classes, get_class, ClassNotFoundError
10 10
 from oscar.core.validators import ExtendedURLValidator
11 11
 from oscar.core.validators import URLDoesNotExistValidator
12
-from oscar.test import patch_settings
13 12
 
14 13
 
15 14
 class TestImportModule(TestCase):
@@ -59,22 +58,22 @@ class ClassLoadingWithLocalOverrideTests(TestCase):
59 58
         self.installed_apps[self.installed_apps.index('oscar.apps.shipping')] = 'tests.site.shipping'
60 59
 
61 60
     def test_loading_class_defined_in_local_module(self):
62
-        with patch_settings(INSTALLED_APPS=self.installed_apps):
61
+        with override_settings(INSTALLED_APPS=self.installed_apps):
63 62
             (Free,) = get_classes('shipping.methods', ('Free',))
64 63
             self.assertEqual('tests.site.shipping.methods', Free.__module__)
65 64
 
66 65
     def test_loading_class_which_is_not_defined_in_local_module(self):
67
-        with patch_settings(INSTALLED_APPS=self.installed_apps):
66
+        with override_settings(INSTALLED_APPS=self.installed_apps):
68 67
             (FixedPrice,) = get_classes('shipping.methods', ('FixedPrice',))
69 68
             self.assertEqual('oscar.apps.shipping.methods', FixedPrice.__module__)
70 69
 
71 70
     def test_loading_class_from_module_not_defined_in_local_app(self):
72
-        with patch_settings(INSTALLED_APPS=self.installed_apps):
71
+        with override_settings(INSTALLED_APPS=self.installed_apps):
73 72
             (Repository,) = get_classes('shipping.repository', ('Repository',))
74 73
             self.assertEqual('oscar.apps.shipping.repository', Repository.__module__)
75 74
 
76 75
     def test_loading_classes_defined_in_both_local_and_oscar_modules(self):
77
-        with patch_settings(INSTALLED_APPS=self.installed_apps):
76
+        with override_settings(INSTALLED_APPS=self.installed_apps):
78 77
             (Free, FixedPrice) = get_classes('shipping.methods', ('Free', 'FixedPrice'))
79 78
             self.assertEqual('tests.site.shipping.methods', Free.__module__)
80 79
             self.assertEqual('oscar.apps.shipping.methods', FixedPrice.__module__)
@@ -142,7 +141,7 @@ class ClassLoadingWithLocalOverrideWithMultipleSegmentsTests(TestCase):
142 141
         self.installed_apps[self.installed_apps.index('oscar.apps.shipping')] = 'tests.site.apps.shipping'
143 142
 
144 143
     def test_loading_class_defined_in_local_module(self):
145
-        with patch_settings(INSTALLED_APPS=self.installed_apps):
144
+        with override_settings(INSTALLED_APPS=self.installed_apps):
146 145
             (Free,) = get_classes('shipping.methods', ('Free',))
147 146
             self.assertEqual('tests.site.apps.shipping.methods', Free.__module__)
148 147
 

+ 3
- 3
tests/unit/order/creator_tests.py Datei anzeigen

@@ -1,13 +1,13 @@
1 1
 from decimal import Decimal as D
2 2
 
3 3
 from django.test import TestCase
4
+from django.test.utils import override_settings
4 5
 from mock import Mock
5 6
 
6 7
 from oscar.apps.basket.models import Basket
7 8
 from oscar.apps.order.models import Order
8 9
 from oscar.test.helpers import create_product
9 10
 from oscar.apps.order.utils import OrderCreator
10
-from oscar.test import patch_settings
11 11
 
12 12
 
13 13
 class TestOrderCreatorErrorCases(TestCase):
@@ -69,14 +69,14 @@ class TestSuccessfulOrderCreation(TestCase):
69 69
 
70 70
     def test_uses_default_order_status_from_settings(self):
71 71
         self.basket.add_product(create_product(price=D('12.00')))
72
-        with patch_settings(OSCAR_INITIAL_ORDER_STATUS='A'):
72
+        with override_settings(OSCAR_INITIAL_ORDER_STATUS='A'):
73 73
             self.creator.place_order(basket=self.basket, order_number='1234')
74 74
         order = Order.objects.get(number='1234')
75 75
         self.assertEqual('A', order.status)
76 76
 
77 77
     def test_uses_default_line_status_from_settings(self):
78 78
         self.basket.add_product(create_product(price=D('12.00')))
79
-        with patch_settings(OSCAR_INITIAL_LINE_STATUS='A'):
79
+        with override_settings(OSCAR_INITIAL_LINE_STATUS='A'):
80 80
             self.creator.place_order(basket=self.basket, order_number='1234')
81 81
         order = Order.objects.get(number='1234')
82 82
         line = order.lines.all()[0]

Laden…
Abbrechen
Speichern