diff --git a/requirements.txt b/requirements.txt index 2235996..63a61b1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,4 @@ python-ms-core==0.0.23 uvicorn==0.20.0 html_testRunner==1.2.1 geopandas==0.14.4 -python-osw-validation==0.2.15 \ No newline at end of file +python-osw-validation==0.3.2 diff --git a/tests/unit_tests/test_config.py b/tests/unit_tests/test_config.py index 886199f..65f9bd4 100644 --- a/tests/unit_tests/test_config.py +++ b/tests/unit_tests/test_config.py @@ -2,6 +2,7 @@ import unittest from unittest.mock import patch from src.config import Settings +import importlib class TestSettings(unittest.TestCase): @@ -34,9 +35,12 @@ def test_settings_with_invalid_auth_simulate(self): settings = Settings() self.assertEqual(settings.auth_provider, 'Hosted') - @patch.dict(os.environ, {}, clear=True) + @patch.dict(os.environ, {'CONTAINER_NAME': 'osw'}, clear=True) def test_default_settings(self): - settings = Settings() + # Reload config to pick up the patched environment and bypass .env values + from src import config + importlib.reload(config) + settings = config.Settings() self.assertEqual(settings.app_name, 'python-osw-validation') self.assertEqual(settings.event_bus.container_name, 'osw') self.assertIsNone(settings.auth_permission_url) diff --git a/tests/unit_tests/test_validation.py b/tests/unit_tests/test_validation.py index aa3cbde..19f3099 100644 --- a/tests/unit_tests/test_validation.py +++ b/tests/unit_tests/test_validation.py @@ -89,20 +89,40 @@ def test_validate_invalid_file_with_errors(self, mock_download_file, mock_clean_ """Test the validate method for a invalid file.""" mock_download_file.return_value = f'{SAVED_FILE_PATH}/{FAILURE_FILE_NAME}' error_in_file = 'wa.microsoft.graph.edges.OSW.geojson' - feature_indexes = [3, 6, 8, 25] - error_message = "Additional properties are not allowed ('crossing' was unexpected)" + expected_errors = [ + { + 'feature_index': 3, + 'error_message': "Additional properties are not allowed ('crossing' was unexpected)" + }, + { + 'feature_index': 6, + 'error_message': "Additional properties are not allowed ('crossing' was unexpected)" + }, + { + 'feature_index': 8, + 'error_message': "Additional properties are not allowed ('crossing' was unexpected)" + }, + { + 'feature_index': 25, + 'error_message': "Additional properties are not allowed ('crossing' was unexpected)" + }, + { + 'feature_index': 27, + 'error_message': "Additional properties are not allowed ('crossing' was unexpected)" + } + ] # Act result = self.validation.validate(max_errors=10) # Assert that validation is marked as valid self.assertFalse(result.is_valid) errors = json.loads(result.validation_message) - count = 0 - for error in errors: + self.assertEqual(len(errors), len(expected_errors)) + + for expected, error in zip(expected_errors, errors): self.assertEqual(error['filename'], error_in_file) - self.assertEqual(error['error_message'][0], error_message) - self.assertEqual(error['feature_index'], feature_indexes[count]) - count += 1 + self.assertEqual(error['feature_index'], expected['feature_index']) + self.assertEqual(error['error_message'][0], expected['error_message']) # Ensure clean_up is called twice (once for the file, once for the folder) self.assertEqual(mock_clean_up.call_count, 2)