|
68 | 68 | "writeOnlyProperties": ["/properties/d"],
|
69 | 69 | }
|
70 | 70 |
|
| 71 | +SCHEMA_WITH_NESTED_PROPERTIES = { |
| 72 | + "properties": { |
| 73 | + "a": {"type": "string"}, |
| 74 | + "g": {"type": "number"}, |
| 75 | + "b": {"$ref": "#/definitions/c"}, |
| 76 | + "f": { |
| 77 | + "type": "array", |
| 78 | + "items": {"$ref": "#/definitions/c"}, |
| 79 | + }, |
| 80 | + "h": { |
| 81 | + "type": "array", |
| 82 | + "insertionOrder": "false", |
| 83 | + "items": {"$ref": "#/definitions/c"}, |
| 84 | + }, |
| 85 | + }, |
| 86 | + "definitions": { |
| 87 | + "c": { |
| 88 | + "type": "object", |
| 89 | + "properties": {"d": {"type": "integer"}, "e": {"type": "integer"}}, |
| 90 | + } |
| 91 | + }, |
| 92 | + "readOnlyProperties": ["/properties/a"], |
| 93 | + "primaryIdentifier": ["/properties/a"], |
| 94 | + "writeOnlyProperties": ["/properties/g"], |
| 95 | +} |
| 96 | + |
71 | 97 | SCHEMA_WITH_COMPOSITE_KEY = {
|
72 | 98 | "properties": {
|
73 | 99 | "a": {"type": "number"},
|
@@ -1223,3 +1249,52 @@ def test_generate_update_example_with_composite_key(
|
1223 | 1249 | created_resource
|
1224 | 1250 | )
|
1225 | 1251 | assert updated_resource == {"a": 1, "c": 2, "d": 3}
|
| 1252 | + |
| 1253 | + |
| 1254 | +def test_compare_should_pass(resource_client): |
| 1255 | + resource_client._update_schema(SCHEMA_WITH_NESTED_PROPERTIES) |
| 1256 | + inputs = {"b": {"d": 1}, "f": [{"d": 1}], "h": [{"d": 1}, {"d": 2}]} |
| 1257 | + |
| 1258 | + outputs = { |
| 1259 | + "b": {"d": 1, "e": 3}, |
| 1260 | + "f": [{"d": 1, "e": 2}], |
| 1261 | + "h": [{"d": 1, "e": 3}, {"d": 2}], |
| 1262 | + } |
| 1263 | + resource_client.compare(inputs, outputs) |
| 1264 | + |
| 1265 | + |
| 1266 | +def test_compare_should_throw_exception(resource_client): |
| 1267 | + resource_client._update_schema(SCHEMA_WITH_NESTED_PROPERTIES) |
| 1268 | + inputs = {"b": {"d": 1}, "f": [{"d": 1}], "h": [{"d": 1}], "z": 1} |
| 1269 | + |
| 1270 | + outputs = { |
| 1271 | + "b": {"d": 1, "e": 2}, |
| 1272 | + "f": [{"d": 1}], |
| 1273 | + "h": [{"d": 1}], |
| 1274 | + } |
| 1275 | + try: |
| 1276 | + resource_client.compare(inputs, outputs) |
| 1277 | + except AssertionError: |
| 1278 | + logging.debug("This test expects Assertion Exception to be thrown") |
| 1279 | + |
| 1280 | + |
| 1281 | +def test_compare_should_throw_key_error(resource_client): |
| 1282 | + resource_client._update_schema(SCHEMA_WITH_NESTED_PROPERTIES) |
| 1283 | + inputs = {"b": {"d": 1}, "f": [{"d": 1}], "h": [{"d": 1}]} |
| 1284 | + |
| 1285 | + outputs = {"b": {"d": 1, "e": 2}, "f": [{"d": 1, "e": 2}, {"d": 2, "e": 3}]} |
| 1286 | + try: |
| 1287 | + resource_client.compare(inputs, outputs) |
| 1288 | + except AssertionError: |
| 1289 | + logging.debug("This test expects Assertion Exception to be thrown") |
| 1290 | + |
| 1291 | + |
| 1292 | +def test_compare_ordered_list_throws_assertion_exception(resource_client): |
| 1293 | + resource_client._update_schema(SCHEMA_WITH_NESTED_PROPERTIES) |
| 1294 | + inputs = {"b": {"d": 1}, "f": [{"d": 1}], "h": [{"d": 1}]} |
| 1295 | + |
| 1296 | + outputs = {"b": {"d": 1, "e": 2}, "f": [{"e": 2}, {"d": 2, "e": 3}]} |
| 1297 | + try: |
| 1298 | + resource_client.compare(inputs, outputs) |
| 1299 | + except AssertionError: |
| 1300 | + logging.debug("This test expects Assertion Exception to be thrown") |
0 commit comments