Skip to content

Commit aa468af

Browse files
- Add trailing slash to API calls (#25)
- Removed unnecessary extra set in API handler - registries is just endpoints keys. - Fixed trailing slashes
1 parent 8ce0f3f commit aa468af

File tree

5 files changed

+11
-13
lines changed

5 files changed

+11
-13
lines changed

src/access_py_telemetry/api.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import multiprocessing
1818
from pathlib import Path, PurePosixPath
1919

20-
from .utils import ENDPOINTS, REGISTRIES
20+
from .utils import ENDPOINTS
2121

2222
S = TypeVar("S", bound="SessionID")
2323
H = TypeVar("H", bound="ApiHandler")
@@ -43,7 +43,6 @@ class ApiHandler:
4343
_instance = None
4444
_server_url = SERVER_URL[:]
4545
endpoints = {service: endpoint for service, endpoint in ENDPOINTS.items()}
46-
registries = {service for service in REGISTRIES}
4746
_extra_fields: dict[str, dict[str, Any]] = {ep_name: {} for ep_name in ENDPOINTS}
4847
_pop_fields: dict[str, list[str]] = {}
4948
_request_timeout = None
@@ -405,4 +404,4 @@ def _format_endpoint(server_url: str, endpoint: str) -> str:
405404
slash between them.
406405
"""
407406
endpoint = str(PurePosixPath(server_url) / endpoint.lstrip("/"))
408-
return re.sub(r"^(https?:/)", r"\1/", endpoint)
407+
return re.sub(r"^(https?:/)(.*?)(?<!/)\/?$", r"\1/\2/", endpoint)

src/access_py_telemetry/utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,3 @@ def build_endpoints(
5151
register.endpoint.replace("/", "_"): register.items
5252
for register in build_endpoints(config)
5353
}
54-
SERVER_URL = "https://tracking-services-d6c2fd311c12.herokuapp.com"

tests/conftest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# type: ignore
22
from pytest import fixture
3-
from access_py_telemetry.api import ApiHandler, ENDPOINTS, SERVER_URL, REGISTRIES
3+
from access_py_telemetry.api import ApiHandler, SERVER_URL
4+
from access_py_telemetry.utils import ENDPOINTS
45
from access_py_telemetry.registry import TelemetryRegister
56

67

@@ -15,7 +16,6 @@ def api_handler():
1516
ApiHandler._instance = None
1617
ApiHandler._server_url = SERVER_URL[:]
1718
ApiHandler.endpoints = {key: val for key, val in ENDPOINTS.items()}
18-
ApiHandler.registries = {key for key in REGISTRIES}
1919
ApiHandler._extra_fields = {ep_name: {} for ep_name in ENDPOINTS.keys()}
2020
ApiHandler._pop_fields = {}
2121

tests/test_api.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_api_handler_extra_fields(local_host, api_handler):
8484

8585
session1.add_extra_fields(XF_NAME, {"version": "1.0"})
8686

87-
blank_registries = {key: {} for key in session1.registries if key != XF_NAME}
87+
blank_registries = {key: {} for key in session1.endpoints if key != XF_NAME}
8888

8989
assert session2.extra_fields == {
9090
"intake_catalog": {"version": "1.0"},
@@ -307,22 +307,22 @@ def test_api_handler_set_timeout(api_handler):
307307
(
308308
"http://localhost:8000",
309309
"/some/endpoint",
310-
"http://localhost:8000/some/endpoint",
310+
"http://localhost:8000/some/endpoint/",
311311
),
312312
(
313313
"http://localhost:8000/",
314314
"some/endpoint/",
315-
"http://localhost:8000/some/endpoint",
315+
"http://localhost:8000/some/endpoint/",
316316
),
317317
(
318318
"https://localhost:8000",
319319
"/some/endpoint",
320-
"https://localhost:8000/some/endpoint",
320+
"https://localhost:8000/some/endpoint/",
321321
),
322322
(
323323
"https://localhost:8000/",
324324
"some/endpoint/",
325-
"https://localhost:8000/some/endpoint",
325+
"https://localhost:8000/some/endpoint/",
326326
),
327327
],
328328
)

tests/test_decorators.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def my_func():
2525
register = TelemetryRegister("intake_catalog")
2626
api_handler = ApiHandler()
2727
blank_registries = {
28-
key: {} for key in api_handler.registries if key != "intake_catalog"
28+
key: {} for key in api_handler.endpoints if key != "intake_catalog"
2929
}
3030

3131
assert api_handler.extra_fields == {
@@ -60,7 +60,7 @@ def my_func():
6060
api_handler = ApiHandler()
6161

6262
blank_registries = {
63-
key: {} for key in api_handler.registries if key != "intake_catalog"
63+
key: {} for key in api_handler.endpoints if key != "intake_catalog"
6464
}
6565

6666
assert api_handler.extra_fields == {

0 commit comments

Comments
 (0)