P5-4418 validate Pwinty SKU code
This commit is contained in:
@@ -4,6 +4,7 @@ from api import create_app, db
|
||||
from api.models.product import Material, Product
|
||||
from api.models.inquiry import Inquiry
|
||||
from api.models.designer import Designer
|
||||
from api.lib import pwinty
|
||||
|
||||
|
||||
class TestEndpoints(flask_testing.TestCase):
|
||||
@@ -209,3 +210,13 @@ class TestEndpoints(flask_testing.TestCase):
|
||||
self.assert200(response)
|
||||
expected = [{"price": 557.5, "price_excl_vat": 446, "sku": "GLOBAL-CFP-12x12"}]
|
||||
self.assertEqual(expected, response.json["data"])
|
||||
|
||||
def test_framed_print_invalid_sku(self):
|
||||
response = self.client.get("/prices/framed-print?sku=invalid&territory=SE")
|
||||
self.assert400(response)
|
||||
self.assertEqual(
|
||||
"sku contains an invalid value, must be one of: {}".format(
|
||||
pwinty.SKU_CODES
|
||||
),
|
||||
response.json["message"],
|
||||
)
|
||||
|
||||
@@ -12,6 +12,7 @@ from api.validators import (
|
||||
validate_number,
|
||||
validate_territory,
|
||||
validate_jsonschema,
|
||||
validate_any_of,
|
||||
)
|
||||
|
||||
|
||||
@@ -138,3 +139,18 @@ class TestValidators(flask_testing.TestCase):
|
||||
content_type="application/json",
|
||||
).data,
|
||||
)
|
||||
|
||||
def test_validate_any_of(self):
|
||||
app = self.app
|
||||
|
||||
@app.route("/", methods=["GET"])
|
||||
@validate_any_of("color", ["red", "green", "blue"])
|
||||
def index():
|
||||
return "ok"
|
||||
|
||||
self.assertEqual(b"No color is specified", self.client.get("/").data)
|
||||
self.assertEqual(
|
||||
b"color contains an invalid value, must be one of: ['red', 'green', 'blue']",
|
||||
self.client.get("/?color=black").data,
|
||||
)
|
||||
self.assertEqual(b"ok", self.client.get("/?color=blue").data)
|
||||
|
||||
Reference in New Issue
Block a user