diff --git a/tests/lib/test_prices.py b/tests/lib/test_prices.py index 8e4fec0..158e3c8 100644 --- a/tests/lib/test_prices.py +++ b/tests/lib/test_prices.py @@ -2,6 +2,7 @@ import unittest2 import mock +from unittest.mock import patch from api.lib.prices import * from tests.factories import ( DesignerFactory, @@ -42,6 +43,12 @@ standard_canvas = Material(name="standard-canvas", price=79920) class TestPrice(unittest2.TestCase): + + def setUp(self) -> None: + price_adjustments_patcher = patch('api.lib.prices.get_price_adjustment', return_value=1.0) + price_adjustments_patcher.start() + self.addCleanup(price_adjustments_patcher.stop) + def test_m2_price(self): self.assertEqual( 236, @@ -179,11 +186,11 @@ class TestPrice(unittest2.TestCase): def test_wallpaper_price_us(self): self.assertEqual( - 60, + 30, wallpaper_price( width=100, height=100, material=standard_wallpaper, market=us ), - "Minium price for US is 2 sqm", + "Minimum price for US is 1 sqm - old 2 sqm requirement is removed", ) def test_wallpaper_custom_inquiry_price(self): @@ -260,3 +267,17 @@ class TestPrice(unittest2.TestCase): self.assertEqual(179.0, wallpaper_kit_price(market=sweden, rounded=False, inc_vat=True)) self.assertEqual(18.0, wallpaper_kit_price(market=us)) self.assertEqual(169.0, wallpaper_kit_price(market=denmark)) + + +class TestPriceWithPriceAdjustment(unittest2.TestCase): + + def test_m2_price_with_price_adjustment(self): + patcher = patch('api.lib.prices.get_price_adjustment', return_value=1.1275) + patcher.start() + self.assertEqual( + 37, # round(23600/100.0 * 0.1 * 1.15 * 1.1275 * 1.21) = round(37,0264235) = 37 + wallpaper_m2_price( + material=standard_wallpaper, market=nl, inc_vat=True + ), + ) + patcher.stop() diff --git a/tests/resources/test_prices.py b/tests/resources/test_prices.py index 29fde34..b626b34 100644 --- a/tests/resources/test_prices.py +++ b/tests/resources/test_prices.py @@ -3,6 +3,7 @@ import flask_testing from api import create_app, db from api.models.product import Material, Product, Currencies from api.models import Inquiry, Designer, Market +from unittest.mock import patch class TestEndpoints(flask_testing.TestCase): @@ -11,10 +12,13 @@ class TestEndpoints(flask_testing.TestCase): def setUp(self): db.create_all() + self._price_adjustments_patcher = patch('api.lib.prices.get_price_adjustment', return_value=1.0) + self._price_adjustments_patcher.start() def tearDown(self): db.session.remove() db.drop_all() + self._price_adjustments_patcher.stop() def _add_market(self): currency = Currencies(iso3char="SEK", exchange_rate=1)