Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_request_server_exception(self, __):
method = mock.Mock()
method_name = "methodName"
setattr(self.zeep_client.client.service, method_name, method)
message = ""
code = "soap:Server"
method.side_effect = zeep.exceptions.Fault(message, code)
with self.assertRaises(SoapServerException) as context:
request = self.create_soap_request(method_name)
self.zeep_client.request(request)
self.assertEqual(context.exception.error, "Invalid amount")
self.assertEqual(context.exception.code, 304)
'localTime': datetime.now().strftime('%H%M%S'),
'additionalData': '',
'callBackUrl': self.config['callback_url'],
'payerId': 0,
}
result = client.service.bpPayRequest(**params)
if not result:
raise TransactionError('Mellat: invalid information. %s' % result)
res = str(result).split(',')
res_code = res[0]
if int(res_code) == 0:
transaction.id = res[1]
else:
raise TransactionError('Mellat: invalid information. %s' % res_code)
except zeep_exceptions.Fault:
raise TransactionError('Mellat: invalid information.')
except zeep_exceptions.Error:
raise GatewayNetworkError
return transaction
params = {
'merchantConfigurationID': self.config['merchant_config_id'],
'encryptedRequest': self._get_encrypted_request(transaction)
}
result = client.service.RequestOperation(**params)
if not result:
raise TransactionError('AsanPardakht: invalid information.')
if result[0:1] == '0':
exploded_result = str(result).split(',') # Should have two part [XX,YY]
transaction.id = exploded_result[1]
else:
raise TransactionError('AsanPardakht: invalid information. code: %s' % str(result))
except zeep_exceptions.Fault:
raise TransactionError('AsanPardakht: invalid information.')
except zeep_exceptions.Error:
raise GatewayNetworkError
return transaction
def login(self, user, password):
"""Use IWebsessionManager to login and exit if credentials are false
:param user: username (VBOX_USER from /etc/default/virtualbox)
:param password: unix password of the supplied user on VirtualBox host
"""
try:
return self.service.IWebsessionManager_logon(user, password)
except zeep.exceptions.Fault:
raise WrongCredentialsError("Wrong credentials supplied")
'Amount': int(transaction.amount),
'CallBackUrl': self.config['callback_url'],
}
result = client.service.SalePaymentRequest(requestData=data)
token = result.Token
status = int(result.Status)
if token and status == 0:
transaction.id = str(token)
else:
raise TransactionError('Parsian: %s-%s' % (
status,
self._response_message_map[str(status)]
))
except zeep_exceptions.Fault:
raise TransactionError('Parsian: invalid information.')
except zeep_exceptions.Error:
raise GatewayNetworkError
return transaction
'merchantId': self.config['merchant'],
'invoiceNo': transaction.order_id,
'paymentId': transaction.order_id,
'specialPaymentId': transaction.order_id,
'amount': int(transaction.amount),
'description': '',
'revertURL': self.config['callback_url'],
}
result = client.service.MakeToken(**params)
token = result.token
if token:
transaction.id = token
else:
raise TransactionError('Irankish: invalid information.')
except zeep_exceptions.Fault:
raise TransactionError('Irankish: invalid information.')
except zeep_exceptions.Error:
raise GatewayNetworkError
return transaction
)
while subcode_element is not None:
subcode_value_element = subcode_element.find(
"soap-env:Value", namespaces=self.nsmap
)
subcode_qname = as_qname(
subcode_value_element.text, subcode_value_element.nsmap, None
)
subcodes.append(subcode_qname)
subcode_element = subcode_element.find(
"soap-env:Subcode", namespaces=self.nsmap
)
# TODO: We should use the fault message as defined in the wsdl.
detail_node = fault_node.find("soap-env:Detail", namespaces=self.nsmap)
raise Fault(
message=message,
code=code,
actor=None,
detail=detail_node,
subcodes=subcodes,
)
def authorize(self):
"""Send this ticket to AFIP for authorization."""
request = self.__create_request_xml()
request = self.__sign_request(request)
request = b64encode(request).decode()
client = clients.get_client("wsaa", self.owner.is_sandboxed)
try:
raw_response = client.service.loginCms(request)
except Fault as e:
if str(e) == "Certificado expirado":
raise exceptions.CertificateExpired(str(e)) from e
if str(e) == "Certificado no emitido por AC de confianza":
raise exceptions.UntrustedCertificate(str(e)) from e
raise exceptions.AuthenticationError(str(e)) from e
response = etree.fromstring(raw_response.encode("utf-8"))
self.token = response.xpath(self.TOKEN_XPATH)[0].text
self.signature = response.xpath(self.SIGN_XPATH)[0].text
self.save()
fault_node = doc.find("soap-env:Body/soap-env:Fault", namespaces=self.nsmap)
if fault_node is None:
raise Fault(
message="Unknown fault occured",
code=None,
actor=None,
detail=etree_to_string(doc),
)
def get_text(name):
child = fault_node.find(name)
if child is not None:
return child.text
raise Fault(
message=get_text("faultstring"),
code=get_text("faultcode"),
actor=get_text("faultactor"),
detail=fault_node.find("detail"),
)