Commit f1d9c0ca authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_wechat: Fixup Tests.

parent 5eeadcf7
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
# #
############################################################################## ##############################################################################
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixinWithAbort from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixinWithAbort
from erp5.component.document.WechatService import WechatService
from DateTime import DateTime from DateTime import DateTime
from zExceptions import Unauthorized from zExceptions import Unauthorized
...@@ -660,24 +662,31 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans ...@@ -660,24 +662,31 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans
self.tic() self.tic()
payment = invoice.SaleInvoiceTransaction_getWechatPaymentRelatedValue() payment = invoice.SaleInvoiceTransaction_getWechatPaymentRelatedValue()
payment.setResourceValue(self.portal.currency_module.EUR) payment.setResourceValue(self.portal.currency_module.EUR)
payment_transaction_id = payment.getId()
self.tic() self.tic()
self.login(person.getUserId()) self.login(person.getUserId())
self._simulatePaymentTransaction_getVADSUrlDict() self._simulatePaymentTransaction_getVADSUrlDict()
try: try:
def mock_absolute_url(): def mock_absolute_url():
return "http://example.org" return "http://example.org"
def callFakeWechatApi(self, URL, wechat_dict):
return {"result_code": 'SUCCESS', "code_url": 'weixin://wxpay/bizpayurl?pr=AAAAA' }
original_method = self.portal.absolute_url original_method = self.portal.absolute_url
original_callWechatApi = WechatService.callWechatApi
self.portal.absolute_url = mock_absolute_url self.portal.absolute_url = mock_absolute_url
WechatService.callWechatApi = callFakeWechatApi
try: try:
redirected_url = payment.PaymentTransaction_redirectToManualWechatPayment() redirected_url = payment.PaymentTransaction_redirectToManualWechatPayment()
finally: finally:
self.portal.absolute_url = original_method self.portal.absolute_url = original_method
WechatService.callWechatApi = original_callWechatApi
finally: finally:
self._dropPaymentTransaction_getVADSUrlDict() self._dropPaymentTransaction_getVADSUrlDict()
self.assertEqual(payment.PaymentTransaction_getTotalPayablePrice(), 0)
payment_transaction_id = payment.getId() expected = "http://example.org/#wechat_payment?trade_no=%s&price=0&payment_url=weixin://wxpay/bizpayurl?pr=" % payment_transaction_id
expected = "http://example.org/#wechat_payment?trade_no=%s&price=1&payment_url=weixin://wxpay/bizpayurl?pr=" % payment_transaction_id
self.assertTrue(redirected_url.startswith(expected), self.assertTrue(redirected_url.startswith(expected),
"%s do not start with %s" % (redirected_url, expected)) "%s do not start with %s" % (redirected_url, expected))
transaction.abort() transaction.abort()
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
# #
############################################################################## ##############################################################################
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixinWithAbort from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixinWithAbort
from erp5.component.document.WechatService import WechatService
from DateTime import DateTime from DateTime import DateTime
from Products.ERP5Type.tests.utils import createZODBPythonScript from Products.ERP5Type.tests.utils import createZODBPythonScript
...@@ -35,7 +37,7 @@ class TestSlapOSWechatInterfaceWorkflow(SlapOSTestCaseMixinWithAbort): ...@@ -35,7 +37,7 @@ class TestSlapOSWechatInterfaceWorkflow(SlapOSTestCaseMixinWithAbort):
createZODBPythonScript(self.portal.portal_skins.custom, createZODBPythonScript(self.portal.portal_skins.custom,
script_name, script_name,
'*args, **kwargs', '*args, **kwargs',
'# Script body\nreturn %f' % HARDCODED_PRICE) '# Script body\nreturn -%f' % HARDCODED_PRICE)
def _dropPaymentTransaction_getTotalPayablePrice(self): def _dropPaymentTransaction_getTotalPayablePrice(self):
script_name = 'PaymentTransaction_getTotalPayablePrice' script_name = 'PaymentTransaction_getTotalPayablePrice'
...@@ -89,12 +91,19 @@ class TestSlapOSWechatInterfaceWorkflow(SlapOSTestCaseMixinWithAbort): ...@@ -89,12 +91,19 @@ class TestSlapOSWechatInterfaceWorkflow(SlapOSTestCaseMixinWithAbort):
try: try:
def mock_absolute_url(): def mock_absolute_url():
return "http://example.org" return "http://example.org"
def callFakeWechatApi(self, URL, wechat_dict):
return {"result_code": 'SUCCESS', "code_url": 'weixin://wxpay/bizpayurl?pr=AAAAA' }
original_method = self.portal.absolute_url original_method = self.portal.absolute_url
original_callWechatApi = WechatService.callWechatApi
self.portal.absolute_url = mock_absolute_url self.portal.absolute_url = mock_absolute_url
WechatService.callWechatApi = callFakeWechatApi
try: try:
event.generateManualPaymentPage() event.generateManualPaymentPage()
finally: finally:
self.portal.absolute_url = original_method self.portal.absolute_url = original_method
WechatService.callWechatApi = original_callWechatApi
finally: finally:
self._dropPaymentTransaction_getTotalPayablePrice() self._dropPaymentTransaction_getTotalPayablePrice()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment