@@ -46,9 +46,89 @@ def test_api_prefix(TestCoreClient, prefix):
46
46
conformance = client .get (f"{ prefix } /conformance" )
47
47
assert conformance .status_code == 200 , conformance .json ()
48
48
49
+ # NOTE: The collections/collection/items/item links do not have the prefix
50
+ # because they are created in the fixtures
51
+ collections = client .get (f"{ prefix } /collections" )
52
+ assert collections .status_code == 200 , collections .json ()
53
+ collection_id = collections .json ()["collections" ][0 ]["id" ]
54
+ print (collections .json ()["links" ])
55
+ collection = client .get (f"{ prefix } /collections/{ collection_id } " )
56
+ assert collection .status_code == 200 , collection .json ()
57
+
58
+ items = client .get (f"{ prefix } /collections/{ collection_id } /items" )
59
+ assert items .status_code == 200 , items .json ()
60
+
61
+ item_id = items .json ()["features" ][0 ]["id" ]
62
+ item = client .get (f"{ prefix } /collections/{ collection_id } /items/{ item_id } " )
63
+ assert item .status_code == 200 , item .json ()
64
+
65
+ link_tests = [
66
+ ("root" , "application/json" , "/" ),
67
+ ("conformance" , "application/json" , "/conformance" ),
68
+ ("data" , "application/json" , "/collections" ),
69
+ ("search" , "application/geo+json" , "/search" ),
70
+ ("service-doc" , "text/html" , "/api.html" ),
71
+ ("service-desc" , "application/vnd.oai.openapi+json;version=3.0" , "/api" ),
72
+ ]
73
+
74
+ for rel_type , expected_media_type , expected_path in link_tests :
75
+ link = get_link (landing .json (), rel_type )
76
+
77
+ assert link is not None , f"Missing { rel_type } link in landing page"
78
+ assert link .get ("type" ) == expected_media_type
79
+
80
+ link_path = urllib .parse .urlsplit (link .get ("href" )).path
81
+ assert link_path == prefix + expected_path
82
+
83
+ resp = client .get (prefix + expected_path )
84
+ assert resp .status_code == 200
85
+
86
+
87
+ @pytest .mark .parametrize ("prefix" , ["" , "/a_prefix" ])
88
+ def test_async_api_prefix (AsyncTestCoreClient , prefix ):
89
+ api_settings = ApiSettings (
90
+ openapi_url = f"{ prefix } /api" ,
91
+ docs_url = f"{ prefix } /api.html" ,
92
+ )
93
+
94
+ api = StacApi (
95
+ settings = api_settings ,
96
+ client = AsyncTestCoreClient (),
97
+ router = APIRouter (prefix = prefix ),
98
+ )
99
+
100
+ with TestClient (api .app , base_url = "http://stac.io" ) as client :
101
+ landing = client .get (f"{ prefix } /" )
102
+ assert landing .status_code == 200 , landing .json ()
103
+
104
+ service_doc = client .get (f"{ prefix } /api.html" )
105
+ assert service_doc .status_code == 200 , service_doc .text
106
+
107
+ service_desc = client .get (f"{ prefix } /api" )
108
+ assert service_desc .status_code == 200 , service_desc .json ()
109
+
110
+ conformance = client .get (f"{ prefix } /conformance" )
111
+ assert conformance .status_code == 200 , conformance .json ()
112
+
113
+ collections = client .get (f"{ prefix } /collections" )
114
+ assert collections .status_code == 200 , collections .json ()
115
+ collection_id = collections .json ()["collections" ][0 ]["id" ]
116
+
117
+ collection = client .get (f"{ prefix } /collections/{ collection_id } " )
118
+ assert collection .status_code == 200 , collection .json ()
119
+
120
+ items = client .get (f"{ prefix } /collections/{ collection_id } /items" )
121
+ assert items .status_code == 200 , items .json ()
122
+
123
+ item_id = items .json ()["features" ][0 ]["id" ]
124
+ item = client .get (f"{ prefix } /collections/{ collection_id } /items/{ item_id } " )
125
+ assert item .status_code == 200 , item .json ()
126
+
49
127
link_tests = [
50
128
("root" , "application/json" , "/" ),
51
129
("conformance" , "application/json" , "/conformance" ),
130
+ ("data" , "application/json" , "/collections" ),
131
+ ("search" , "application/geo+json" , "/search" ),
52
132
("service-doc" , "text/html" , "/api.html" ),
53
133
("service-desc" , "application/vnd.oai.openapi+json;version=3.0" , "/api" ),
54
134
]
0 commit comments