Skip to content

Commit

Permalink
Add test for exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosgoce committed Jan 5, 2018
1 parent e55a8fa commit 0952a12
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/test_aeat.py
Expand Up @@ -4,7 +4,7 @@

from tests import factories
from zeep import xsd

from zeep import exceptions as zeep_exceptions
from aeat import Config, Controller, wsdl


Expand Down Expand Up @@ -123,3 +123,24 @@ def response():

msg = 'Validation error. CC315A,DatOfPreMES9: Element too long (length constraint)'
assert msg == result.error


@pytest.mark.parametrize('detail,exception_cls', [
('Unknown AEAT error', zeep_exceptions.XMLSyntaxError),
('Validation error', zeep_exceptions.ValidationError),
('Unknown error', Exception),
])
@patch('aeat.Controller.operation', new_callable=PropertyMock)
def test_controller_operation_request_exception_handling(operation_patch, detail, exception_cls):
def operation(arg, Signature):
raise exception_cls

operation_patch.return_value = operation

config = Mock(signed=True)
ctrl = Controller(Mock(), config)

result = ctrl.request({'arg': 'x'})

assert not result.valid
assert detail == result.error

0 comments on commit 0952a12

Please sign in to comment.