'Verify that a validator function can throw an exception.'

def test_validator(self):

    validator_data = {}
    def verify_file_presence(should_exist):
        '    Verify    whether    or    not    the    stored    file,    passed    to    the    validator,    exists.    '
        self.assertEqual(should_exist, validator_data['storage'].exists(validator_data['filename']))
    def store_file_data(storage, filename):
        '    Stores    file    validator    data    for    testing    after    validation    is    complete.    '
        validator_data['storage'] = storage
        validator_data['filename'] = filename
        verify_file_presence(True)
    def exception_validator(storage, filename):
        '    Validation    test    function    that    throws    an    exception    '
        self.assertEqual('error_file.csv', os.path.basename(filename))
        with storage.open(filename, 'rU') as f:
            self.assertEqual(self.file_content, f.read())
        store_file_data(storage, filename)
        raise FileValidationException('validation    failed')
    def success_validator(storage, filename):
        '    Validation    test    function    that    is    a    no-op    '
        self.assertIn('success_file', os.path.basename(filename))
        store_file_data(storage, filename)
    with self.assertRaises(FileValidationException) as error:
        self.request.FILES = {'uploaded_file': SimpleUploadedFile('tempfile.csv', self.file_content)}
        store_uploaded_file(self.request, 'uploaded_file', ['.csv'], 'error_file', self.default_max_size, validator=exception_validator)
    self.verify_exception('validation    failed', error)
    verify_file_presence(False)
    self.request.FILES = {'uploaded_file': SimpleUploadedFile('tempfile.csv', self.file_content)}
    store_uploaded_file(self.request, 'uploaded_file', ['.csv'], 'success_file', self.default_max_size, validator=success_validator)
    verify_file_presence(True)
