Skip to content

Commit

Permalink
pep8. fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
toutpt committed Jan 22, 2013
1 parent c048c42 commit 18b1973
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -3,7 +3,7 @@ python: 2.7
env:
- TARGET=test
- TARGET=coverage.sh
# - TARGET=python-validation.sh
- TARGET=python-validation.sh

# - TARGET=css-validation.sh
# - TARGET=js-validation.sh
Expand Down
32 changes: 25 additions & 7 deletions collective/cmcicpaiement/retour.py
Expand Up @@ -57,12 +57,14 @@ def update(self):
if registry:
self._settings = registry.forInterface(settings.Settings)
if self.portal_state is None:
self.portal_state = component.getMultiAdapter((self.context,
self.request),
name="plone_portal_state")
self.portal_state = component.getMultiAdapter(
(self.context, self.request),
name="plone_portal_state"
)
if self.portal_membership is None:
self.portal_membership = getToolByName(self.context,
'portal_membership')
self.portal_membership = getToolByName(
self.context, 'portal_membership'
)

#update oTpe
self._oTpe._sCle = self._settings.security_key
Expand All @@ -76,13 +78,29 @@ def update(self):
oTpe = self._oTpe
oHmac = sceau.CMCIC_Hmac(oTpe)

Certification = {'MAC': "", 'date': "", 'montant': "", 'reference': "", 'texte-libre': "", 'code-retour': "", 'cvx': "", 'vld': "", 'brand': "", 'status3ds': "", 'numauto': "", 'motifrefus': "", 'originecb': "", 'bincb': "", 'hpancb': "", 'ipclient': "", 'originetr': "", 'veres': "", 'pares': "", 'montantech': ""}
Certification = {
'MAC': "", 'date': "", 'montant': "", 'reference': "",
'texte-libre': "", 'code-retour': "", 'cvx': "", 'vld': "",
'brand': "", 'status3ds': "", 'numauto': "", 'motifrefus': "",
'originecb': "", 'bincb': "", 'hpancb': "", 'ipclient': "",
'originetr': "", 'veres': "", 'pares': "", 'montantech': ""
}

for key in Certification.keys():
if key in params: # .has_key(key):
Certification[key] = params[key] # value

sChaineMAC = oTpe.sNumero + "*" + Certification["date"] + "*" + Certification['montant'] + "*" + Certification['reference'] + "*" + Certification['texte-libre'] + "*" + oTpe.sVersion + "*" + Certification['code-retour'] + "*" + Certification['cvx'] + "*" + Certification['vld'] + "*" + Certification['brand'] + "*" + Certification['status3ds'] + "*" + Certification['numauto'] + "*" + Certification['motifrefus'] + "*" + Certification['originecb'] + "*" + Certification['bincb'] + "*" + Certification['hpancb'] + "*" + Certification['ipclient'] + "*" + Certification['originetr'] + "*" + Certification['veres'] + "*" + Certification['pares'] + "*"
sChaineMAC = oTpe.sNumero + "*" + Certification["date"] + "*" +\
Certification['montant'] + "*" + Certification['reference'] +\
"*" + Certification['texte-libre'] + "*" + oTpe.sVersion + "*" +\
Certification['code-retour'] + "*" + Certification['cvx'] + "*" +\
Certification['vld'] + "*" + Certification['brand'] + "*" +\
Certification['status3ds'] + "*" + Certification['numauto'] +\
"*" + Certification['motifrefus'] + "*" +\
Certification['originecb'] + "*" + Certification['bincb'] + "*" +\
Certification['hpancb'] + "*" + Certification['ipclient'] + "*" +\
Certification['originetr'] + "*" + Certification['veres'] + "*" +\
Certification['pares'] + "*"

self._sceau_validated = oHmac.bIsValidHmac(
sChaineMAC,
Expand Down
36 changes: 24 additions & 12 deletions collective/cmcicpaiement/tests/test_sceau.py
Expand Up @@ -2,27 +2,39 @@
from collective.cmcicpaiement.tests import base, utils


class TestMAC(base.UnitTestCase):
class TestCMCIC_Hmac(base.UnitTestCase):
"""We tests the setup (install) of the addons. You should check all
stuff in profile are well activated (browserlayer, js, content types, ...)
"""

def setUp(self):
super(TestMAC, self).setUp()
super(TestCMCIC_Hmac, self).setUp()
from collective.cmcicpaiement import sceau

self.mac = sceau.MAC()
self.oTpe = sceau.CMCIC_Tpe()
self.mac = sceau.CMCIC_Hmac(self.oTpe)
self.settings = utils.EnvSettings()
self.mac.set_key(self.settings.security_key)
self.oTpe._sCle = self.settings.security_key
self.oTpe.sCodeSociete = self.settings.societe

def test_getUsableKey(self):
self.assertEqual(
self.mac._getUsableKey(self.oTpe),
'\xbe\xbd#\x81":K\xdd,v{?\x87\xe0\xb1\\CL"{'
)

def test_format_data(self):
pass
# TODO: add tests

def test_computeHMACSHA1(self):
pass

def test_hmac_sha1(self):
pass

def test_update(self):
self.assertTrue(self.mac._wrapped is not None)
self.mac.update()
self.assertEqual(self.mac._key, self.settings.security_key)
def test_bIsValidHmac(self):
pass

def test_set_key(self):
self.mac.set_key('key1')
self.assertEqual(self.mac._key, 'key1')

def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)
2 changes: 1 addition & 1 deletion collective/cmcicpaiement/tests/test_setup.py
Expand Up @@ -32,4 +32,4 @@ def test_uninstall_browserlayer(self):


def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)
return unittest.defaultTestLoader.loadTestsFromName(__name__)
5 changes: 4 additions & 1 deletion collective/cmcicpaiement/tests/utils.py
Expand Up @@ -4,7 +4,10 @@

class EnvSettings(object):
def __init__(self):
self.security_key = os.getenv('CMCIC_SECURITY_KEY', '')
self.security_key = os.getenv(
'CMCIC_SECURITY_KEY',
'BEBD2381223A4BDD2C767B3F87E0B15C434C227B'
)
self.TPE = os.getenv('CMCIC_TPE')
self.societe = os.getenv('CMCIC_SOCIETE')
self.bank = os.getenv(
Expand Down

0 comments on commit 18b1973

Please sign in to comment.