Commit f5b92a1b authored by Łukasz Nowak's avatar Łukasz Nowak

Initialise testing.

Cover basic _getSignature cases.
parent be898a8d
##############################################################################
#
# Copyright (c) 2002-2011 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# 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 Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
import hashlib
import DateTime
def sha1(s):
return hashlib.sha1(s).hexdigest()
class TestERP5PayzenSecurePaymentMixin(ERP5TypeTestCase):
"""
An ERP5 Payzen Secure Payment test case
"""
def getTitle(self):
return "ERP5 Payzen Secure Payment"
def getBusinessTemplateList(self):
"""
Tuple of Business Templates we need to install
"""
return ('erp5_base'
, 'erp5_secure_payment'
, 'erp5_payzen_secure_payment')
def afterSetUp(self):
self.portal = self.getPortalObject()
self.service_password = '0123456789012345'
self.service = self.portal.portal_secure_payments.newContent(
portal_type='Payzen Service',
service_password = self.service_password)
self.stepTic()
class TestERP5PayzenSecurePayment(TestERP5PayzenSecurePaymentMixin):
def test_getSignature_dict_simple(self):
self.assertEqual(
self.service._getSignature({'key': 'value'}, ['key']),
sha1('value+' + self.service_password)
)
def test_getSignature_dict_key_sort(self):
self.assertEqual(
self.service._getSignature({'key': 'value', 'key1': 'value1'}, ['key',
'key1']),
sha1('value+value1+' + self.service_password)
)
self.assertEqual(
self.service._getSignature({'key': 'value', 'key1': 'value1'}, ['key1',
'key']),
sha1('value1+value+' + self.service_password)
)
def test_getSignature_dict_date_as_DateTime(self):
now = DateTime.DateTime()
d = {'key': now}
self.assertEqual(
self.service._getSignature(d, ['key']),
sha1(now.strftime('%Y%m%d') + '+' + self.service_password)
)
# dict was updated
self.assertEqual(d['key'], now.strftime('%Y-%m-%dT%H:%M:%S'))
def test_getSignature_dict_date_as_DateTime_output_date(self):
now = DateTime.DateTime()
d = {'key': now}
self.assertEqual(
self.service._getSignature(d, ['key'], output_date_format='%Y'),
sha1(now.strftime('%Y%m%d') + '+' + self.service_password)
)
# dict was updated with passed format
self.assertEqual(d['key'], now.strftime('%Y'))
def test_getSignature_dict_date_as_DateTime_signature_format(self):
now = DateTime.DateTime()
d = {'key': now}
self.assertEqual(
self.service._getSignature(d, ['key'], signature_date_format='%Y'),
sha1(now.strftime('%Y') + '+' + self.service_password)
)
# dict was updated with passed format
self.assertEqual(d['key'], now.strftime('%Y-%m-%dT%H:%M:%S'))
def test_getSignature_dict_date_as_string(self):
now = DateTime.DateTime()
d = {'keyDaTe': now.strftime('%Y-%m-%d %H:%M:%S')}
self.assertEqual(
self.service._getSignature(d, ['keyDaTe']),
sha1(now.strftime('%Y%m%d') + '+' + self.service_password)
)
# dict was updated with passed format
self.assertEqual(d['keyDaTe'], now.strftime('%Y-%m-%dT%H:%M:%S'))
37
\ No newline at end of file
38
\ No newline at end of file
testERP5PayzenSecurePayment
\ 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