Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 64 additions & 24 deletions schemas/curve.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,23 @@
"description": "The reference item for the value. (x-axis)",
"type": "string",
"enum": [
"o_n", "1w", "1m", "3m", "6m", "9m", "12m", "15m", "18m",
"21m", "24m", "27m", "30m", "33m", "36m", "60m", "120m"
"o_n",
"1w",
"1m",
"3m",
"6m",
"9m",
"12m",
"15m",
"18m",
"21m",
"24m",
"27m",
"30m",
"33m",
"36m",
"60m",
"120m"
]
},
"value": {
Expand All @@ -63,40 +78,65 @@
]
}
},
"required": ["reference", "value"]
"required": [
"reference",
"value"
]
}
},
"version_id": {
"description": "The version identifier of the data such as the firm's internal batch identifier.",
"type": "string"
}
},
"required": ["id", "date", "values"],
"required": [
"id",
"date",
"values"
],
"additionalProperties": true,
"if": {
"properties": { "type": { "const": "risk_rating" } },
"required": ["type"]
},
"then": {
"properties": {
"values": {
"items": {
"properties": {
"value": { "type": "string" }
"oneOf": [
{
"required": [
"type"
],
"properties": {
"type": {
"const": "risk_rating"
},
"values": {
"items": {
"properties": {
"value": {
"type": "string"
}
}
}
}
}
}
},
"else": {
"properties": {
"values": {
"items": {
"properties": {
"value": { "type": "number" }
},
{
"not": {
"required": [
"type"
],
"properties": {
"type": {
"const": "risk_rating"
}
}
},
"properties": {
"values": {
"items": {
"properties": {
"value": {
"type": "number"
}
}
}
}
}
}
}
}
]
}
7 changes: 3 additions & 4 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import requests
from string import ascii_lowercase, digits


HOME = os.path.join(os.path.dirname(__file__), "..")
SCHEMAS_DIR = os.path.join(HOME, "schemas")
DOCS_DIR = os.path.join(HOME, "documentation", "properties")
Expand Down Expand Up @@ -150,7 +149,7 @@ def check_schema_fields(schema_dir, schema_name):
errs.extend((prop, r) for r in required if r not in spec)
else:
try:
(url, ref_prop_path) = spec["$ref"].split("#")
url, ref_prop_path = spec["$ref"].split("#")
except ValueError as exc:
raise ValueError(
f"{spec} is not an appropriate format. Should be {{url}}#/{{property_path}}"
Expand All @@ -160,15 +159,15 @@ def check_schema_fields(schema_dir, schema_name):

prop_path_tuple = ref_prop_path.split("/")
if len(prop_path_tuple) == 3:
(start, base, ref_prop_name) = prop_path_tuple
start, base, ref_prop_name = prop_path_tuple
assert start == "", "Referenced property path must begin with /"
assert (
base == "properties"
), f"Referenced property for schemas should be /properties/{ref_prop_name} but got {ref_prop_path}"
ref_properties = resp.json()[base]

elif len(prop_path_tuple) == 2:
(start, ref_prop_name) = prop_path_tuple
start, ref_prop_name = prop_path_tuple
assert start == "", "Referenced property path must begin with /"
assert url.endswith(
"common.json"
Expand Down
8 changes: 6 additions & 2 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ def test_unknown_curve_type(self):
self.validator.validate(instance=unknown_curve)

unknown_curve["values"] = [{"reference": "1m", "value": "AAA"}]
with pytest.raises(ValidationError, match="is not of type 'number'"):
with pytest.raises(
ValidationError, match="is not valid under any of the given schemas"
):
self.validator.validate(instance=unknown_curve)

def test_invalid_mixed_value_types(self):
Expand All @@ -328,7 +330,9 @@ def test_invalid_mixed_value_types(self):
{"reference": "6m", "value": 0.02},
],
}
with pytest.raises(ValidationError, match="is not of type 'number'"):
with pytest.raises(
ValidationError, match="is not valid under any of the given schemas"
):
self.validator.validate(instance=invalid_mixed_curve)


Expand Down