add unit tests for spplus module

This commit is contained in:
Benjamin Dauvergne 2012-01-31 10:59:26 +01:00
parent 40a4e5ffa1
commit 4f0def0fd3
4 changed files with 45 additions and 8 deletions

View File

@ -142,16 +142,9 @@ if __name__ == '__main__':
import sys
ntkey = '58 6d fc 9c 34 91 9b 86 3f fd 64 63 c9 13 4a 26 ba 29 74 1e c7 e9 80 79'
payment = Payment({'cle': ntkey, 'siret': '00000000000001-01'})
print payment.request(10)
if len(sys.argv) == 2:
print sign_url_paiement(ntkey, sys.argv[1])
print sign_ntkey_query(ntkey, sys.argv[1])
elif len(sys.argv) > 2:
print sign_url_paiement(sys.argv[1], sys.argv[2])
print sign_ntkey_query(sys.argv[1], sys.argv[2])
else:
tests = [('x=coin', 'c04f8266d6ae3ce37551cce996c751be4a95d10a'),
('x=coin&y=toto', 'ef008e02f8dbf5e70e83da416b0b3a345db203de')]
for query, result in tests:
assert sign_ntkey_query(ntkey, query) == result

View File

@ -6,7 +6,35 @@ Setup script for eopayment
import distutils
import distutils.core
from glob import glob
from os.path import splitext, basename, join as pjoin
import os
import re
from unittest import TextTestRunner, TestLoader
class TestCommand(distutils.core.Command):
user_options = [ ]
def initialize_options(self):
self._dir = os.getcwd()
def finalize_options(self):
pass
def run(self):
'''
Finds all the tests modules in tests/, and runs them.
'''
testfiles = [ ]
for t in glob(pjoin(self._dir, 'tests', '*.py')):
if not t.endswith('__init__.py'):
testfiles.append('.'.join(
['tests', splitext(basename(t))[0]])
)
tests = TestLoader().loadTestsFromNames(testfiles)
t = TextTestRunner(verbosity = 4)
t.run(tests)
def get_version():
text = file('eopayment/__init__.py').read()
@ -29,4 +57,5 @@ distutils.core.setup(name='eopayment',
packages=['eopayment'],
requires=[
'pycrypto (>= 2.5)'
])
],
cmdclass={'test': TestCommand})

0
tests/__init__.py Normal file
View File

15
tests/spplus.py Normal file
View File

@ -0,0 +1,15 @@
from unittest import TestCase
import eopayment.spplus as spplus
class SPPlustTest(TestCase):
ntkey = '58 6d fc 9c 34 91 9b 86 3f ' \
'fd 64 63 c9 13 4a 26 ba 29 74 1e c7 e9 80 79'
tests = [('x=coin', 'c04f8266d6ae3ce37551cce996c751be4a95d10a'),
('x=coin&y=toto', 'ef008e02f8dbf5e70e83da416b0b3a345db203de')]
def test_spplus(self):
payment = spplus.Payment({'cle': self.ntkey, 'siret': '00000000000001-01'})
for query, result in self.tests:
self.assertEqual(spplus.sign_ntkey_query(self.ntkey, query).lower(), result)