Beispiel #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"}
Beispiel #2
0
 def test_ref_to_primitive():
     uri = URI.from_string(
         "base/ref-to-primitive.json#/top/ref_to_primitive")
     document = loader(uri.root)
     assert RefPointer(uri).resolve(document) == "foo"
Beispiel #3
0
 def uri() -> URI:
     return URI.from_string("base/file1.json#/")
Beispiel #4
0
 def ref_dict():
     return RefDict(URI.from_string("base/file1.json#/definitions"))
Beispiel #5
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"}
Beispiel #6
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"
Beispiel #7
0
 def test_get_uri_with_newline(reference: str):
     uri = URI.from_string(reference)
     result = resolve_uri(uri)
     assert result == {"foo": "bar"}
Beispiel #8
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"
Beispiel #9
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"}
Beispiel #10
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"}
Beispiel #11
0
 def test_get_backref():
     backref_uri = URI.from_string("base/file1.json#/definitions/backref")
     backref = resolve_uri(backref_uri)
     assert backref == {"type": "null"}
Beispiel #12
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"}
Beispiel #13
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"}
Beispiel #14
0
 def test_get_no_ref():
     uri = URI.from_string("base/file1.json#/definitions/foo")
     data = resolve_uri(uri)
     assert data == {"type": "string"}
Beispiel #15
0
def test_from_string_fails_for_bad_references(reference: str):
    with pytest.raises(ReferenceParseError):
        _ = URI.from_string(reference)
Beispiel #16
0
def test_from_string_modifies_bad_references(reference: str):
    uri = URI.from_string(reference)
    assert str(uri).endswith("#/")