Skip to content

Commit

Permalink
Existing line, readded tests!
Browse files Browse the repository at this point in the history
  • Loading branch information
st8st8 committed Mar 3, 2024
1 parent 2af3057 commit 2516a2d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/oscar/apps/basket/abstract_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ def merge_line(self, line, add_quantities=True, strategy=None):
existing_line.quantity += line.quantity
else:
existing_line.quantity = max(existing_line.quantity, line.quantity)

if strategy:
existing_line.stockrecord = strategy.fetch_for_product(existing_line.product).stockrecord

Check warning on line 351 in src/oscar/apps/basket/abstract_models.py

View check run for this annotation

Codecov / codecov/patch

src/oscar/apps/basket/abstract_models.py#L351

Added line #L351 was not covered by tests
existing_line.save()
line.delete()
finally:
Expand Down
55 changes: 37 additions & 18 deletions tests/integration/partner/test_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

from django.test import TestCase

from oscar.apps.basket.models import Basket
from oscar.apps.basket.models import Line
from oscar.apps.catalogue import models
from oscar.apps.partner import strategy
from oscar.test import factories

from oscar.apps.basket.models import Basket
from oscar.test.basket import add_product


class TestDefaultStrategy(TestCase):
strategy = None
Expand Down Expand Up @@ -62,12 +60,41 @@ def test_availability_does_not_require_price(self):
info = self.strategy.fetch_for_product(product)
self.assertTrue(info.availability.is_available_to_buy)

def test_strategy_change_upon_login(self):
product_class = factories.ProductClassFactory(track_stock=False)
product = factories.ProductFactory(product_class=product_class, stockrecords=[])
factories.StockRecordFactory(price=None, product=product)
info = self.strategy.fetch_for_product(product)
self.assertTrue(info.availability.is_available_to_buy)

class UK2(strategy.UK):
def select_stockrecord(self, product):
try:
return product.stockrecords.all()[1]
except IndexError:
pass


class TestStrategyChange(TestCase):
basket = None
product = None
strategy = None

def setUp(self):
self.product = factories.create_product()
factories.create_stockrecord(product=self.product, partner_sku="1", price=1)
factories.create_stockrecord(product=self.product, partner_sku="2", price=2)
self.strategy = strategy.Default()
self.basket = Basket.objects.create()
self.basket.strategy = strategy.UK()
self.basket.add_product(self.product, 1)

def test_basket_price_changes_when_strategy_does(self):
self.assertEqual(self.basket.all_lines()[0].stockrecord.partner_sku, "1")
self.basket.strategy = UK2()
self.basket.freeze()
self.assertEqual(self.basket.total_excl_tax, 2)

def test_basket_stockrecord_does_not_change_when_strategy_does(self):
self.assertEqual(self.basket.all_lines()[0].stockrecord.partner_sku, "1")
self.basket.strategy = UK2()
self.basket.freeze()
self.assertEqual(self.basket.all_lines()[0].stockrecord.partner_sku, "1")
self.assertEqual(self.basket.total_excl_tax, 2)


class TestDefaultStrategyForParentProductWhoseVariantsHaveNoStockRecords(TestCase):
Expand Down Expand Up @@ -139,12 +166,4 @@ def test_pricing_policy_unavailable_if_no_price_excl_tax(self):
product = factories.ProductFactory(stockrecords=[])
factories.StockRecordFactory(price=None, product=product)
info = strategy.US().fetch_for_product(product)
self.assertFalse(info.price.exists)


class UK2(strategy.UK):
def select_stockrecord(self, product):
try:
return product.stockrecords.all()[1]
except IndexError:
pass
self.assertFalse(info.price.exists)

0 comments on commit 2516a2d

Please sign in to comment.