Commit 70c8cda5 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_payzen: Dont include testing data

   It is more accurate to include testing data via test (on setup), otherwise it can lead to enable undesired configurations and eventually include testing data in production.

   If required, use a separated bt5 for include specific testing data.
parent 6b41fe8f
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Payzen Service" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_count</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_mt_index</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>_tree</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>PSERV-Payzen-Test</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_payzen_test</string> </value>
</item>
<item>
<key> <string>payzen_vads_action_mode</string> </key>
<value> <string>INTERACTIVE</string> </value>
</item>
<item>
<key> <string>payzen_vads_ctx_mode</string> </key>
<value> <string>TEST</string> </value>
</item>
<item>
<key> <string>payzen_vads_page_action</string> </key>
<value> <string>PAYMENT</string> </value>
</item>
<item>
<key> <string>payzen_vads_version</string> </key>
<value> <string>V2</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Payzen Service</string> </value>
</item>
<item>
<key> <string>service_password</string> </key>
<value> <string>bar</string> </value>
</item>
<item>
<key> <string>service_username</string> </key>
<value> <string>foo</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>PayZen</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Length" module="BTrees.Length"/>
</pickle>
<pickle> <int>0</int> </pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Link" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>default_link</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Link</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>url_string</string> </key>
<value> <string>https://secure.payzen.eu/vads-payment/</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Link" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>wsdl_link</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Link</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>url_string</string> </key>
<value> <string>https://secure.payzen.eu/vads-ws/v3?wsdl</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -99,7 +99,7 @@ class Foo:
def updateStatus(self):
pass
return Foo()
""" )
""")
self.commit()
def _dropPaymentTransaction_createPayzenEvent(self):
......
......@@ -19,11 +19,26 @@
#
##############################################################################
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixinWithAbort
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixinWithAbort, \
SlapOSTestCaseMixin, simulate
from DateTime import DateTime
from zExceptions import Unauthorized
from Products.ERP5Type.tests.utils import createZODBPythonScript
class PayzenServiceTestCase(SlapOSTestCaseMixin):
def afterSetUp(self):
SlapOSTestCaseMixin.afterSetUp(self)
self.payzen_secure_payment = self.portal.portal_secure_payments.newContent(
portal_type="Payzen Service",
reference="PSERV-Payzen-Test"
)
self.tic()
def beforeTearDown(self):
SlapOSTestCaseMixin.beforeTearDown(self)
self.portal.portal_secure_payments.manage_delObjects(
ids=[self.payzen_secure_payment.getId()])
self.tic()
class TestSlapOSCurrency_getIntegrationMapping(SlapOSTestCaseMixinWithAbort):
......@@ -161,7 +176,7 @@ class TestSlapOSPaymentTransaction_generatePayzenId(SlapOSTestCaseMixinWithAbort
REQUEST={})
class TestSlapOSPaymentTransaction_createPayzenEvent(SlapOSTestCaseMixinWithAbort):
class TestSlapOSPaymentTransaction_createPayzenEvent(PayzenServiceTestCase):
def test_createPayzenEvent_REQUEST_disallowed(self):
payment_transaction = self.createPaymentTransaction()
......@@ -171,24 +186,21 @@ class TestSlapOSPaymentTransaction_createPayzenEvent(SlapOSTestCaseMixinWithAbor
REQUEST={})
def test_createPayzenEvent_newPayment(self):
self.portal.portal_secure_payments.slapos_payzen_test.setReference("PSERV-Payzen-Test")
self.tic()
payment_transaction = self.createPaymentTransaction()
payzen_event = payment_transaction.PaymentTransaction_createPayzenEvent()
self.assertEqual(payzen_event.getPortalType(), "Payzen Event")
self.assertEqual(payzen_event.getSource(),
"portal_secure_payments/slapos_payzen_test")
self.assertEqual(payzen_event.getDestination(), payment_transaction.getRelativeUrl())
self.payzen_secure_payment.getRelativeUrl())
self.assertEqual(payzen_event.getDestination(),
payment_transaction.getRelativeUrl())
def test_createPayzenEvent_kwParameter(self):
self.portal.portal_secure_payments.slapos_payzen_test.setReference("PSERV-Payzen-Test")
self.tic()
payment_transaction = self.createPaymentTransaction()
payzen_event = payment_transaction.PaymentTransaction_createPayzenEvent(
title='foo')
self.assertEqual(payzen_event.getPortalType(), "Payzen Event")
self.assertEqual(payzen_event.getSource(),
"portal_secure_payments/slapos_payzen_test")
self.payzen_secure_payment.getRelativeUrl())
self.assertEqual(payzen_event.getDestination(), payment_transaction.getRelativeUrl())
self.assertEqual(payzen_event.getTitle(), "foo")
......@@ -226,7 +238,7 @@ class TestSlapOSPayzenEvent_processUpdate(SlapOSTestCaseMixinWithAbort):
data_kw = {
'status': 'ERROR',
'answer':{
'answer': {
'errorCode': "foo",
},
}
......@@ -552,32 +564,8 @@ class TestSlapOSPayzenEvent_processUpdate(SlapOSTestCaseMixinWithAbort):
'Automatic acknowledge as result of correct communication',
event.workflow_history['system_event_workflow'][-1]['comment'])
def _simulatePaymentTransaction_getRecentPayzenId(self):
script_name = 'PaymentTransaction_getPayzenId'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""return DateTime().toZone('UTC'), 'foo'""")
def _simulatePaymentTransaction_getOldPayzenId(self):
script_name = 'PaymentTransaction_getPayzenId'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""from erp5.component.module.DateUtils import addToDate
return addToDate(DateTime(), to_add={'day': -1, 'second': -1}).toZone('UTC'), 'foo'""")
def _dropPaymentTransaction_getPayzenId(self):
script_name = 'PaymentTransaction_getPayzenId'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
@simulate("PaymentTransaction_getPayzenId", '*args, **kwargs',
"""return DateTime().toZone('UTC'), 'foo'""")
def test_processUpdate_recentNotFoundOnPayzenSide(self):
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
......@@ -589,12 +577,7 @@ return addToDate(DateTime(), to_add={'day': -1, 'second': -1}).toZone('UTC'), 'f
"errorCode": "PSP_010",
},
}
self._simulatePaymentTransaction_getRecentPayzenId()
try:
event.PayzenEvent_processUpdate(data_kw)
finally:
self._dropPaymentTransaction_getPayzenId()
self.assertEqual(event.getValidationState(), "acknowledged")
self.assertEqual(
......@@ -605,6 +588,9 @@ return addToDate(DateTime(), to_add={'day': -1, 'second': -1}).toZone('UTC'), 'f
'Error code PSP_010 (Not found) did not changed the document state.',
payment.workflow_history['edit_workflow'][-1]['comment'])
@simulate("PaymentTransaction_getPayzenId", '*args, **kwargs',
"""from erp5.component.module.DateUtils import addToDate
return addToDate(DateTime(), to_add={'day': -1, 'second': -1}).toZone('UTC'), 'foo'""")
def test_processUpdate_oldNotFoundOnPayzenSide(self):
"""
This Test is supposed to Fail as for now we do not want to cancel automatically
......@@ -619,12 +605,7 @@ return addToDate(DateTime(), to_add={'day': -1, 'second': -1}).toZone('UTC'), 'f
"errorCode": "PSP_010",
},
}
self._simulatePaymentTransaction_getOldPayzenId()
try:
event.PayzenEvent_processUpdate(data_kw)
finally:
self._dropPaymentTransaction_getPayzenId()
self.assertEqual(event.getValidationState(), "acknowledged")
self.assertEqual(
......@@ -662,7 +643,7 @@ return addToDate(DateTime(), to_add={'day': -1, 'second': -1}).toZone('UTC'), 'f
'Aborting refused payzen payment.',
payment.workflow_history['accounting_workflow'][-1]['comment'])
class TestSlapOSPayzenBase_getPayzenServiceRelativeUrl(SlapOSTestCaseMixinWithAbort):
class TestSlapOSPayzenBase_getPayzenServiceRelativeUrl(PayzenServiceTestCase):
def test_getPayzenServiceRelativeUrl_REQUEST_disallowed(self):
self.assertRaises(
......@@ -671,30 +652,21 @@ class TestSlapOSPayzenBase_getPayzenServiceRelativeUrl(SlapOSTestCaseMixinWithAb
REQUEST={})
def test_getPayzenServiceRelativeUrl_default_result(self):
self.portal.portal_secure_payments.slapos_payzen_test.setReference("PSERV-Payzen-Test")
self.tic()
result = self.portal.Base_getPayzenServiceRelativeUrl()
self.assertEqual(result, 'portal_secure_payments/slapos_payzen_test')
self.assertEqual(result, self.payzen_secure_payment.getRelativeUrl())
def test_getPayzenServiceRelativeUrl_not_found(self):
self.portal.portal_secure_payments.slapos_payzen_test.setReference("disabled")
self.payzen_secure_payment.setReference("disabled")
self.tic()
result = self.portal.Base_getPayzenServiceRelativeUrl()
self.assertEqual(result, None)
class TestSlapOSPayzenPaymentTransaction_redirectToManualPayzenPayment(
SlapOSTestCaseMixinWithAbort):
def _simulatePaymentTransaction_getVADSUrlDict(self):
script_name = 'PaymentTransaction_getVADSUrlDict'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""payment_transaction_url = context.getRelativeUrl()
PayzenServiceTestCase):
@simulate("PaymentTransaction_getVADSUrlDict", '*args, **kwargs',
"""payment_transaction_url = context.getRelativeUrl()
return dict(vads_url_already_registered="%s/already_registered" % (payment_transaction_url),
vads_url_cancel="%s/cancel" % (payment_transaction_url),
vads_url_error="%s/error" % (payment_transaction_url),
......@@ -703,25 +675,36 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans
vads_url_success="%s/success" % (payment_transaction_url),
vads_url_return="%s/return" % (payment_transaction_url),
)""")
def _dropPaymentTransaction_getVADSUrlDict(self):
script_name = 'PaymentTransaction_getVADSUrlDict'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
def test_PaymentTransaction_redirectToManualPayzenPayment_unauthorzied(self):
payment = self.createPaymentTransaction()
self._simulatePaymentTransaction_getVADSUrlDict()
self.logout()
try:
self.assertRaises(Unauthorized, payment.PaymentTransaction_redirectToManualPayzenPayment)
finally:
self.login()
self._dropPaymentTransaction_getVADSUrlDict()
@simulate("PaymentTransaction_getVADSUrlDict", '*args, **kwargs',
"""payment_transaction_url = context.getRelativeUrl()
return dict(vads_url_already_registered="%s/already_registered" % (payment_transaction_url),
vads_url_cancel="%s/cancel" % (payment_transaction_url),
vads_url_error="%s/error" % (payment_transaction_url),
vads_url_referral="%s/referral" % (payment_transaction_url),
vads_url_refused="%s/refused" % (payment_transaction_url),
vads_url_success="%s/success" % (payment_transaction_url),
vads_url_return="%s/return" % (payment_transaction_url),
)""")
def test_PaymentTransaction_redirectToManualPayzenPayment_redirect(self):
self.portal.portal_secure_payments.slapos_payzen_test.setReference("PSERV-Payzen-Test")
# Ensure secure payment is consistent
self.payzen_secure_payment.edit(
payzen_vads_action_mode='INTERACTIVE',
payzen_vads_ctx_mode='TEST',
payzen_vads_page_action='PAYMENT',
payzen_vads_version='V2',
link_url_string="https://secure.payzen.eu/vads-payment/",
service_api_key="A",
service_password="B",
service_username="C"
)
self.tic()
project = self.addProject()
person = self.makePerson(project)
invoice = self.createStoppedSaleInvoiceTransaction(
......@@ -744,11 +727,7 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans
self.tic()
self.login(person.getUserId())
self._simulatePaymentTransaction_getVADSUrlDict()
try:
text_content = payment.PaymentTransaction_redirectToManualPayzenPayment()
finally:
self._dropPaymentTransaction_getVADSUrlDict()
payment_transaction_url = payment.getRelativeUrl()
for item in ["vads_site_id",
......@@ -778,6 +757,16 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans
self.assertEqual(
len(system_event_list[0].contentValues(portal_type="Payzen Event Message")), 1)
@simulate("PaymentTransaction_getVADSUrlDict", '*args, **kwargs',
"""payment_transaction_url = context.getRelativeUrl()
return dict(vads_url_already_registered="%s/already_registered" % (payment_transaction_url),
vads_url_cancel="%s/cancel" % (payment_transaction_url),
vads_url_error="%s/error" % (payment_transaction_url),
vads_url_referral="%s/referral" % (payment_transaction_url),
vads_url_refused="%s/refused" % (payment_transaction_url),
vads_url_success="%s/success" % (payment_transaction_url),
vads_url_return="%s/return" % (payment_transaction_url),
)""")
def test_PaymentTransaction_redirectToManualPayzenPayment_already_registered(self):
project = self.addProject()
person = self.makePerson(project)
......@@ -802,11 +791,7 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans
payment.PaymentTransaction_generatePayzenId()
self.tic()
self.login(person.getUserId())
self._simulatePaymentTransaction_getVADSUrlDict()
try:
redirect = payment.PaymentTransaction_redirectToManualPayzenPayment()
finally:
self._dropPaymentTransaction_getVADSUrlDict()
self.assertEqual("%s/already_registered" % payment.getRelativeUrl(),
redirect)
......
# Copyright (c) 2002-2012 Nexedi SA and Contributors. All Rights Reserved.
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixinWithAbort
# -*- coding:utf-8 -*-
##############################################################################
#
# Copyright (c) 2022 Nexedi SA and Contributors. All Rights Reserved.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixinWithAbort, \
simulate
import lxml.html
from DateTime import DateTime
from Products.ERP5Type.tests.utils import createZODBPythonScript
import difflib
HARDCODED_PRICE = -99.6
......@@ -17,6 +36,21 @@ vads_url_return = 'http://example.org/return'
class TestSlapOSPayzenInterfaceWorkflow(SlapOSTestCaseMixinWithAbort):
def createPayzenService(self):
self.payzen_secure_payment = self.portal.portal_secure_payments.newContent(
portal_type="Payzen Service",
reference="PSERV-Payzen-Test"
)
self.tic()
def beforeTearDown(self):
SlapOSTestCaseMixinWithAbort.beforeTearDown(self)
if getattr(self, "payzen_secure_payment", None):
self.portal.portal_secure_payments.manage_delObjects(
ids=[self.payzen_secure_payment.getId()])
self.tic()
slapos_payzen_html = '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
......@@ -26,6 +60,8 @@ class TestSlapOSPayzenInterfaceWorkflow(SlapOSTestCaseMixinWithAbort):
<title>title</title>
</head>
<body onload="document.payment.submit();">
<center><h2>Redirecting to payment processor...</h2></center>
<p></p><center><img src="ERP5VCS_imgs/wait.gif"></img></center>
<form action="%(action)s" id="payment" method="POST" name="payment">
<input name="signature" type="hidden" value="%(signature)s"></input>
......@@ -94,21 +130,6 @@ class TestSlapOSPayzenInterfaceWorkflow(SlapOSTestCaseMixinWithAbort):
</body>
</html>'''
def _simulatePaymentTransaction_getTotalPayablePrice(self):
script_name = 'PaymentTransaction_getTotalPayablePrice'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\nreturn %f' % HARDCODED_PRICE)
def _dropPaymentTransaction_getTotalPayablePrice(self):
script_name = 'PaymentTransaction_getTotalPayablePrice'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
def test_generateManualPaymentPage_mandatoryParameters(self):
event = self.createPayzenEvent()
# vads_url_cancel
......@@ -175,7 +196,7 @@ class TestSlapOSPayzenInterfaceWorkflow(SlapOSTestCaseMixinWithAbort):
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
event.edit(destination_value=payment)
_ , _ = payment.PaymentTransaction_generatePayzenId()
payment.PaymentTransaction_generatePayzenId()
self.assertRaises(ValueError, event.generateManualPaymentPage,
vads_url_cancel=vads_url_cancel,
vads_url_error=vads_url_error,
......@@ -199,11 +220,12 @@ class TestSlapOSPayzenInterfaceWorkflow(SlapOSTestCaseMixinWithAbort):
)
def test_generateManualPaymentPage_noCurrency(self):
self.createPayzenService()
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
event.edit(
destination_value=payment,
source="portal_secure_payments/slapos_payzen_test",
source=self.payzen_secure_payment.getRelativeUrl(),
)
self.assertRaises(AttributeError, event.generateManualPaymentPage,
vads_url_cancel=vads_url_cancel,
......@@ -214,7 +236,21 @@ class TestSlapOSPayzenInterfaceWorkflow(SlapOSTestCaseMixinWithAbort):
vads_url_return=vads_url_return,
)
@simulate("PaymentTransaction_getTotalPayablePrice", '*args, **kwargs',
'# Script body\nreturn %f' % HARDCODED_PRICE)
def test_generateManualPaymentPage_defaultUseCase(self):
self.createPayzenService()
self.payzen_secure_payment.edit(
payzen_vads_action_mode='INTERACTIVE',
payzen_vads_ctx_mode='TEST',
payzen_vads_page_action='PAYMENT',
payzen_vads_version='V2',
link_url_string="https://secure.payzen.eu/vads-payment/",
service_api_key="A",
service_password="B",
service_username="C"
)
self.tic()
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
payment.edit(
......@@ -222,12 +258,10 @@ class TestSlapOSPayzenInterfaceWorkflow(SlapOSTestCaseMixinWithAbort):
)
event.edit(
destination_value=payment,
source="portal_secure_payments/slapos_payzen_test",
source=self.payzen_secure_payment.getRelativeUrl(),
)
before_date = DateTime()
self._simulatePaymentTransaction_getTotalPayablePrice()
try:
event.generateManualPaymentPage(
vads_url_cancel=vads_url_cancel,
vads_url_error=vads_url_error,
......@@ -236,8 +270,6 @@ class TestSlapOSPayzenInterfaceWorkflow(SlapOSTestCaseMixinWithAbort):
vads_url_success=vads_url_success,
vads_url_return=vads_url_return,
)
finally:
self._dropPaymentTransaction_getTotalPayablePrice()
after_date = DateTime()
# Payment start date is modified
......@@ -271,7 +303,8 @@ class TestSlapOSPayzenInterfaceWorkflow(SlapOSTestCaseMixinWithAbort):
'vads_site_id': 'foo',
}
# Calculate the signature...
self.portal.portal_secure_payments.slapos_payzen_test._getFieldList(data_dict)
self.payzen_secure_payment._getFieldList(data_dict)
data_dict['action'] = 'https://secure.payzen.eu/vads-payment/'
if getattr(self, "custom_slapos_payzen_html", None):
......@@ -314,45 +347,30 @@ class TestSlapOSPayzenInterfaceWorkflow(SlapOSTestCaseMixinWithAbort):
event.edit(
destination_value=payment,
)
_ , _ = payment.PaymentTransaction_generatePayzenId()
payment.PaymentTransaction_generatePayzenId()
self.assertRaises(AttributeError, event.updateStatus)
def mockRestGetInfo(self, method_to_call, expected_args, result_tuple):
payment_service = self.portal.portal_secure_payments.slapos_payzen_test
def mockrest_getInfo(arg1, arg2):
self.assertEqual(arg1, expected_args[0])
self.assertEqual(arg2, expected_args[1])
return result_tuple
setattr(payment_service, 'rest_getInfo', mockrest_getInfo)
setattr(self.payzen_secure_payment, 'rest_getInfo', mockrest_getInfo)
try:
return method_to_call()
finally:
del payment_service.rest_getInfo
def _simulatePayzenEvent_processUpdate(self):
script_name = 'PayzenEvent_processUpdate'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by PayzenEvent_processUpdate') """ )
self.commit()
def _dropPayzenEvent_processUpdate(self):
script_name = 'PayzenEvent_processUpdate'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
self.commit()
del self.payzen_secure_payment.rest_getInfo
@simulate("PayzenEvent_processUpdate", '*args, **kwargs',
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by PayzenEvent_processUpdate') """)
def test_updateStatus_defaultUseCase(self):
self.createPayzenService()
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
event.edit(
destination_value=payment,
source="portal_secure_payments/slapos_payzen_test",
source_value=self.payzen_secure_payment,
)
transaction_date, transaction_id = \
payment.PaymentTransaction_generatePayzenId()
......@@ -361,8 +379,6 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P
mocked_sent_text = 'mocked_sent_text'
mocked_received_text = 'mocked_received_text'
self._simulatePayzenEvent_processUpdate()
try:
self.mockRestGetInfo(
event.updateStatus,
(transaction_date.toZone('UTC').asdatetime(),
......@@ -370,8 +386,6 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P
.asdatetime().strftime('%Y%m%d'), transaction_id)),
(mocked_data_kw, mocked_sent_text, mocked_received_text),
)
finally:
self._dropPayzenEvent_processUpdate()
event_message_list = event.contentValues(portal_type="Payzen Event Message")
self.assertEqual(len(event_message_list), 2)
......
......@@ -4,6 +4,4 @@ portal_integrations/slapos_payzen_test_integration/Causality
portal_integrations/slapos_payzen_test_integration/Resource
portal_integrations/slapos_payzen_test_integration/Resource/**
portal_integrations/slapos_payzen_test_integration/SourceProject
portal_secure_payments/slapos_payzen_test
portal_secure_payments/slapos_payzen_test/**
sale_trade_condition_module/slapos_manual_accounting_trade_condition
\ No newline at end of file
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