stac-fastapi.api 2.5.5__tar.gz → 2.5.5.post1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/PKG-INFO +1 -1
  2. stac_fastapi_api-2.5.5.post1/stac_fastapi/api/version.py +2 -0
  3. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/stac_fastapi.api.egg-info/PKG-INFO +1 -1
  4. stac_fastapi_api-2.5.5.post1/tests/test_app_prefix.py +146 -0
  5. stac_fastapi_api-2.5.5/stac_fastapi/api/version.py +0 -2
  6. stac_fastapi_api-2.5.5/tests/test_app_prefix.py +0 -66
  7. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/README.md +0 -0
  8. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/setup.cfg +0 -0
  9. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/setup.py +0 -0
  10. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/stac_fastapi/api/__init__.py +0 -0
  11. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/stac_fastapi/api/app.py +0 -0
  12. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/stac_fastapi/api/config.py +0 -0
  13. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/stac_fastapi/api/errors.py +0 -0
  14. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/stac_fastapi/api/middleware.py +0 -0
  15. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/stac_fastapi/api/models.py +0 -0
  16. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/stac_fastapi/api/openapi.py +0 -0
  17. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/stac_fastapi/api/routes.py +0 -0
  18. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/stac_fastapi.api.egg-info/SOURCES.txt +0 -0
  19. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/stac_fastapi.api.egg-info/dependency_links.txt +0 -0
  20. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/stac_fastapi.api.egg-info/not-zip-safe +0 -0
  21. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/stac_fastapi.api.egg-info/requires.txt +0 -0
  22. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/stac_fastapi.api.egg-info/top_level.txt +0 -0
  23. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/tests/test_api.py +0 -0
  24. {stac_fastapi_api-2.5.5 → stac_fastapi_api-2.5.5.post1}/tests/test_middleware.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: stac-fastapi.api
3
- Version: 2.5.5
3
+ Version: 2.5.5.post1
4
4
  Summary: An implementation of STAC API based on the FastAPI framework.
5
5
  Home-page: https://github.com/stac-utils/stac-fastapi
6
6
  Author: Arturo Engineering
@@ -0,0 +1,2 @@
1
+ """Library version."""
2
+ __version__ = "2.5.5.post1"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: stac-fastapi.api
3
- Version: 2.5.5
3
+ Version: 2.5.5.post1
4
4
  Summary: An implementation of STAC API based on the FastAPI framework.
5
5
  Home-page: https://github.com/stac-utils/stac-fastapi
6
6
  Author: Arturo Engineering
@@ -0,0 +1,146 @@
1
+ import urllib
2
+ from typing import Optional
3
+
4
+ import pytest
5
+ from fastapi import APIRouter
6
+ from starlette.testclient import TestClient
7
+
8
+ from stac_fastapi.api.app import StacApi
9
+ from stac_fastapi.types.config import ApiSettings
10
+
11
+
12
+ def get_link(landing_page, rel_type, method: Optional[str] = None):
13
+ return next(
14
+ filter(
15
+ lambda link: link["rel"] == rel_type
16
+ and (not method or link.get("method") == method),
17
+ landing_page["links"],
18
+ ),
19
+ None,
20
+ )
21
+
22
+
23
+ @pytest.mark.parametrize("prefix", ["", "/a_prefix"])
24
+ def test_api_prefix(TestCoreClient, prefix):
25
+ api_settings = ApiSettings(
26
+ openapi_url=f"{prefix}/api",
27
+ docs_url=f"{prefix}/api.html",
28
+ )
29
+
30
+ api = StacApi(
31
+ settings=api_settings,
32
+ client=TestCoreClient(),
33
+ router=APIRouter(prefix=prefix),
34
+ )
35
+
36
+ with TestClient(api.app, base_url="http://stac.io") as client:
37
+ landing = client.get(f"{prefix}/")
38
+ assert landing.status_code == 200, landing.json()
39
+
40
+ service_doc = client.get(f"{prefix}/api.html")
41
+ assert service_doc.status_code == 200, service_doc.text
42
+
43
+ service_desc = client.get(f"{prefix}/api")
44
+ assert service_desc.status_code == 200, service_desc.json()
45
+
46
+ conformance = client.get(f"{prefix}/conformance")
47
+ assert conformance.status_code == 200, conformance.json()
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
+
127
+ link_tests = [
128
+ ("root", "application/json", "/"),
129
+ ("conformance", "application/json", "/conformance"),
130
+ ("data", "application/json", "/collections"),
131
+ ("search", "application/geo+json", "/search"),
132
+ ("service-doc", "text/html", "/api.html"),
133
+ ("service-desc", "application/vnd.oai.openapi+json;version=3.0", "/api"),
134
+ ]
135
+
136
+ for rel_type, expected_media_type, expected_path in link_tests:
137
+ link = get_link(landing.json(), rel_type)
138
+
139
+ assert link is not None, f"Missing {rel_type} link in landing page"
140
+ assert link.get("type") == expected_media_type
141
+
142
+ link_path = urllib.parse.urlsplit(link.get("href")).path
143
+ assert link_path == prefix + expected_path
144
+
145
+ resp = client.get(prefix + expected_path)
146
+ assert resp.status_code == 200
@@ -1,2 +0,0 @@
1
- """Library version."""
2
- __version__ = "2.5.5"
@@ -1,66 +0,0 @@
1
- import urllib
2
- from typing import Optional
3
-
4
- import pytest
5
- from fastapi import APIRouter
6
- from starlette.testclient import TestClient
7
-
8
- from stac_fastapi.api.app import StacApi
9
- from stac_fastapi.types.config import ApiSettings
10
-
11
-
12
- def get_link(landing_page, rel_type, method: Optional[str] = None):
13
- return next(
14
- filter(
15
- lambda link: link["rel"] == rel_type
16
- and (not method or link.get("method") == method),
17
- landing_page["links"],
18
- ),
19
- None,
20
- )
21
-
22
-
23
- @pytest.mark.parametrize("prefix", ["", "/a_prefix"])
24
- def test_api_prefix(TestCoreClient, prefix):
25
- api_settings = ApiSettings(
26
- openapi_url=f"{prefix}/api",
27
- docs_url=f"{prefix}/api.html",
28
- )
29
-
30
- api = StacApi(
31
- settings=api_settings,
32
- client=TestCoreClient(),
33
- router=APIRouter(prefix=prefix),
34
- )
35
-
36
- with TestClient(api.app, base_url="http://stac.io") as client:
37
- landing = client.get(f"{prefix}/")
38
- assert landing.status_code == 200, landing.json()
39
-
40
- service_doc = client.get(f"{prefix}/api.html")
41
- assert service_doc.status_code == 200, service_doc.text
42
-
43
- service_desc = client.get(f"{prefix}/api")
44
- assert service_desc.status_code == 200, service_desc.json()
45
-
46
- conformance = client.get(f"{prefix}/conformance")
47
- assert conformance.status_code == 200, conformance.json()
48
-
49
- link_tests = [
50
- ("root", "application/json", "/"),
51
- ("conformance", "application/json", "/conformance"),
52
- ("service-doc", "text/html", "/api.html"),
53
- ("service-desc", "application/vnd.oai.openapi+json;version=3.0", "/api"),
54
- ]
55
-
56
- for rel_type, expected_media_type, expected_path in link_tests:
57
- link = get_link(landing.json(), rel_type)
58
-
59
- assert link is not None, f"Missing {rel_type} link in landing page"
60
- assert link.get("type") == expected_media_type
61
-
62
- link_path = urllib.parse.urlsplit(link.get("href")).path
63
- assert link_path == prefix + expected_path
64
-
65
- resp = client.get(prefix + expected_path)
66
- assert resp.status_code == 200