diff --git a/eopayment/spplus.py b/eopayment/spplus.py index 6cce5d9..43ebc78 100644 --- a/eopayment/spplus.py +++ b/eopayment/spplus.py @@ -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 diff --git a/setup.py b/setup.py index 4ff3468..d4c21aa 100644 --- a/setup.py +++ b/setup.py @@ -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}) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/spplus.py b/tests/spplus.py new file mode 100644 index 0000000..d28f2da --- /dev/null +++ b/tests/spplus.py @@ -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)