|
1 | 1 | """Tests for map_target_disease""" |
2 | | - |
| 2 | +import json |
3 | 3 | import unittest |
4 | 4 | from unittest.mock import patch |
5 | | -from typing import List |
6 | | -from tests.utils_for_recordprocessor_tests.values_for_recordprocessor_tests import TargetDiseaseElements |
7 | 5 | from tests.utils_for_recordprocessor_tests.mock_environment_variables import MOCK_ENVIRONMENT_DICT |
8 | 6 |
|
9 | 7 | with patch("os.environ", MOCK_ENVIRONMENT_DICT): |
10 | | - from mappings import map_target_disease, Vaccine |
| 8 | + from mappings import map_target_disease |
11 | 9 |
|
12 | 10 |
|
| 11 | +@patch("mappings.redis_client") |
13 | 12 | class TestMapTargetDisease(unittest.TestCase): |
14 | 13 | """ |
15 | 14 | Test that map_target_disease returns the correct target disease element for valid vaccine types, or [] for |
16 | 15 | invalid vaccine types. |
17 | 16 | """ |
18 | 17 |
|
19 | | - def test_map_target_disease_valid(self): |
| 18 | + def test_map_target_disease_valid(self, mock_redis_client): |
20 | 19 | """Tests map_target_disease returns the disease coding information when using valid vaccine types""" |
21 | | - # NOTE: TEST CASES SHOULD INCLUDE ALL VACCINE TYPES WHICH ARE VALID FOR THIS PRODUCT. |
22 | | - # A NEW VACCINE TYPE SHOULD BE ADDED TO THIS TEST EVERY TIME THERE IS A VACCINE TYPE UPLIFT |
23 | | - # (note that this will require adding the vaccine type to the TargetDiseaseElements class). |
24 | | - # Target disease elements are intentionally hardcoded as a way of ensuring that the correct code and display |
25 | | - # values are being used, and that the element is being built up correctly. |
26 | | - vaccines: List[Vaccine] = [Vaccine.RSV, Vaccine.COVID_19, Vaccine.FLU, Vaccine.MMR] |
27 | | - for vaccine in vaccines: |
28 | | - with self.subTest(vaccine=vaccine): |
29 | | - self.assertEqual(map_target_disease(vaccine), getattr(TargetDiseaseElements, vaccine.value)) |
30 | | - |
31 | | - def test_map_target_disease_invalid(self): |
| 20 | + mock_redis_client.hget.return_value = json.dumps([{ |
| 21 | + "code": "55735004", |
| 22 | + "term": "Respiratory syncytial virus infection (disorder)" |
| 23 | + }]) |
| 24 | + |
| 25 | + self.assertEqual(map_target_disease("RSV"), [{ |
| 26 | + "coding": [{ |
| 27 | + "system": "http://snomed.info/sct", |
| 28 | + "code": "55735004", |
| 29 | + "display": "Respiratory syncytial virus infection (disorder)" |
| 30 | + }] |
| 31 | + }]) |
| 32 | + |
| 33 | + mock_redis_client.hget.assert_called_with("vacc_to_diseases", "RSV") |
| 34 | + |
| 35 | + def test_map_target_disease_invalid(self, mock_redis_client): |
32 | 36 | """Tests map_target_disease does not return the disease coding information when using invalid vaccine types.""" |
| 37 | + |
| 38 | + mock_redis_client.hget.return_value = None |
| 39 | + |
33 | 40 | self.assertEqual(map_target_disease("invalid_vaccine"), []) |
34 | 41 |
|
| 42 | + mock_redis_client.hget.assert_called_with("vacc_to_diseases", "invalid_vaccine") |
| 43 | + |
35 | 44 |
|
36 | 45 | if __name__ == "__main__": |
37 | 46 | unittest.main() |
0 commit comments