Exemplo n.º 1
0
    def test_validation_fails_when_one_file_has_bad_schema(self):
        bad_file_result = {
            'file': 'bad.xml',
            'results': {
                'schema': {
                    # Set the schema as NOT valid
                    'valid': False,
                    'errors': ['schema was bad']
                },
                'use_cases': {
                    DEFAULT_USE_CASE: {
                        'errors': [],
                        'warnings': [],
                    }
                }
            }
        }

        body = {
            'success':
            True,
            'validation_results': [
                {
                    'file': 'file1.xml',
                    'results': {
                        'schema': {
                            'valid': True
                        },
                        'use_cases': {
                            DEFAULT_USE_CASE: {
                                'errors': [],
                                'warnings': [],
                            }
                        }
                    }
                },
                bad_file_result,
            ]
        }

        with patch('seed.building_sync.validation_client._validation_api_post',
                   return_value=responseFactory(200, body)):
            all_files_valid, file_summaries = validate_use_case(self.zip_file)

        self.assertFalse(all_files_valid)
        bad_file_names = [f['file'] for f in file_summaries]
        self.assertEqual([bad_file_result['file']], bad_file_names)
Exemplo n.º 2
0
    def test_validation_zip_file_ok_when_warnings(self):
        good_body = {
            'success':
            True,
            'validation_results': [
                {
                    'file': 'file1.xml',
                    'results': {
                        'schema': {
                            'valid': True
                        },
                        'use_cases': {
                            DEFAULT_USE_CASE: {
                                'errors': [],
                                # Include a warning
                                'warnings': ['This is a warning!'],
                            }
                        }
                    }
                },
                {
                    'file': 'file2.xml',
                    'results': {
                        'schema': {
                            'valid': True
                        },
                        'use_cases': {
                            DEFAULT_USE_CASE: {
                                'errors': [],
                                # Include a warning
                                'warnings': ['This is another warning!'],
                            }
                        }
                    }
                }
            ]
        }

        with patch('seed.building_sync.validation_client._validation_api_post',
                   return_value=responseFactory(200, good_body)):
            all_files_valid, file_summaries = validate_use_case(self.zip_file)

        self.assertTrue(all_files_valid)
        file_names = [f['file'] for f in file_summaries]
        self.assertEqual(['file1.xml', 'file2.xml'], file_names)
Exemplo n.º 3
0
    def test_validation_zip_file_ok(self):
        good_body = {
            'success':
            True,
            'validation_results': [{
                'file': 'file1.xml',
                'results': {
                    'schema': {
                        'valid': True
                    },
                    'use_cases': {
                        DEFAULT_USE_CASE: {
                            'errors': [],
                            'warnings': [],
                        }
                    }
                }
            }, {
                'file': 'file2.xml',
                'results': {
                    'schema': {
                        'valid': True
                    },
                    'use_cases': {
                        DEFAULT_USE_CASE: {
                            'errors': [],
                            'warnings': [],
                        }
                    }
                }
            }]
        }

        with patch('seed.building_sync.validation_client._validation_api_post',
                   return_value=responseFactory(200, good_body)):
            all_files_valid, file_summaries = validate_use_case(self.zip_file)

        self.assertTrue(all_files_valid)
        self.assertEqual([], file_summaries)