Skip to content

Commit 10d3cf3

Browse files
Minor rewordings
1 parent cc20f8d commit 10d3cf3

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

src/daq_config_server/client.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
class RequestedResponseFormats(StrEnum):
16-
DICT = ValidAcceptHeaders.JSON # Convert to dict using json.loads()
16+
DICT = ValidAcceptHeaders.JSON # Convert to dict using Response.json()
1717
DECODED_STRING = ValidAcceptHeaders.PLAIN_TEXT # Use utf-8 decoding in response
1818
RAW_BYTE_STRING = ValidAcceptHeaders.RAW_BYTES # Use raw bytes in response
1919

@@ -60,11 +60,10 @@ def _cached_get(
6060
"""
6161

6262
try:
63-
r = requests.get(
64-
self._url + endpoint + (f"/{item}"), headers={"Accept": accept_header}
65-
)
63+
request_url = self._url + endpoint + (f"/{item}")
64+
r = requests.get(request_url, headers={"Accept": accept_header})
6665
r.raise_for_status()
67-
self._log.debug(f"Cache set for {endpoint}/{item}.")
66+
self._log.debug(f"Cache set for {request_url}.")
6867
return r
6968
except requests.exceptions.HTTPError as e:
7069
self._log.error(f"HTTP error: {e}")
@@ -121,21 +120,22 @@ def get_file_contents(
121120
) -> Any:
122121
"""
123122
Get contents of a file from the config server in the format specified.
124-
If data parsing fails, the return type will be bytes. Optionally try to use
125-
cached result.
123+
If data parsing fails, contents will return as raw bytes. Optionally look
124+
for cached result before making request.
126125
127126
Args:
128127
file_path: Path to the file.
129128
requested_response_format: Specify how to parse the response.
130-
reset_cached_result: Whether to reset cache for specific request.
129+
reset_cached_result: If true, make a request and store response in cache,
130+
otherwise look for cached response before making
131+
new request
131132
Returns:
132133
The file contents, in the format specified.
133134
"""
134135

135-
accept_header = requested_response_format
136136
return self._get(
137137
ENDPOINTS.CONFIG,
138-
accept_header,
138+
requested_response_format,
139139
file_path,
140140
reset_cached_result=reset_cached_result,
141141
)

tests/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from pathlib import Path
22

3-
TEST_DATA_DIR: Path = Path(f"{Path(__file__).parent}/test_data")
3+
TEST_DATA_DIR = Path(f"{Path(__file__).parent}/test_data")

tests/unit_tests/test_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ async def _assert_get_and_response(
3030
assert response.status_code == status.HTTP_200_OK
3131

3232
content_bytes = await response.aread()
33+
content_type = response.headers["content-type"].split(";")[0].strip()
3334

3435
# Copy logic of the real client when decoding responses
3536
try:
36-
match header["Accept"]:
37+
match content_type:
3738
case ValidAcceptHeaders.JSON:
3839
content = response.json()
3940
case ValidAcceptHeaders.PLAIN_TEXT:

tests/unit_tests/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test_get_file_contents_warns_and_gives_bytes_on_invalid_json(
9393

9494

9595
@patch("daq_config_server.client.requests.get")
96-
def test_read_unformatted_file_reading_reset_cached_result_true_without_cache(
96+
def test_get_file_contents_caching(
9797
mock_request: MagicMock,
9898
):
9999
"""Test reset_cached_result=False and reset_cached_result=True."""

0 commit comments

Comments
 (0)