Skip to content

Commit d5da7d7

Browse files
committed
resolver / reference tests (sqm)
1 parent 82dc9a5 commit d5da7d7

File tree

1 file changed

+56
-25
lines changed

1 file changed

+56
-25
lines changed

tests/test_resolver/test_resolver_reference.py

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,53 @@ def get_data_set():
1616
"//anotherserver.com/files/example.json",
1717
],
1818
"relative_references": [
19+
"#/definitions/myElement",
1920
"document.json#/myElement",
2021
"../document.json#/myElement",
2122
"../another-folder/document.json#/myElement",
2223
],
2324
"absolute_references": [
24-
"#/definitions/myElement",
2525
"http://path/to/your/resource",
2626
"http://path/to/your/resource.json#myElement",
2727
"//anotherserver.com/files/example.json",
2828
],
29-
"remotepath_by_reference": {
30-
"#/definitions/myElement": None,
29+
"full_document_references": [
30+
"http://path/to/your/resource",
31+
"//anotherserver.com/files/example.json",
32+
],
33+
"not_full_document_references": [
34+
"#/definitions/myElement",
35+
"document.json#/myElement",
36+
"../document.json#/myElement",
37+
"../another-folder/document.json#/myElement",
38+
"http://path/to/your/resource.json#myElement",
39+
],
40+
"path_by_reference": {
41+
"#/definitions/myElement": "",
3142
"document.json#/myElement": "document.json",
3243
"../document.json#/myElement": "../document.json",
3344
"../another-folder/document.json#/myElement": "../another-folder/document.json",
3445
"http://path/to/your/resource": "http://path/to/your/resource",
3546
"http://path/to/your/resource.json#myElement": "http://path/to/your/resource.json",
3647
"//anotherserver.com/files/example.json": "//anotherserver.com/files/example.json",
3748
},
38-
"path_by_reference": {
49+
"pointer_by_reference": {
3950
"#/definitions/myElement": "/definitions/myElement",
4051
"document.json#/myElement": "/myElement",
4152
"../document.json#/myElement": "/myElement",
4253
"../another-folder/document.json#/myElement": "/myElement",
43-
"http://path/to/your/resource": "/",
54+
"http://path/to/your/resource": "",
4455
"http://path/to/your/resource.json#myElement": "/myElement",
45-
"//anotherserver.com/files/example.json": "/",
56+
"//anotherserver.com/files/example.json": "",
4657
},
47-
"pathparent_by_reference": {
58+
"pointerparent_by_reference": {
4859
"#/definitions/myElement": "/definitions",
49-
"document.json#/myElement": "/",
50-
"../document.json#/myElement": "/",
51-
"../another-folder/document.json#/myElement": "/",
52-
"http://path/to/your/resource": "/",
53-
"http://path/to/your/resource.json#myElement": "/",
54-
"//anotherserver.com/files/example.json": "/",
60+
"document.json#/myElement": "",
61+
"../document.json#/myElement": "",
62+
"../another-folder/document.json#/myElement": "",
63+
"http://path/to/your/resource": None,
64+
"http://path/to/your/resource.json#myElement": "",
65+
"//anotherserver.com/files/example.json": None,
5566
},
5667
}
5768

@@ -138,37 +149,57 @@ def test_is_relative():
138149
assert ref.is_relative() == True
139150

140151

141-
def test_path():
152+
def test_pointer():
142153
from openapi_python_client.resolver.reference import Reference
143154

144155
data_set = get_data_set()
145156

146-
for ref_str in data_set["path_by_reference"].keys():
157+
for ref_str in data_set["pointer_by_reference"].keys():
147158
ref = Reference(ref_str)
148-
path = data_set["path_by_reference"][ref_str]
149-
assert ref.path == path
159+
pointer = data_set["pointer_by_reference"][ref_str]
160+
assert ref.pointer.value == pointer
150161

151162

152-
def test_path_parent():
163+
def test_pointer_parent():
153164
from openapi_python_client.resolver.reference import Reference
154165

155166
data_set = get_data_set()
156167

157-
for ref_str in data_set["pathparent_by_reference"].keys():
168+
for ref_str in data_set["pointerparent_by_reference"].keys():
158169
ref = Reference(ref_str)
159-
path_parent = data_set["pathparent_by_reference"][ref_str]
160-
assert ref.path_parent == path_parent
170+
pointer_parent = data_set["pointerparent_by_reference"][ref_str]
171+
172+
if pointer_parent is not None:
173+
assert ref.pointer.parent.value == pointer_parent
174+
else:
175+
assert ref.pointer.parent == None
161176

162177

163-
def test_remote_path():
178+
def test_path():
164179
from openapi_python_client.resolver.reference import Reference
165180

166181
data_set = get_data_set()
167182

168-
for ref_str in data_set["remotepath_by_reference"].keys():
183+
for ref_str in data_set["path_by_reference"].keys():
184+
ref = Reference(ref_str)
185+
path = data_set["path_by_reference"][ref_str]
186+
assert ref.path == path
187+
188+
189+
def test_is_full_document():
190+
from openapi_python_client.resolver.reference import Reference
191+
192+
data_set = get_data_set()
193+
194+
for ref_str in data_set["full_document_references"]:
195+
ref = Reference(ref_str)
196+
assert ref.is_full_document() == True
197+
assert ref.pointer.parent == None
198+
199+
for ref_str in data_set["not_full_document_references"]:
169200
ref = Reference(ref_str)
170-
remote_path = data_set["remotepath_by_reference"][ref_str]
171-
assert ref.remote_path == remote_path
201+
assert ref.is_full_document() == False
202+
assert ref.pointer.parent != None
172203

173204

174205
def test_value():

0 commit comments

Comments
 (0)