add support for product price calculations
This commit is contained in:
+103
-14
@@ -1,8 +1,9 @@
|
||||
import json
|
||||
import flask_testing
|
||||
from api import create_app, db
|
||||
from api.models.product import Material, MaterialPrice
|
||||
from api.models.product import Material, MaterialPrice, Product
|
||||
from api.models.inquiry import Inquiry
|
||||
from api.models.designer import Designer
|
||||
|
||||
|
||||
class TestEndpoints(flask_testing.TestCase):
|
||||
@@ -31,31 +32,119 @@ class TestEndpoints(flask_testing.TestCase):
|
||||
db.session.commit()
|
||||
return inquiry
|
||||
|
||||
def _add_designer(self, pricepremium):
|
||||
designer = Designer('Disney', 'disney', 'US',
|
||||
'USD', pricepremium=pricepremium)
|
||||
db.session.add(designer)
|
||||
db.session.commit()
|
||||
return designer
|
||||
|
||||
def _add_product(self, designer=None):
|
||||
product = Product(designer=designer)
|
||||
db.session.add(product)
|
||||
db.session.commit()
|
||||
return product
|
||||
|
||||
def test_wallpaper(self):
|
||||
self._add_material('standard-wallpaper', 1, 236)
|
||||
self._add_material('premium-wallpaper', 1, 260)
|
||||
response = self.client.get(
|
||||
'/prices/wallpaper?width=200&height=10&territory=SE')
|
||||
self.assert200(response)
|
||||
products = response.json['data']
|
||||
self.assertEqual(2, len(products))
|
||||
expected = [
|
||||
{
|
||||
'm2_price': 295.0,
|
||||
'price_excl_vat': 236.0,
|
||||
'price': 295.0,
|
||||
'material': 'standard-wallpaper',
|
||||
'material_id': 1
|
||||
},
|
||||
{
|
||||
'm2_price': 325.0,
|
||||
'price_excl_vat': 260.0,
|
||||
'price': 325.0,
|
||||
'material': 'premium-wallpaper',
|
||||
'material_id': 2
|
||||
}
|
||||
]
|
||||
self.assertEqual(expected, response.json['data'])
|
||||
|
||||
def test_wallpaper_with_product(self):
|
||||
self._add_material('standard-wallpaper', 1, 236)
|
||||
self._add_material('premium-wallpaper', 1, 260)
|
||||
designer = self._add_designer(4)
|
||||
product = self._add_product(designer)
|
||||
response = self.client.get(
|
||||
'/prices/wallpaper?width=200&height=200&territory=SE&product=1')
|
||||
expected = [
|
||||
{
|
||||
'price': 1227.2,
|
||||
'price_excl_vat': 981.76,
|
||||
'material_id': 1,
|
||||
'm2_price': 306.8,
|
||||
'material': 'standard-wallpaper'
|
||||
},
|
||||
{
|
||||
'price': 1352.0000000000002,
|
||||
'price_excl_vat': 1081.6000000000001,
|
||||
'material_id': 2,
|
||||
'm2_price': 338.00000000000006,
|
||||
'material': 'premium-wallpaper'
|
||||
}
|
||||
]
|
||||
self.assertEqual(expected, response.json['data'])
|
||||
|
||||
def test_canvas(self):
|
||||
self._add_material('standard-canvas', 2, 799.2)
|
||||
response = self.client.get(
|
||||
'/prices/canvas?width=200&height=10&territory=SE')
|
||||
self.assert200(response)
|
||||
products = response.json['data']
|
||||
self.assertEqual(2, len(products))
|
||||
for product in products:
|
||||
if product['framed']:
|
||||
self.assertEqual(150, product['width'])
|
||||
self.assertEqual(40, product['height'])
|
||||
self.assertEqual(1213, product['price'])
|
||||
else:
|
||||
self.assertEqual(200, product['width'])
|
||||
self.assertEqual(20, product['height'])
|
||||
self.assertEqual(400, product['price'])
|
||||
expected = [
|
||||
{
|
||||
'price_excl_vat': 970.3471312000001,
|
||||
'price': 1212.9339140000002,
|
||||
'width': 150,
|
||||
'height': 40,
|
||||
'framed': True,
|
||||
'm2_price': 999.0
|
||||
},
|
||||
{
|
||||
'price_excl_vat': 319.68000000000006,
|
||||
'price': 399.6000000000001,
|
||||
'width': 200,
|
||||
'height': 20,
|
||||
'framed': False,
|
||||
'm2_price': 999.0
|
||||
}
|
||||
]
|
||||
self.assertEqual(expected, response.json['data'])
|
||||
|
||||
def test_canvas_with_product(self):
|
||||
self._add_material('standard-canvas', 2, 799.2)
|
||||
designer = self._add_designer(4)
|
||||
product = self._add_product(designer)
|
||||
response = self.client.get(
|
||||
'/prices/canvas?width=200&height=10&territory=SE&product=1')
|
||||
self.assert200(response)
|
||||
expected = [
|
||||
{
|
||||
'height': 40,
|
||||
'price_excl_vat': 989.5279312000002,
|
||||
'price': 1236.9099140000003,
|
||||
'framed': True,
|
||||
'm2_price': 1038.96,
|
||||
'width': 150
|
||||
},
|
||||
{
|
||||
'height': 20,
|
||||
'price_excl_vat': 332.46720000000005,
|
||||
'price': 415.58400000000006,
|
||||
'framed': False,
|
||||
'm2_price': 1038.96,
|
||||
'width': 200
|
||||
}
|
||||
]
|
||||
self.assertEqual(expected, response.json['data'])
|
||||
|
||||
def test_diy_frame(self):
|
||||
response = self.client.get(
|
||||
|
||||
Reference in New Issue
Block a user