Skip to content

Commit

Permalink
Change how VIES suds validation errors are handled in the test case
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphje committed Apr 8, 2016
1 parent 99b549d commit 28538ad
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tests/test_vat_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,33 @@ def test_vies_check_validator(self):
validator = VATNumberValidator(vies_check=True)

validator('DE114103379')
with self.assertRaises(ValidationError) as context_manager:
validator('DE999999999')
try:
with self.assertRaises(ValidationError) as context_manager:
validator('DE999999999')
self.assertEqual(context_manager.exception.messages, ['This VAT number does not exist.'])
except AssertionError:
# Check if the validation succeeded due to a SUDS error.
# You should be wary of skipped tests because of this, but the service may also be unavailable at the time.
if validator._wsdl_exception is not None:
print("Suds WSDL test skipped due to connection failure")
self.skipTest("Suds WSDL client failed")
self.assertEqual(context_manager.exception.messages, ['This VAT number does not exist.'])
else:
raise

def test_vies_check_validator_native(self):
validator = VATNumberValidator(vies_check=True)
validator._check_vies = validator._check_vies_native

validator('DE114103379')
with self.assertRaises(ValidationError) as context_manager:
validator('DE999999999')
try:
with self.assertRaises(ValidationError) as context_manager:
validator('DE999999999')
self.assertEqual(context_manager.exception.messages, ['This VAT number does not exist.'])
except AssertionError:
# Check if the validation succeeded due to a SUDS error.
# You should be wary of skipped tests because of this, but the service may also be unavailable at the time.
if validator._wsdl_exception is not None:
print("Native WSDL test skipped due to connection failure")
self.skipTest("Native WSDL client failed")
self.assertEqual(context_manager.exception.messages, ['This VAT number does not exist.'])
else:
raise

0 comments on commit 28538ad

Please sign in to comment.