-
Notifications
You must be signed in to change notification settings - Fork 3
VED-790-Redis-Schema-Storage #867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6792846
debugs
nhsdevws 9fe7761
debug
nhsdevws d5cb381
generic json
nhsdevws 2daa43c
upload json
nhsdevws 40413ae
lint
nhsdevws 50169f6
tidy
nhsdevws 74d7dbe
tidy
nhsdevws c333cf3
tidy
nhsdevws 312966f
unit tests
nhsdevws e90c537
sonar check
nhsdevws 3ddcf64
sonar quotes
nhsdevws bf79557
Merge branch 'master' into VED-790-Redis-Schema-Storage
nhsdevws 3e1e352
coverage
nhsdevws bc09f1d
Merge branch 'master' into VED-790-Redis-Schema-Storage
nhsdevws 0c1ea2d
Validation Schema
nhsdevws 05182a5
tidy
nhsdevws 42fb582
Early Return
nhsdevws fd36f9d
rtransform test
nhsdevws a3bee76
validation_rules
nhsdevws 762fd6b
validation_rules_FILE_KEY
nhsdevws 3319cfc
TestTransformConfigs
nhsdevws c963376
validation rules test
nhsdevws File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| class RedisCacheKey: | ||
| PERMISSIONS_CONFIG_FILE_KEY = "permissions_config.json" | ||
| DISEASE_MAPPING_FILE_KEY = "disease_mapping.json" | ||
| VALIDATION_RULES_FILE_KEY = "validation_rules.json" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,22 @@ | ||
| from constants import RedisCacheKey | ||
| from transform_configs import transform_vaccine_map, transform_supplier_permissions | ||
| from transform_configs import ( | ||
| transform_vaccine_map, transform_supplier_permissions, transform_validation_rules | ||
| ) | ||
| from common.clients import logger | ||
| ''' | ||
| Transform config file to format required in REDIS cache. | ||
| ''' | ||
|
|
||
|
|
||
| def transform_map(data, file_type): | ||
| def transform_map(data, file_type) -> dict: | ||
| # Transform the vaccine map data as needed | ||
| logger.info("Transforming data for file type: %s", file_type) | ||
| if file_type == RedisCacheKey.PERMISSIONS_CONFIG_FILE_KEY: | ||
| return transform_supplier_permissions(data) | ||
| if file_type == RedisCacheKey.DISEASE_MAPPING_FILE_KEY: | ||
| return transform_vaccine_map(data) | ||
| if file_type == RedisCacheKey.VALIDATION_RULES_FILE_KEY: | ||
| return transform_validation_rules(data) | ||
|
|
||
| logger.info("No specific transformation defined for file type: %s", file_type) | ||
| return data # Default case, return data as is if no transformation is defined | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
|
|
||
| import unittest | ||
| from unittest.mock import patch | ||
| from transform_map import transform_map | ||
| from constants import RedisCacheKey | ||
|
|
||
|
|
||
| class TestTransformMap(unittest.TestCase): | ||
| def setUp(self): | ||
| self.mock_logger_info = patch("transform_map.logger.info").start() | ||
| self.mock_logger_warning = patch("transform_map.logger.warning").start() | ||
| self.mock_supplier_permissions = patch("transform_map.transform_supplier_permissions", | ||
| return_value={"result": "supplier"}).start() | ||
| self.mock_vaccine_map = patch("transform_map.transform_vaccine_map", return_value={"result": "vaccine"}).start() | ||
| self.mock_validation_rules = patch("transform_map.transform_validation_rules").start() | ||
|
|
||
| def tearDown(self): | ||
| patch.stopall() | ||
|
|
||
| def test_permissions_config_file_key_calls_supplier_permissions(self): | ||
| data = {"some": "data"} | ||
| result = transform_map(data, RedisCacheKey.PERMISSIONS_CONFIG_FILE_KEY) | ||
dlzhry2nhs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.mock_supplier_permissions.assert_called_once_with(data) | ||
| self.assertEqual(result, {"result": "supplier"}) | ||
| self.mock_logger_info.assert_any_call( | ||
| "Transforming data for file type: %s", RedisCacheKey.PERMISSIONS_CONFIG_FILE_KEY) | ||
|
|
||
| def test_disease_mapping_file_key_calls_vaccine_map(self): | ||
| data = {"other": "data"} | ||
| self.mock_validation_rules.return_value = {"validation_rules": data} | ||
| result = transform_map(data, RedisCacheKey.DISEASE_MAPPING_FILE_KEY) | ||
| self.mock_vaccine_map.assert_called_once_with(data) | ||
| self.assertEqual(result, {"result": "vaccine"}) | ||
| self.mock_logger_info.assert_any_call( | ||
| "Transforming data for file type: %s", RedisCacheKey.DISEASE_MAPPING_FILE_KEY) | ||
|
|
||
| def test_validation_rules_file_key_calls_validation_rules(self): | ||
| data = {"validation": "schema"} | ||
| self.mock_validation_rules.return_value = {"validation_rules": data} | ||
| result = transform_map(data, RedisCacheKey.VALIDATION_RULES_FILE_KEY) | ||
| self.mock_validation_rules.assert_called_once_with(data) | ||
| self.assertEqual(result, {"validation_rules": data}) | ||
| self.mock_logger_info.assert_any_call( | ||
| "Transforming data for file type: %s", RedisCacheKey.VALIDATION_RULES_FILE_KEY) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.