Quellcode durchsuchen

Remove find_by_code method from repo

This was no longer being used as the checkout code had changed to load
all viable methods and then iterate over to find the appropriate one.
master
David Winterbottom vor 11 Jahren
Ursprung
Commit
0b7a136263

+ 1
- 0
oscar/apps/checkout/views.py Datei anzeigen

@@ -317,6 +317,7 @@ class ShippingMethodView(CheckoutSessionMixin, generic.TemplateView):
317 317
         # Save the code for the chosen shipping method in the session
318 318
         # and continue to the next step.
319 319
         self.checkout_session.use_shipping_method(method_code)
320
+
320 321
         return self.get_success_response()
321 322
 
322 323
     def get_success_response(self):

+ 4
- 13
oscar/apps/shipping/repository.py Datei anzeigen

@@ -15,6 +15,8 @@ class Repository(object):
15 15
     # that isn't thread safe.
16 16
     methods = (methods.Free,)
17 17
 
18
+    # API
19
+
18 20
     def get_shipping_methods(self, user, basket, shipping_addr=None,
19 21
                              request=None, **kwargs):
20 22
         """
@@ -48,6 +50,8 @@ class Repository(object):
48 50
         # Choose the cheapest method by default
49 51
         return min(shipping_methods, key=lambda method: method.charge_excl_tax)
50 52
 
53
+    # Helpers
54
+
51 55
     def prime_methods(self, basket, methods):
52 56
         """
53 57
         Prime a list of shipping method instances
@@ -82,16 +86,3 @@ class Repository(object):
82 86
                         method, discount['offer'])
83 87
 
84 88
         return method
85
-
86
-    def find_by_code(self, code, basket):
87
-        """
88
-        Return the appropriate Method object for the given code
89
-        """
90
-        for method_class in self.methods:
91
-            if method_class.code == code:
92
-                method = method_class()
93
-                return self.prime_method(basket, method)
94
-
95
-        # Check for NoShippingRequired as that is a special case
96
-        if code == methods.NoShippingRequired.code:
97
-            return self.prime_method(basket, methods.NoShippingRequired())

+ 5
- 16
tests/integration/order/creator_tests.py Datei anzeigen

@@ -8,7 +8,7 @@ from oscar.apps.catalogue.models import ProductClass, Product
8 8
 from oscar.apps.offer.utils import Applicator
9 9
 from oscar.apps.order.models import Order
10 10
 from oscar.apps.order.utils import OrderCreator
11
-from oscar.apps.shipping.methods import Free, Base
11
+from oscar.apps.shipping.methods import Free, FixedPrice
12 12
 from oscar.apps.shipping.repository import Repository
13 13
 from oscar.core.loading import get_class
14 14
 from oscar.test import factories
@@ -149,17 +149,6 @@ class TestPlacingOrderForDigitalGoods(TestCase):
149 149
         self.assertTrue(stockrecord.num_allocated is None)
150 150
 
151 151
 
152
-class Fixed(Base):
153
-    code = 'test'
154
-    charge_incl_tax = charge_excl_tax = D('5.00')
155
-    is_tax_known = True
156
-
157
-
158
-class StubRepository(Repository):
159
-    """ Custom shipping methods """
160
-    methods = (Fixed, Free)
161
-
162
-
163 152
 class TestShippingOfferForOrder(TestCase):
164 153
 
165 154
     def setUp(self):
@@ -179,8 +168,8 @@ class TestShippingOfferForOrder(TestCase):
179 168
         add_product(self.basket, D('12.00'))
180 169
         self.apply_20percent_shipping_offer()
181 170
 
182
-        # Normal shipping 5.00
183
-        shipping = StubRepository().find_by_code('test', self.basket)
171
+        shipping = FixedPrice(D('5.00'), D('5.00'))
172
+        shipping = Repository().prime_method(self.basket, shipping)
184 173
 
185 174
         place_order(self.creator,
186 175
                     basket=self.basket,
@@ -196,8 +185,8 @@ class TestShippingOfferForOrder(TestCase):
196 185
         add_product(self.basket, D('12.00'))
197 186
         self.apply_20percent_shipping_offer()
198 187
 
199
-        # Free shipping
200
-        shipping = StubRepository().find_by_code(Free.code, self.basket)
188
+        shipping = Free()
189
+        shipping = Repository().prime_method(self.basket, shipping)
201 190
 
202 191
         place_order(self.creator,
203 192
                     basket=self.basket,

+ 0
- 17
tests/unit/shipping/repository_tests.py Datei anzeigen

@@ -1,5 +1,3 @@
1
-from decimal import Decimal as D
2
-
3 1
 from django.test import TestCase
4 2
 from nose.plugins.attrib import attr
5 3
 
@@ -21,18 +19,3 @@ class TestShippingRepository(TestCase):
21 19
 
22 20
         method = available_methods[0]
23 21
         self.assertTrue(isinstance(method, methods.Free))
24
-        self.assertEqual(D('0.00'), method.charge_incl_tax)
25
-        self.assertEqual(D('0.00'), method.charge_excl_tax)
26
-
27
-    def test_allows_free_method_to_be_retrieved(self):
28
-        method = self.repo.find_by_code(methods.Free.code, self.basket)
29
-        self.assertTrue(isinstance(method, methods.Free))
30
-
31
-    def test_allows_no_shipping_required_method_to_be_retrieved(self):
32
-        method = self.repo.find_by_code(
33
-            methods.NoShippingRequired.code, self.basket)
34
-        self.assertTrue(isinstance(method, methods.NoShippingRequired))
35
-
36
-    def test_returns_none_for_unknown_code(self):
37
-        method = self.repo.find_by_code('asdf', self.basket)
38
-        self.assertIsNone(method)

Laden…
Abbrechen
Speichern