File: test_util_resolver.py

package info (click to toggle)
python-prance 25.4.8.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,140 kB
  • sloc: python: 3,381; makefile: 205
file content (745 lines) | stat: -rw-r--r-- 22,201 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
"""Test suite for prance.util.resolver ."""

__author__ = "Jens Finkhaeuser"
__copyright__ = "Copyright (c) 2016-2021 Jens Finkhaeuser"
__license__ = "MIT"
__all__ = ()


import pytest
from unittest.mock import patch

from prance.util import fs
from prance.util import resolver
from prance.util.url import ResolutionError

from . import none_of


def get_specs(fname):
    specs = fs.read_file(fname)

    from prance.util import formats

    specs = formats.parse_spec(specs, fname)

    return specs


def mock_get_petstore(*args, **kwargs):
    from .mock_response import MockResponse, PETSTORE_YAML

    return MockResponse(text=PETSTORE_YAML)


def recursion_limit_handler_none(limit, refstring, recursions):
    return None


@pytest.fixture
def externals_file():
    return get_specs("tests/specs/with_externals.yaml")


@pytest.fixture
def recursive_objs_file():
    return get_specs("tests/specs/recursive_objs.yaml")


@pytest.fixture
def recursive_files_file():
    return get_specs("tests/specs/recursive_files.yaml")


@pytest.fixture
def recursion_limit_file():
    return get_specs("tests/specs/recursion_limit.yaml")


@pytest.fixture
def recursion_limit_files_file():
    return get_specs("tests/specs/recursion_limit_files.yaml")


@pytest.fixture
def missing_file():
    return get_specs("tests/specs/missing_reference.yaml")


def test_resolver_noname(externals_file):
    res = resolver.RefResolver(externals_file)
    # Can't build a fragment URL without reference
    with pytest.raises(ResolutionError):
        res.resolve_references()


@patch("requests.get")
def test_resolver_named(mock_get, externals_file):
    mock_get.side_effect = mock_get_petstore

    import os.path
    from prance.util import fs

    res = resolver.RefResolver(
        externals_file, fs.abspath("tests/specs/with_externals.yaml")
    )
    res.resolve_references()


@patch("requests.get")
def test_resolver_missing_reference(mock_get, missing_file):
    mock_get.side_effect = mock_get_petstore

    import os.path

    res = resolver.RefResolver(
        missing_file, fs.abspath("tests/specs/missing_reference.yaml")
    )
    with pytest.raises(ResolutionError) as exc:
        res.resolve_references()

    assert str(exc.value).startswith("Cannot resolve")


@patch("requests.get")
def test_resolver_recursive_objects(mock_get, recursive_objs_file):
    mock_get.side_effect = mock_get_petstore

    # Recursive references to objects are a problem
    import os.path

    res = resolver.RefResolver(
        recursive_objs_file, fs.abspath("tests/specs/recursive_objs.yaml")
    )
    with pytest.raises(ResolutionError) as exc:
        res.resolve_references()

    assert str(exc.value).startswith("Recursion reached limit")


@patch("requests.get")
def test_resolver_recursive_files(mock_get, recursive_files_file):
    mock_get.side_effect = mock_get_petstore

    # Recursive references to files are not a problem
    import os.path

    res = resolver.RefResolver(
        recursive_files_file, fs.abspath("tests/specs/recursive_files.yaml")
    )
    res.resolve_references()


def test_recursion_limit_do_not_recurse_raise(recursion_limit_file):
    # Expect the default behaviour to raise.
    import os.path

    res = resolver.RefResolver(
        recursion_limit_file, fs.abspath("tests/specs/recursion_limit.yaml")
    )
    with pytest.raises(ResolutionError) as exc:
        res.resolve_references()

    assert str(exc.value).startswith("Recursion reached limit of 1")


def test_recursion_limit_do_not_recurse_ignore(recursion_limit_file):
    # If we overload the handler, we should not get an error but should
    # also simply not have the 'next' field - or it should be None
    import os.path

    res = resolver.RefResolver(
        recursion_limit_file,
        fs.abspath("tests/specs/recursion_limit.yaml"),
        recursion_limit_handler=recursion_limit_handler_none,
    )
    res.resolve_references()

    from prance.util import formats

    contents = formats.serialize_spec(res.specs, "foo.yaml")

    # The effect of returning None on recursion limit should be that
    # despite having recursion, the outermost reference to
    # definitions/Pet should get resolved.
    assert (
        "properties" in res.specs["paths"]["/pets"]["get"]["responses"]["200"]["schema"]
    )

    # However, the 'next' field should not be resolved.
    assert (
        res.specs["paths"]["/pets"]["get"]["responses"]["200"]["schema"]["properties"][
            "next"
        ]["schema"]
        is None
    )


def test_recursion_limit_set_limit_ignore(recursion_limit_file):
    # If we overload the handler, and set the recursion limit higher,
    # we should get nested Pet objects a few levels deep.

    import os.path

    res = resolver.RefResolver(
        recursion_limit_file,
        fs.abspath("tests/specs/recursion_limit.yaml"),
        recursion_limit=2,
        recursion_limit_handler=recursion_limit_handler_none,
    )
    res.resolve_references()

    from prance.util import formats

    contents = formats.serialize_spec(res.specs, "foo.yaml")

    # The effect of returning None on recursion limit should be that
    # despite having recursion, the outermost reference to
    # definitions/Pet should get resolved.
    assert (
        "properties" in res.specs["paths"]["/pets"]["get"]["responses"]["200"]["schema"]
    )

    # However, the 'next' field should be resolved due to the higher recursion limit
    next_field = res.specs["paths"]["/pets"]["get"]["responses"]["200"]["schema"][
        "properties"
    ]["next"]["schema"]
    assert next_field is not None

    # But the 'next' field of the 'next' field should not be resolved.
    assert next_field["properties"]["next"]["schema"] is None


def test_recursion_limit_do_not_recurse_raise_files(recursion_limit_files_file):
    # Expect the default behaviour to raise.
    import os.path

    res = resolver.RefResolver(
        recursion_limit_files_file, fs.abspath("tests/specs/recursion_limit_files.yaml")
    )
    with pytest.raises(ResolutionError) as exc:
        res.resolve_references()

    assert str(exc.value).startswith("Recursion reached limit of 1")


def test_recursion_limit_do_not_recurse_ignore_files(recursion_limit_files_file):
    # If we overload the handler, we should not get an error but should
    # also simply not have the 'next' field - or it should be None
    import os.path

    res = resolver.RefResolver(
        recursion_limit_files_file,
        fs.abspath("tests/specs/recursion_limit_files.yaml"),
        recursion_limit_handler=recursion_limit_handler_none,
    )
    res.resolve_references()

    from prance.util import formats

    contents = formats.serialize_spec(res.specs, "foo.yaml")

    # The effect of returning None on recursion limit should be that
    # despite having recursion, the outermost reference to
    # definitions/Pet should get resolved.
    assert (
        "properties" in res.specs["paths"]["/pets"]["get"]["responses"]["200"]["schema"]
    )

    # However, the 'next' field should not be resolved.
    assert (
        res.specs["paths"]["/pets"]["get"]["responses"]["200"]["schema"]["properties"][
            "next"
        ]["schema"]
        is None
    )


def test_recursion_limit_set_limit_ignore_files(recursion_limit_files_file):
    # If we overload the handler, and set the recursion limit higher,
    # we should get nested Pet objects a few levels deep.

    import os.path

    res = resolver.RefResolver(
        recursion_limit_files_file,
        fs.abspath("tests/specs/recursion_limit_files.yaml"),
        recursion_limit=2,
        recursion_limit_handler=recursion_limit_handler_none,
    )
    res.resolve_references()

    from prance.util import formats

    contents = formats.serialize_spec(res.specs, "foo.yaml")

    # The effect of returning None on recursion limit should be that
    # despite having recursion, the outermost reference to
    # definitions/Pet should get resolved.
    assert (
        "properties" in res.specs["paths"]["/pets"]["get"]["responses"]["200"]["schema"]
    )

    # However, the 'next' field should be resolved due to the higher recursion limit
    next_field = res.specs["paths"]["/pets"]["get"]["responses"]["200"]["schema"][
        "properties"
    ]["next"]["schema"]
    assert next_field is not None

    # But the 'next' field of the 'next' field should not be resolved.
    assert next_field["properties"]["next"]["schema"] is None


@patch("requests.get")
def test_issue_22_empty_path(mock_get, externals_file):
    mock_get.side_effect = mock_get_petstore

    # The raw externals file must have unresolved data
    assert len(externals_file["paths"]["/pets/{petId}"]["get"]["parameters"]) == 1
    param = externals_file["paths"]["/pets/{petId}"]["get"]["parameters"][0]

    assert "overwritten" in param
    assert "$ref" in param

    import os.path
    from prance.util import fs

    res = resolver.RefResolver(
        externals_file, fs.abspath("tests/specs/with_externals.yaml")
    )
    res.resolve_references()

    # The tests should resolve the reference, but the reference overwrites
    # all else.
    assert len(res.specs["paths"]["/pets/{petId}"]["get"]["parameters"]) == 1
    param = res.specs["paths"]["/pets/{petId}"]["get"]["parameters"][0]

    # Dereferenced keys must exist here
    assert "type" in param
    assert "description" in param
    assert "required" in param
    assert "in" in param
    assert "name" in param

    # Previously defined keys must not
    assert "overwritten" not in param
    assert "$ref" not in param


def test_issue_38_tilde_one():
    specs = get_specs("tests/specs/issue_38_a.yaml")
    res = resolver.RefResolver(specs, fs.abspath("tests/specs/issue_38_a.yaml"))
    res.resolve_references()

    path = res.specs["paths"]["/api/v2/vms"]
    assert "get" in path
    assert "operationId" in path["get"]
    assert "description" in path["get"]


@patch("requests.get")
def test_issue_23_partial_resolution_all(mock_get):
    mock_get.side_effect = mock_get_petstore

    specs = get_specs("tests/specs/with_externals.yaml")
    res = resolver.RefResolver(specs, fs.abspath("tests/specs/with_externals.yaml"))
    res.resolve_references()

    # By default, all externals need to be resolved.
    from prance.util.path import path_get

    val = path_get(res.specs, ("paths", "/pets", "get", "responses", "200", "schema"))
    assert "$ref" not in val

    val = path_get(
        res.specs, ("paths", "/pets", "get", "responses", "default", "schema")
    )
    assert "$ref" not in val

    val = path_get(
        res.specs, ("paths", "/pets", "post", "responses", "default", "schema")
    )
    assert "$ref" not in val

    val = path_get(res.specs, ("paths", "/pets/{petId}", "get", "parameters", 0))
    assert "$ref" not in val

    val = path_get(
        res.specs, ("paths", "/pets/{petId}", "get", "responses", "200", "schema")
    )
    assert "$ref" not in val

    val = path_get(
        res.specs, ("paths", "/pets/{petId}", "get", "responses", "203", "schema")
    )
    assert "$ref" not in val

    val = path_get(
        res.specs, ("paths", "/pets/{petId}", "get", "responses", "default", "schema")
    )
    assert "$ref" not in val


def test_issue_23_partial_resolution_internal():
    specs = get_specs("tests/specs/with_externals.yaml")
    res = resolver.RefResolver(
        specs,
        fs.abspath("tests/specs/with_externals.yaml"),
        resolve_types=resolver.RESOLVE_INTERNAL,
    )
    res.resolve_references()

    # By default, all externals need to be resolved.
    from prance.util.path import path_get

    val = path_get(res.specs, ("paths", "/pets", "get", "responses", "200", "schema"))
    assert "$ref" in val

    val = path_get(
        res.specs, ("paths", "/pets", "get", "responses", "default", "schema")
    )
    assert "$ref" in val

    val = path_get(
        res.specs, ("paths", "/pets", "post", "responses", "default", "schema")
    )
    assert "$ref" in val

    val = path_get(res.specs, ("paths", "/pets/{petId}", "get", "parameters", 0))
    assert "$ref" in val

    val = path_get(
        res.specs, ("paths", "/pets/{petId}", "get", "responses", "200", "schema")
    )
    assert "$ref" in val

    val = path_get(
        res.specs, ("paths", "/pets/{petId}", "get", "responses", "203", "schema")
    )
    assert "$ref" in val

    val = path_get(
        res.specs, ("paths", "/pets/{petId}", "get", "responses", "default", "schema")
    )
    assert "$ref" not in val


def test_issue_23_partial_resolution_files():
    specs = get_specs("tests/specs/with_externals.yaml")
    res = resolver.RefResolver(
        specs,
        fs.abspath("tests/specs/with_externals.yaml"),
        resolve_types=resolver.RESOLVE_FILES,
    )
    res.resolve_references()

    # By default, all externals need to be resolved.
    from prance.util.path import path_get

    val = path_get(res.specs, ("paths", "/pets", "get", "responses", "200", "schema"))
    assert "$ref" not in val

    val = path_get(
        res.specs, ("paths", "/pets", "get", "responses", "default", "schema")
    )
    assert "$ref" not in val

    val = path_get(
        res.specs, ("paths", "/pets", "post", "responses", "default", "schema")
    )
    assert "$ref" not in val

    val = path_get(res.specs, ("paths", "/pets/{petId}", "get", "parameters", 0))
    assert "$ref" not in val

    val = path_get(
        res.specs, ("paths", "/pets/{petId}", "get", "responses", "200", "schema")
    )
    assert "$ref" in val

    val = path_get(
        res.specs, ("paths", "/pets/{petId}", "get", "responses", "203", "schema")
    )
    assert "$ref" not in val

    val = path_get(
        res.specs, ("paths", "/pets/{petId}", "get", "responses", "default", "schema")
    )
    assert "$ref" in val


@pytest.mark.skipif(none_of("openapi-spec-validator"), reason="Missing backends")
def test_issue_65_partial_resolution_files():
    specs = """openapi: "3.0.0"
info:
  title: ''
  version: '1.0.0'
paths: {}
components:
    schemas:
        SampleArray:
            type: array
            items:
              $ref: '#/components/schemas/ItemType'

        ItemType:
          type: integer
"""
    from prance.util import formats

    specs = formats.parse_spec(specs, "issue_65.yaml")

    res = resolver.RefResolver(
        specs, fs.abspath("issue_65.yaml"), resolve_types=resolver.RESOLVE_FILES
    )
    res.resolve_references()

    from prance.util.path import path_get

    val = path_get(res.specs, ("components", "schemas", "SampleArray", "items"))
    assert "$ref" in val


@patch("requests.get")
def test_issue_23_partial_resolution_http(mock_get):
    mock_get.side_effect = mock_get_petstore

    specs = get_specs("tests/specs/with_externals.yaml")
    res = resolver.RefResolver(
        specs,
        fs.abspath("tests/specs/with_externals.yaml"),
        resolve_types=resolver.RESOLVE_HTTP,
    )
    res.resolve_references()

    # By default, all externals need to be resolved.
    from prance.util.path import path_get

    val = path_get(res.specs, ("paths", "/pets", "get", "responses", "200", "schema"))
    assert "$ref" in val

    val = path_get(
        res.specs, ("paths", "/pets", "get", "responses", "default", "schema")
    )
    assert "$ref" in val

    val = path_get(
        res.specs, ("paths", "/pets", "post", "responses", "default", "schema")
    )
    assert "$ref" in val

    val = path_get(res.specs, ("paths", "/pets/{petId}", "get", "parameters", 0))
    assert "$ref" in val

    val = path_get(
        res.specs, ("paths", "/pets/{petId}", "get", "responses", "200", "schema")
    )
    assert "$ref" not in val

    val = path_get(
        res.specs, ("paths", "/pets/{petId}", "get", "responses", "203", "schema")
    )
    assert "$ref" in val

    val = path_get(
        res.specs, ("paths", "/pets/{petId}", "get", "responses", "default", "schema")
    )
    assert "$ref" in val


def test_issue_23_partial_resolution_invalid_scheme():
    specs = {"$ref": "foo://cannot-do-anything"}
    res = resolver.RefResolver(specs, fs.abspath("tests/specs/with_externals.yaml"))

    with pytest.raises(ValueError):
        res.resolve_references()


def test_issue_69_urlparse_error():
    # XXX depending on python version, the error may not actually come from
    #     parsing the URL, but from trying to load a local file that does
    #     not exist. See test_issue_72_* for a test case that specifically
    #     tries for a nonexistent file url.
    specs = {"$ref": "file://a\u2100b/bad/netloc"}
    res = resolver.RefResolver(specs, fs.abspath("tests/specs/with_externals.yaml"))

    with pytest.raises(ResolutionError) as exinfo:
        res.resolve_references()

    assert "bad/netloc" in str(exinfo.value)


def test_issue_72_nonexistent_file_error():
    specs = {"$ref": "file://does/not/exist"}
    res = resolver.RefResolver(specs, fs.abspath("tests/specs/with_externals.yaml"))

    with pytest.raises(ResolutionError) as exinfo:
        res.resolve_references()

    assert "not/exist" in str(exinfo.value)


@pytest.mark.skipif(none_of("openapi-spec-validator"), reason="Missing backends")
def test_issue_78_resolve_internal_bug():
    specs = ""
    with open("tests/specs/issue_78/openapi.json") as fh:
        specs = fh.read()

    from prance.util import formats

    specs = formats.parse_spec(specs, "openapi.json")

    res = resolver.RefResolver(
        specs, fs.abspath("openapi.json"), resolve_types=resolver.RESOLVE_FILES
    )
    res.resolve_references()

    from prance.util.path import path_get

    val = path_get(res.specs, ("paths", "/endpoint", "post", "requestBody", "content"))

    # Reference to file is resolved
    assert "application/json" in val
    # Internal reference within file is NOT resolved
    assert "$ref" in val["application/json"]


@pytest.mark.skipif(none_of("openapi-spec-validator"), reason="Missing backends")
def test_issue_77_translate_external():
    specs = ""
    with open("tests/specs/issue_78/openapi.json") as fh:
        specs = fh.read()

    from prance.util import formats

    specs = formats.parse_spec(specs, "openapi.json")

    res = resolver.RefResolver(
        specs,
        fs.abspath("openapi.json"),
        resolve_types=resolver.RESOLVE_FILES,
        resolve_method=resolver.TRANSLATE_EXTERNAL,
    )
    res.resolve_references()

    from prance.util.path import path_get

    val = path_get(res.specs, ("components", "schemas", "_schemas.json_Body"))

    # Reference to file is translated in components/schemas
    assert "content" in val
    assert "application/json" in val["content"]

    # Reference url is updated
    val = path_get(res.specs, ("paths", "/endpoint", "post", "requestBody", "$ref"))
    assert val == "#/components/schemas/_schemas.json_Body"


@pytest.mark.skipif(none_of("openapi-spec-validator"), reason="Missing backends")
def test_issue_77_translate_external_refs_internal():
    specs = ""
    with open("tests/specs/issue_78/openapi.json") as fh:
        specs = fh.read()

    from prance.util import formats

    specs = formats.parse_spec(specs, "openapi.json")

    res = resolver.RefResolver(
        specs,
        fs.abspath("openapi.json"),
        resolve_types=resolver.RESOLVE_FILES | resolver.RESOLVE_INTERNAL,
        resolve_method=resolver.TRANSLATE_EXTERNAL,
    )
    res.resolve_references()

    from prance.util.path import path_get

    val = path_get(res.specs, ("components", "schemas", "_schemas.json_Body"))

    # Reference to file is translated in components/schemas
    assert "content" in val
    assert "application/json" in val["content"]

    # Internal Reference links updated
    assert (
        "#/components/schemas/_schemas.json_Something"
        == val["content"]["application/json"]["$ref"]
    )

    # Internal references is copied to components/schemas separately
    val = path_get(res.specs, ("components", "schemas", "_schemas.json_Something"))
    assert "type" in val

    # File reference url is updated as well
    val = path_get(res.specs, ("paths", "/endpoint", "post", "requestBody", "$ref"))
    assert val == "#/components/schemas/_schemas.json_Body"


@pytest.mark.skipif(none_of("openapi-spec-validator"), reason="Missing backends")
def test_issue_77_internal_refs_unresolved():
    specs = ""
    with open("tests/specs/issue_78/openapi.json") as fh:
        specs = fh.read()

    from prance.util import formats

    specs = formats.parse_spec(specs, "openapi.json")

    res = resolver.RefResolver(
        specs,
        fs.abspath("openapi.json"),
        resolve_types=resolver.RESOLVE_FILES,
        resolve_method=resolver.TRANSLATE_EXTERNAL,
    )
    res.resolve_references()

    from prance.util.path import path_get

    val = path_get(res.specs, ("components", "schemas"))

    # File reference resolved
    assert "_schemas.json_Body" in val

    # Internal file reference not resolved
    assert "_schemas.json_Something" not in val


@pytest.mark.xfail(reason="https://github.com/RonnyPfannschmidt/prance/issues/87")
def test_issue_205_swagger_resolution_failure():
    specs = ""
    with open("tests/specs/kubernetes_api_docs.json") as fh:
        specs = fh.read()

    from prance.util import formats

    specs = formats.parse_spec(specs, "kubernetes_api_docs.json")

    res = resolver.RefResolver(
        specs,
        fs.abspath("kubernetes_api_docs.json"),
        resolve_types=resolver.RESOLVE_FILES,
        resolve_method=resolver.TRANSLATE_EXTERNAL,
    )
    # test will raise an exception
    res.resolve_references()


@patch("requests.get")
def test_resolve_package_ref(mock_get):
    mock_get.side_effect = mock_get_petstore

    specs = get_specs("tests/specs/with_externals.yaml")
    res = resolver.RefResolver(
        specs,
        fs.abspath("tests/specs/with_externals.yaml"),
        resolve_types=resolver.RESOLVE_FILES,
    )
    res.resolve_references()

    from prance.util.path import path_get

    val = path_get(
        res.specs, ("paths", "/pets/{petId}", "get", "responses", "203", "schema")
    )
    assert "required" in val