def test_call_soap_method_with_object_simple(self, built): err = WebFault(Mock(response=Mock(fault=None, document=None)), None) type(err).fault = PropertyMock(return_value="fault") built.return_value.get_library_instance.return_value._client.return_value.service.action = Mock( side_effect=err) assert SOAPLibrary.call_soap_method_with_object("action", item=2) == "fault"
def test_get_change_request_by_id__faulty_request(self, mock_soap_client, fireflow_client): """Make sure that api call failure result in AlgoSecAPIError being raised""" mock_soap_client.service.getTicket.side_effect = WebFault(MagicMock(), document={}) with pytest.raises(AlgoSecAPIError): fireflow_client.get_change_request_by_id(MagicMock())
def test_initiate_client_login_error(self, mocker, fireflow_client): mock_get_soap_client = mocker.MagicMock() mock_get_soap_client.return_value.service.authenticate.side_effect = WebFault( 'Login Error', document={}) with mocker.patch.object(fireflow_client, '_get_soap_client', mock_get_soap_client): with pytest.raises(AlgoSecLoginError): fireflow_client._initiate_client()
def test_initiate_client_login_error(self, mocker, analyzer_client): mock_get_soap_client = MagicMock() mock_get_soap_client.return_value.service.connect.side_effect = WebFault( "Login Error", document={}) with mocker.patch.object(analyzer_client, "_get_soap_client", mock_get_soap_client): with pytest.raises(AlgoSecLoginError): analyzer_client._initiate_client()
def test_search_zip_code(self, mock_api_call): web_client = WebServiceClient(self.env['l10n_br.zip']) mock_api_call.side_effect = WebFault("", "") self.assertRaises(WebFault, web_client.search_zip_code, 70002900) mock_api_call.side_effect = TransportError("", "") self.assertRaises(TransportError, web_client.search_zip_code, 70002900)
def execute_soap(vim, host, moid, method, **kwargs): from suds import WebFault response = host.RetrieveManagedMethodExecuter().executeSoap(moid=moid, version=SOAP_VERSION, method=method, argument=generate_arguments(vim, **kwargs)) if response.response is None and response.fault.faultMsg is not None: fault = marshall_response(vim, response) fault.faultstring = response.faul.faultMsg raise WebFault(fault, response) return marshall_response(vim, response.response)
def get_projects_list(self): mantis_creds = self.app.config['webadmin'] client = Client("http://localhost/mantisbt/api/soap/mantisconnect.php?wsdl") try: projects = client.service.mc_projects_get_user_accessible(mantis_creds['user'], mantis_creds['password']) except WebFault: return ["An error occurred", WebFault.__repr__()] return list(map(lambda prj: Project(name=prj['name'], description=prj['description']), projects))
def get_project_list(self): try: return list( map( self.convert_soap_to_model, self.client.service.mc_projects_get_user_accessible( self.app.user, self.app.password))) except WebFault: raise WebFault( "\nThe system can not get contacts for specified user.\n")
def test_run_traffic_simulation_query__faulty_query( self, mocker, analyzer_client): mock_soap_client = MagicMock() mock_soap_client.service.query.side_effect = WebFault("Query Error", document={}) with mocker.patch.object(analyzer_client, "_client", mock_soap_client): with pytest.raises(AlgoSecAPIError): analyzer_client.run_traffic_simulation_query( MagicMock(), MagicMock(), MagicMock())
def test_raises_when_suds_WebFault(self, mock_client): """Raises an error if suds raises a WebFault""" mock_checkVat = mock_client.return_value.service.checkVat mock_checkVat.side_effect = WebFault(500, 'error') v = VATIN(VALID_VIES_COUNTRY_CODE, VALID_VIES_NUMBER) with self.assertRaises(ValueError): v.is_valid() mock_checkVat.assert_called_with(VALID_VIES_COUNTRY_CODE, VALID_VIES_NUMBER)
def parking_space_availability_atos_get_informations_test(): """ Atos validate return good stands informations or None if an error occured """ stands = Stands(5, 9) all_stands = {'1': Stands(4, 8), '2': stands} provider = AtosProvider(u'10', u'vélitul', u'https://webservice.atos.com?wsdl', {'keolis'}) provider.get_all_stands = MagicMock(return_value=all_stands) assert provider.get_informations(poi) == stands provider.get_all_stands = MagicMock( side_effect=WebFault('fake fault', 'mock')) assert provider.get_informations(poi) is None
def test_create_change_request__faulty_api_call(self, mock_soap_client, fireflow_client): """Make sure that upon api call failure, AlgoSecAPIError is raised""" mock_soap_client.service.createTicket.side_effect = WebFault( 'Query Error', document={}) with pytest.raises(AlgoSecAPIError): fireflow_client.create_change_request( subject=(MagicMock()), requestor_name=(MagicMock()), email=(MagicMock()), traffic_lines=MagicMock(), description=(MagicMock()), template=(MagicMock()), )
def detect_fault(self, body): """ Detect I{hidden} soapenv:Fault element in the soap body. @param body: The soap envelope body. @type body: L{Element} @raise WebFault: When found. """ fault = body.getChild('Fault', envns) if fault is None: return unmarshaller = self.unmarshaller(False) p = unmarshaller.process(fault) if self.options().faults: raise WebFault(p, fault) return self
def create(self, project): try: self.client.service.mc_project_add( self.app.user, self.app.password, { "name": project.name, "status": { "name": project.status }, "inherit_global": project.inherit, "view_state": { "name": project.view }, "description": project.description }) except WebFault: raise WebFault("\nThe system can not create the project.\n")
def test_raises_when_suds_web_fault(self, mock_client): """Raise an error if suds raises a WebFault.""" mock_check_vat = mock_client.return_value.service.checkVat mock_check_vat.side_effect = WebFault(500, 'error') v = VATIN(VALID_VIES_COUNTRY_CODE, VALID_VIES_NUMBER) logging.getLogger('vies').setLevel(logging.CRITICAL) with pytest.raises(WebFault): v.validate() logging.getLogger('vies').setLevel(logging.NOTSET) mock_check_vat.assert_called_with(VALID_VIES_COUNTRY_CODE, VALID_VIES_NUMBER)
def get_fault(self, reply): """ Extract the fault from the specified soap reply. If I{faults} is True, an exception is raised. Otherwise, the I{unmarshalled} fault L{Object} is returned. This method is called when the server raises a I{web fault}. @param reply: A soap reply message. @type reply: str @return: A fault object. @rtype: tuple ( L{Element}, L{Object} ) """ reply = self.replyfilter(reply) sax = Parser() faultroot = sax.parse(string=reply) soapenv = faultroot.getChild('Envelope') soapbody = soapenv.getChild('Body') fault = soapbody.getChild('Fault') unmarshaller = self.unmarshaller(False) p = unmarshaller.process(fault) if self.options().faults: raise WebFault(p, faultroot) return (faultroot, p.detail)
def test_report_soap_failure__webfault_is_fetched(self): """See that webfault is translated into AlgoSecAPIError""" with pytest.raises(AlgoSecAPIError): with report_soap_failure(AlgoSecAPIError): raise WebFault("Some Error", document={})
def raiseSaveError(self): fault = MockFault(str('200'), '202 random error') document = {} raise WebFault(fault, document)
def raiseInvalidAuth(self): fault = MockFault(str('200'), '200 is invalid auth') document = {} raise WebFault(fault, document)
def raiseZoneNotFound(self): fault = MockFault(str('102'), '102 is zone not found') document = {} raise WebFault(fault, document)
def test_make_call_connection_error(self): self.api.client.service.TestService.side_effect = WebFault('a', 'b') self.assertRaises(AuthorizeConnectionError, self.api._make_call, 'TestService', 'foo') self.assertEqual(self.api.client.service.TestService.call_args[0], (self.api.client_auth, 'foo'))
def test_call_method_raises_TableFault_for_table_fault_exception_from_service( self): self.client.service.give_me_a_table.side_effect = WebFault( Mock(faultstring='TableFault'), Mock()) with self.assertRaises(TableFault): self.interact.call('give_me_a_table', 'awesome_table')
def test_call_method_raises_ServiceError_for_unhandled_webfault(self): self.client.service.rm_rf.side_effect = WebFault(Mock(), Mock()) with self.assertRaises(ServiceError): self.interact.call('rm_rf', '/.')
def test_canntGetBugsForProject(self): jira = JiraTracker() jiraInstance = self.getMockFor(jira) jira.selectProject(["",""]) fault = Holder() fault.faultstring = "" when(jiraInstance.service).getIssuesFromJqlSearch(any(), any(), any()).thenRaise(WebFault(fault, None)) self.assertRaises(StopIteration, next, jira._getItems())
def test_call_method_raises_ApiLimitError_for_rate_limit_exception_from_service( self): self.client.service.rm_rf.side_effect = WebFault( Mock(faultstring='API_LIMIT_EXCEEDED'), Mock()) with self.assertRaises(ApiLimitError): self.interact.call('rm_rf', '/.')
def test_call_method_raises_ListFault_for_list_fault_exception_from_service( self): self.client.service.list_thing.side_effect = WebFault( Mock(faultstring='ListFault'), Mock()) with self.assertRaises(ListFault): self.interact.call('list_thing')