Fix unit tests (#62)

This commit is contained in:
Fredrik Ringqvist
2022-07-28 13:46:50 +02:00
committed by GitHub
parent 934537f0b9
commit 80dee6bd86
2 changed files with 27 additions and 2 deletions
+23 -2
View File
@@ -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()