diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/api.py b/tests/api.py deleted file mode 100644 index 9daf5ba..0000000 --- a/tests/api.py +++ /dev/null @@ -1,57 +0,0 @@ -import unittest -import os.path -import datetime - -from pyasn1.type import univ - -import rfc3161 - -class Rfc3161(unittest.TestCase): - - def default_test(self, tsa_server, certificate, username=None, password=None, data='xx', nonce=None, **kwargs): - kwargs.update({ - 'certificate': file(certificate).read() - }) - if username and password: - kwargs.update({ - 'username': username, - 'password': password, - }) - - timestamper = rfc3161.RemoteTimestamper(tsa_server, **kwargs) - kwargs = {} - if nonce: - kwargs['nonce'] = nonce - value, substrate = timestamper(data=data, **kwargs) - self.assertIsNot(value, False, msg=substrate) - self.assertIsInstance(rfc3161.get_timestamp(value), datetime.datetime) - self.assertNotEqual(value, None) - self.assertEqual(substrate, '') - - def test_time_certum_pl(self): - self.default_test('http://time.certum.pl', - os.path.join(os.path.dirname(__file__), - '../data/certum_certificate.crt')) - - def test_teszt_e_szigno_hu(self): - data = '{"comment": "Envoi en Commission", "to": "Benjamin Dauvergne", "filetype": "Arr\u00eat CC", "from": "Benjamin Dauvergne", "files": [{"name": "affectations_ange1d.xlsx", "digest": "ce57e4ba353107dddaab91b9ad26c0569ffe0f94", "size": 16279}]}' - self.default_test('https://teszt.e-szigno.hu:440/tsa', - username='teszt', password='teszt', - certificate=os.path.join(os.path.dirname(__file__), - '../data/e_szigno_test_tsa2.crt'), - data=data, hashname='sha256') - - def test_teszt_e_szigno_hu_with_nonce(self): - data = '{"comment": "Envoi en Commission", "to": "Benjamin Dauvergne", "filetype": "Arr\u00eat CC", "from": "Benjamin Dauvergne", "files": [{"name": "affectations_ange1d.xlsx", "digest": "ce57e4ba353107dddaab91b9ad26c0569ffe0f94", "size": 16279}]}' - self.default_test('https://teszt.e-szigno.hu:440/tsa', - username='teszt', password='teszt', - certificate=os.path.join(os.path.dirname(__file__), - '../data/e_szigno_test_tsa2.crt'), - data=data, nonce=2, hashname='sha256') - - # Fedict TSS is broken for now - # def test_fedict(self): - # url = 'http://tsa.belgium.be/connect' - # self.default_test(url, - # os.path.join(os.path.dirname(__file__), - # '../data/fedict.crt')) diff --git a/tests/test_api.py b/tests/test_api.py new file mode 100644 index 0000000..f04bf06 --- /dev/null +++ b/tests/test_api.py @@ -0,0 +1,51 @@ +import os.path +import datetime + +from pyasn1.type import univ + +import rfc3161 + + +def default_test(tsa_server, certificate, username=None, password=None, data='xx', nonce=None, **kwargs): + kwargs.update({ + 'certificate': file(certificate).read() + }) + if username and password: + kwargs.update({ + 'username': username, + 'password': password, + }) + + timestamper = rfc3161.RemoteTimestamper(tsa_server, **kwargs) + kwargs = {} + if nonce: + kwargs['nonce'] = nonce + value, substrate = timestamper(data=data, **kwargs) + assert not value is False, substrate + assert isinstance(rfc3161.get_timestamp(value), datetime.datetime) + assert not value is None + assert substrate == '' + + +def test_time_certum_pl(): + default_test('http://time.certum.pl', + os.path.join(os.path.dirname(__file__), + '../data/certum_certificate.crt')) + + +def test_teszt_e_szigno_hu(): + data = '{"comment": "Envoi en Commission", "to": "Benjamin Dauvergne", "filetype": "Arr\u00eat CC", "from": "Benjamin Dauvergne", "files": [{"name": "affectations_ange1d.xlsx", "digest": "ce57e4ba353107dddaab91b9ad26c0569ffe0f94", "size": 16279}]}' + default_test('https://teszt.e-szigno.hu:440/tsa', + username='teszt', password='teszt', + certificate=os.path.join(os.path.dirname(__file__), + '../data/e_szigno_test_tsa2.crt'), + data=data, hashname='sha256') + + +def test_teszt_e_szigno_hu_with_nonce(): + data = '{"comment": "Envoi en Commission", "to": "Benjamin Dauvergne", "filetype": "Arr\u00eat CC", "from": "Benjamin Dauvergne", "files": [{"name": "affectations_ange1d.xlsx", "digest": "ce57e4ba353107dddaab91b9ad26c0569ffe0f94", "size": 16279}]}' + default_test('https://teszt.e-szigno.hu:440/tsa', + username='teszt', password='teszt', + certificate=os.path.join(os.path.dirname(__file__), + '../data/e_szigno_test_tsa2.crt'), + data=data, nonce=2, hashname='sha256') diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..935b510 --- /dev/null +++ b/tox.ini @@ -0,0 +1,6 @@ +[testenv] +deps = + pytest-cov + pytest +commands = + py.test {posargs:tests/}