|
1 | 1 | import os |
| 2 | +import json |
2 | 3 | import unittest |
3 | 4 | from pathlib import Path |
4 | 5 | from src.validation import Validation |
@@ -75,12 +76,36 @@ def test_validate_invalid_file(self, mock_download_file, mock_clean_up): |
75 | 76 |
|
76 | 77 | # Assert that validation is marked as valid |
77 | 78 | self.assertFalse(result.is_valid) |
78 | | - self.assertIn('Validation error', ' '.join(result.validation_message)) |
| 79 | + errors = json.loads(result.validation_message) |
| 80 | + self.assertNotEqual(len(errors), 0) |
79 | 81 |
|
80 | 82 |
|
81 | 83 | # Ensure clean_up is called twice (once for the file, once for the folder) |
82 | 84 | self.assertEqual(mock_clean_up.call_count, 2) |
83 | 85 |
|
| 86 | + @patch('src.validation.Validation.clean_up') |
| 87 | + @patch('src.validation.Validation.download_single_file') |
| 88 | + def test_validate_invalid_file_with_errors(self, mock_download_file, mock_clean_up): |
| 89 | + """Test the validate method for a invalid file.""" |
| 90 | + mock_download_file.return_value = f'{SAVED_FILE_PATH}/{FAILURE_FILE_NAME}' |
| 91 | + error_in_file = 'wa.microsoft.graph.edges.OSW.geojson' |
| 92 | + feature_indexes = [3, 6, 8, 25] |
| 93 | + error_message = "Additional properties are not allowed ('crossing' was unexpected)" |
| 94 | + # Act |
| 95 | + result = self.validation.validate(max_errors=10) |
| 96 | + |
| 97 | + # Assert that validation is marked as valid |
| 98 | + self.assertFalse(result.is_valid) |
| 99 | + errors = json.loads(result.validation_message) |
| 100 | + count = 0 |
| 101 | + for error in errors: |
| 102 | + self.assertEqual(error['filename'], error_in_file) |
| 103 | + self.assertEqual(error['error_message'][0], error_message) |
| 104 | + self.assertEqual(error['feature_index'], feature_indexes[count]) |
| 105 | + count += 1 |
| 106 | + # Ensure clean_up is called twice (once for the file, once for the folder) |
| 107 | + self.assertEqual(mock_clean_up.call_count, 2) |
| 108 | + |
84 | 109 | @patch('src.validation.OSWValidation') |
85 | 110 | @patch('src.validation.Validation.clean_up') |
86 | 111 | def test_validate_invalid_zip(self, mock_clean_up, mock_osw_validation): |
|
0 commit comments