6
6
import pathlib
7
7
import unittest .mock
8
8
from copy import copy
9
+ from typing import Dict
10
+ from typing import Generator
9
11
10
12
import pystac
11
13
import pytest
15
17
16
18
17
19
@pytest .fixture
18
- def r_session ():
20
+ def r_session () -> Generator [ requests . Session , None , None ] :
19
21
yield requests .Session ()
20
22
21
23
22
24
@pytest .fixture
23
- def catalog_dict ():
25
+ def catalog_dict () -> Generator [ Dict [ str , str ], None , None ] :
24
26
current_path = pathlib .Path (os .path .dirname (os .path .abspath (__file__ )))
25
27
26
28
with open (current_path / "resources" / "landing_page.json" ) as f :
@@ -31,7 +33,7 @@ def catalog_dict():
31
33
32
34
33
35
@pytest .fixture
34
- def sample_item ():
36
+ def sample_item () -> Generator [ pystac . Item , None , None ] :
35
37
current_path = pathlib .Path (os .path .dirname (os .path .abspath (__file__ )))
36
38
37
39
with open (current_path / "resources" / "sample-item.json" ) as f :
@@ -42,7 +44,7 @@ def sample_item():
42
44
43
45
44
46
@pytest .fixture
45
- def expected_headers ():
47
+ def expected_headers () -> Generator [ Dict [ str , str ], None , None ] :
46
48
yield {
47
49
"User-Agent" : "python-requests/2.28.2" ,
48
50
"Accept-Encoding" : "gzip, deflate" ,
@@ -52,17 +54,23 @@ def expected_headers():
52
54
}
53
55
54
56
55
- def test_get_catalog (r_session , catalog_dict , expected_headers ):
56
- r_session .headers = copy (expected_headers )
57
+ def test_get_catalog (
58
+ r_session : requests .Session ,
59
+ catalog_dict : Dict [str , str ],
60
+ expected_headers : Dict [str , str ],
61
+ ) -> None :
62
+ r_session .headers = copy (expected_headers ) # type: ignore
57
63
expected_headers .update ({"Accept-Encoding" : "*" })
58
64
59
65
catalog = validations .get_catalog (catalog_dict , r_session )
60
- assert catalog ._stac_io .headers == expected_headers
66
+ assert catalog ._stac_io .headers == expected_headers # type: ignore
61
67
62
68
63
- def test_retrieve (r_session , expected_headers ):
69
+ def test_retrieve (
70
+ r_session : requests .Session , expected_headers : Dict [str , str ]
71
+ ) -> None :
64
72
headers = {"Authorization" : "api-key fake-api-key-value" }
65
- r_session .send = unittest .mock .MagicMock ()
73
+ r_session .send = unittest .mock .MagicMock () # type: ignore
66
74
r_session .send .status_code = 500
67
75
68
76
validations .retrieve (
@@ -78,7 +86,11 @@ def test_retrieve(r_session, expected_headers):
78
86
assert prepared_request_headers == expected_headers
79
87
80
88
81
- def test_validate_api (request , r_session , expected_headers ):
89
+ def test_validate_api (
90
+ request : pytest .FixtureRequest ,
91
+ r_session : requests .Session ,
92
+ expected_headers : Dict [str , str ],
93
+ ) -> None :
82
94
if request .config .getoption ("typeguard_packages" ):
83
95
pytest .skip (
84
96
"The import hook that typeguard uses seems to break the mock below."
@@ -104,14 +116,18 @@ def test_validate_api(request, r_session, expected_headers):
104
116
105
117
106
118
def test_validate_browseable (
107
- request , r_session , catalog_dict , sample_item , expected_headers
108
- ):
119
+ request : pytest .FixtureRequest ,
120
+ r_session : requests .Session ,
121
+ catalog_dict : Dict [str , str ],
122
+ sample_item : pystac .Item ,
123
+ expected_headers : Dict [str , str ],
124
+ ) -> None :
109
125
if request .config .getoption ("typeguard_packages" ):
110
126
pytest .skip (
111
127
"The import hook that typeguard uses seems to break the mock below."
112
128
)
113
129
114
- r_session .headers = copy (expected_headers )
130
+ r_session .headers = copy (expected_headers ) # type: ignore
115
131
116
132
with unittest .mock .patch (
117
133
"stac_api_validator.validations.get_catalog"
0 commit comments