示例#1
0
 def test_get_remote_ref_cache_clear_reloads():
     remote_ref_uri = URI.from_string(
         "base/file1.json#/definitions/remote_ref")
     resolve_uri.cache_clear()
     with patch(f"{resolve_uri.__module__}.get_document") as mock_doc:
         mock_doc.side_effect = get_document
         _ = [resolve_uri(remote_ref_uri) for _ in range(3)]
         assert mock_doc.call_count == 2  # file1 and file2 loaded
         resolve_uri.cache_clear()
         remote_ref = resolve_uri(remote_ref_uri)
         assert mock_doc.call_count == 4
         assert remote_ref == {"type": "integer"}
示例#2
0
 def test_get_ref_with_escaped_chars(field: str):
     uri = URI.from_string(
         f"base/with-escaped-chars.json#/properties/{field}")
     result = resolve_uri(uri)
     assert result == {"type": "integer"}
示例#3
0
 def test_get_ref_with_newline(base: str):
     uri = URI.from_string(f"{base}#/top/ref\nto\nnewline/foo")
     result = resolve_uri(uri)
     assert result == "bar"
示例#4
0
 def test_get_uri_with_newline(reference: str):
     uri = URI.from_string(reference)
     result = resolve_uri(uri)
     assert result == {"foo": "bar"}
示例#5
0
 def test_get_ref_with_spaces(base: str):
     uri = URI.from_string(f"{base}#/top/ref to spaces/foo")
     result = resolve_uri(uri)
     assert result == "bar"
示例#6
0
 def test_get_non_reference():
     non_ref_uri = URI.from_string("base/nonref.json#/definitions")
     non_ref = resolve_uri(non_ref_uri)
     assert non_ref["$ref"] == {"type": "string"}
示例#7
0
 def test_get_nested_remote_ref():
     nested_remote_uri = URI.from_string(
         "base/file1.json#/definitions/remote_nested/foo")
     nested_remote = resolve_uri(nested_remote_uri)
     assert nested_remote == {"type": "array"}
示例#8
0
 def test_get_backref():
     backref_uri = URI.from_string("base/file1.json#/definitions/backref")
     backref = resolve_uri(backref_uri)
     assert backref == {"type": "null"}
示例#9
0
 def test_get_remote_ref():
     remote_ref_uri = URI.from_string(
         "base/file1.json#/definitions/remote_ref")
     remote_ref = resolve_uri(remote_ref_uri)
     assert remote_ref == {"type": "integer"}
示例#10
0
 def test_get_local_ref():
     local_ref_uri = URI.from_string(
         "base/file1.json#/definitions/local_ref")
     local_ref = resolve_uri(local_ref_uri)
     assert local_ref == {"type": "number"}
示例#11
0
 def test_get_no_ref():
     uri = URI.from_string("base/file1.json#/definitions/foo")
     data = resolve_uri(uri)
     assert data == {"type": "string"}