Skip to content

Commit 2b7bc4c

Browse files
Update system test
1 parent 2873893 commit 2b7bc4c

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

tests/system_tests/test_client.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,35 +32,35 @@
3232

3333

3434
@pytest.fixture
35-
def server():
35+
def client():
3636
return ConfigClient(SERVER_ADDRESS)
3737

3838

3939
@pytest.fixture
40-
def deployed_server():
40+
def deployed_client():
4141
return ConfigClient(DEPLOYED_SERVER_ADDRESS)
4242

4343

4444
@pytest.mark.requires_local_server
45-
def test_read_unformatted_file_as_plain_text(server: ConfigClient):
45+
def test_read_unformatted_file_as_plain_text(client: ConfigClient):
4646
with open(TestDataPaths.TEST_BEAMLINE_PARAMETERS_PATH) as f:
4747
expected_response = f.read()
4848

4949
assert (
50-
server.get_file_contents(
50+
client.get_file_contents(
5151
ServerFilePaths.BEAMLINE_PARAMETERS,
5252
)
5353
== expected_response
5454
)
5555

5656

5757
@pytest.mark.requires_local_server
58-
def test_read_file_as_bytes(server: ConfigClient):
58+
def test_read_file_as_bytes(client: ConfigClient):
5959
with open(TestDataPaths.TEST_BEAMLINE_PARAMETERS_PATH, "rb") as f:
6060
expected_response = f.read()
6161

6262
assert (
63-
server.get_file_contents(
63+
client.get_file_contents(
6464
ServerFilePaths.BEAMLINE_PARAMETERS,
6565
bytes,
6666
)
@@ -69,12 +69,12 @@ def test_read_file_as_bytes(server: ConfigClient):
6969

7070

7171
@pytest.mark.requires_local_server
72-
def test_read_good_json_as_dict(server: ConfigClient):
72+
def test_read_good_json_as_dict(client: ConfigClient):
7373
with open(TestDataPaths.TEST_GOOD_JSON_PATH) as f:
7474
expected_response = json.loads(f.read())
7575

7676
assert (
77-
server.get_file_contents(
77+
client.get_file_contents(
7878
ServerFilePaths.GOOD_JSON_FILE,
7979
dict[Any, Any],
8080
)
@@ -83,12 +83,12 @@ def test_read_good_json_as_dict(server: ConfigClient):
8383

8484

8585
@pytest.mark.requires_local_server
86-
def test_read_good_json_as_untyped_dict(server: ConfigClient):
86+
def test_read_good_json_as_untyped_dict(client: ConfigClient):
8787
with open(TestDataPaths.TEST_GOOD_JSON_PATH) as f:
8888
expected_response = json.loads(f.read())
8989

9090
assert (
91-
server.get_file_contents(
91+
client.get_file_contents(
9292
ServerFilePaths.GOOD_JSON_FILE,
9393
dict,
9494
)
@@ -97,51 +97,51 @@ def test_read_good_json_as_untyped_dict(server: ConfigClient):
9797

9898

9999
@pytest.mark.requires_local_server
100-
def test_bad_json_gives_http_error_with_details(server: ConfigClient):
100+
def test_bad_json_gives_http_error_with_details(client: ConfigClient):
101101
file_path = ServerFilePaths.BAD_JSON_FILE
102102
file_name = os.path.basename(file_path)
103103
expected_detail = (
104104
f"Failed to convert {file_name} to application/json. "
105105
"Try requesting this file as a different type."
106106
)
107107

108-
server._log.error = MagicMock()
108+
client._log.error = MagicMock()
109109
with pytest.raises(requests.exceptions.HTTPError):
110-
server.get_file_contents(
110+
client.get_file_contents(
111111
file_path,
112112
dict[Any, Any],
113113
)
114-
server._log.error.assert_called_once_with(expected_detail)
114+
client._log.error.assert_called_once_with(expected_detail)
115115

116116

117117
@pytest.mark.requires_local_server
118-
def test_request_with_file_not_on_whitelist(server: ConfigClient):
118+
def test_request_with_file_not_on_whitelist(client: ConfigClient):
119119
file_path = "/not_allowed_file_location"
120120
with pytest.raises(
121121
requests.exceptions.HTTPError, match=f"{file_path} is not a whitelisted file."
122122
):
123-
server.get_file_contents(
123+
client.get_file_contents(
124124
file_path,
125125
)
126126

127127

128128
@pytest.mark.requires_local_server
129-
def test_request_for_file_with_converter_works(server: ConfigClient):
129+
def test_request_for_file_with_converter_works(client: ConfigClient):
130130
expected = {
131131
"rows": [[5700, 5.4606], [5760, 5.5], [6000, 5.681], [6500, 6.045]],
132132
}
133-
result = server.get_file_contents(ServerFilePaths.GOOD_LUT, dict)
133+
result = client.get_file_contents(ServerFilePaths.GOOD_LUT, dict)
134134
assert result == expected
135135

136136

137137
@pytest.mark.requires_local_server
138138
def test_request_for_file_with_converter_works_with_pydantic_model(
139-
server: ConfigClient,
139+
client: ConfigClient,
140140
):
141141
expected = UndulatorEnergyGapLookupTable(
142142
rows=[[5700, 5.4606], [5760, 5.5], [6000, 5.681], [6500, 6.045]],
143143
)
144-
result = server.get_file_contents(
144+
result = client.get_file_contents(
145145
ServerFilePaths.GOOD_LUT, UndulatorEnergyGapLookupTable
146146
)
147147
assert isinstance(result, UndulatorEnergyGapLookupTable)
@@ -150,10 +150,10 @@ def test_request_for_file_with_converter_works_with_pydantic_model(
150150

151151
@pytest.mark.requires_local_server
152152
def test_request_for_file_with_converter_with_wrong_pydantic_model_errors(
153-
server: ConfigClient,
153+
client: ConfigClient,
154154
):
155155
with pytest.raises(ValidationError):
156-
server.get_file_contents(ServerFilePaths.GOOD_LUT, DisplayConfig)
156+
client.get_file_contents(ServerFilePaths.GOOD_LUT, DisplayConfig)
157157

158158

159159
@pytest.mark.parametrize(
@@ -178,7 +178,7 @@ def test_request_for_file_with_converter_with_wrong_pydantic_model_errors(
178178
)
179179
@pytest.mark.requires_local_server
180180
def test_get_file_contents_with_force_parser_option_overides_converter_to_config_map(
181-
server: ConfigClient,
181+
client: ConfigClient,
182182
mock_file_converter_map: dict[str, Callable[[str], Any]],
183183
file_converter_map_entry: Callable[[str], Any] | None,
184184
desired_return_type: type[ConfigModel],
@@ -191,7 +191,7 @@ def test_get_file_contents_with_force_parser_option_overides_converter_to_config
191191
else:
192192
mock_file_converter_map[str(filepath)] = file_converter_map_entry
193193

194-
result = server.get_file_contents(
194+
result = client.get_file_contents(
195195
filepath,
196196
desired_return_type,
197197
force_parser=converter,
@@ -201,18 +201,18 @@ def test_get_file_contents_with_force_parser_option_overides_converter_to_config
201201

202202
@pytest.mark.requires_deployed_server
203203
def test_all_files_in_file_converter_map_can_be_converted_to_dict(
204-
deployed_server: ConfigClient,
204+
deployed_client: ConfigClient,
205205
):
206206
for filename in FILE_TO_CONVERTER_MAP.keys():
207207
if filename.startswith("/tests/test_data/"):
208208
continue
209-
result = deployed_server.get_file_contents(filename, dict)
209+
result = deployed_client.get_file_contents(filename, dict)
210210
assert isinstance(result, dict)
211211

212212

213213
@pytest.mark.requires_deployed_server
214214
def test_all_files_in_file_converter_map_can_be_converted_to_target_type(
215-
deployed_server: ConfigClient,
215+
deployed_client: ConfigClient,
216216
):
217217
with patch(
218218
"daq_config_server.app._file_converter_map.xmltodict.parse.__annotations__",
@@ -223,5 +223,5 @@ def test_all_files_in_file_converter_map_can_be_converted_to_target_type(
223223
continue
224224
return_type = get_type_hints(converter)["return"]
225225
assert return_type is dict or issubclass(return_type, ConfigModel)
226-
result = deployed_server.get_file_contents(filename, return_type)
226+
result = deployed_client.get_file_contents(filename, return_type)
227227
assert isinstance(result, return_type)

0 commit comments

Comments
 (0)