Skip to content

Commit d883ad7

Browse files
committed
18 errors
1 parent 4e98552 commit d883ad7

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

backend/tests/sample_data/mock_redis_cache.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,23 @@
2727
"MENACWY": "[{\"code\": \"23511006\", \"term\": \"Meningococcal infectious disease\"}]"
2828
}
2929

30-
def fake_hget(name, key):
31-
# Custom logic for your test
30+
31+
def get_data(name):
3232
if name == "diseases_to_vacc":
33-
if key in MOCK_REDIS_D2V_RESPONSE:
34-
return MOCK_REDIS_D2V_RESPONSE[key]
33+
return MOCK_REDIS_D2V_RESPONSE
3534
elif name == "vacc_to_diseases":
36-
if key in MOCK_REDIS_V2D_RESPONSE:
37-
return MOCK_REDIS_V2D_RESPONSE[key]
38-
return None
35+
return MOCK_REDIS_V2D_RESPONSE
36+
return {}
37+
38+
def fake_hget(name, key):
39+
ret = get_data(name)
40+
if key in ret:
41+
return ret[key]
42+
return {}
43+
44+
def fake_hkeys(name):
45+
ret = fake_hget(name)
46+
# return all keys
47+
if ret != {}:
48+
return list(ret.keys())
49+
return []

backend/tests/test_parameter_parser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
create_query_string,
1515
SearchParams,
1616
)
17-
from sample_data.mock_redis_cache import fake_hget
17+
from sample_data.mock_redis_cache import fake_hkeys
1818

1919
class TestParameterParser(unittest.TestCase):
2020
def setUp(self):
@@ -28,7 +28,7 @@ def setUp(self):
2828
self.mock_logger_info = self.logger_info_patcher.start()
2929
self.redis_patcher = patch("parameter_parser.redis_client")
3030
self.mock_redis_client = self.redis_patcher.start()
31-
self.mock_redis_client.hget.side_effect = fake_hget
31+
self.mock_redis_client.hkeys.side_effect = fake_hkeys
3232

3333
def tearDown(self):
3434
patch.stopall()
@@ -120,9 +120,9 @@ def test_process_search_params_whitelists_immunization_target(self):
120120
self.immunization_target_key: ["not-a-code"],
121121
}
122122
)
123-
self.assertEqual(
124-
str(e.exception),
125-
"immunization-target must be one or more of the following: COVID19, FLU, HPV, MMR, MMRV, RSV, PERTUSSIS, SHINGLES, PCV13, 3in1, MENACWY",
123+
self.assertTrue(
124+
str(e.exception).startswith("immunization-target must be one or more of the following:"),
125+
f"Unexpected exception message: {str(e.exception)}"
126126
)
127127

128128
params = process_search_params(

0 commit comments

Comments
 (0)