Commit c47a03b9 authored by Vincent Texier's avatar Vincent Texier

issue #52 reformat code in tests

parent aabed40c
Pipeline #3615 passed with stages
in 1 minute and 59 seconds
......@@ -356,7 +356,8 @@ class TestBmaBlockchain(WebFunctionalSetupMixin, unittest.TestCase):
async def go():
_, port, url = await self.create_server('GET',
'/blockchain/memberships/8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU',
'/blockchain/memberships'
'/8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU',
handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
client = Client(BMAEndpoint("127.0.0.1", "", "", port))
......
......@@ -27,6 +27,7 @@ class TestBmaApi(unittest.TestCase):
api = API(endpoint.conn_handler(session), )
self.assertEqual(api.reverse_url("http", "/test/url"), "http://test.com:9092/test/url")
await session.close()
self.loop.run_until_complete(go())
def test_reverse_url_only_ipv4(self):
......@@ -37,6 +38,7 @@ class TestBmaApi(unittest.TestCase):
api = API(endpoint.conn_handler(session), )
self.assertEqual(api.reverse_url("http", "/test/url"), "http://124.2.2.1:9092/test/url")
await session.close()
self.loop.run_until_complete(go())
def test_reverse_url_only_ipv6(self):
......@@ -47,6 +49,7 @@ class TestBmaApi(unittest.TestCase):
self.assertEqual(api.reverse_url("http", "/test/url"),
"http://[2001:0db8:0000:85a3:0000:0000:ac1f:8001]:9092/test/url")
await session.close()
self.loop.run_until_complete(go())
def test_parse_error(self):
......
'''
"""
Created on 6 déc. 2014
@author: inso
'''
"""
import unittest
from duniterpy.documents.certification import Identity, Certification, Revocation
from duniterpy.documents.block import Block, BlockUID
from duniterpy.documents.block import BlockUID
from duniterpy.constants import EMPTY_HASH
selfcert_inlines = ["HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:\
h/H8tDIEbfA4yxMQcvfOXVDQhi1sUa9qYtPKrM59Bulv97ouwbAvAsEkC1Uyit1IOpeAV+CQQs4IaAyjE8F1Cw==:\
32-DB30D958EE5CB75186972286ED3F4686B8A1C2CD:lolcat\n", "RdrHvL179Rw62UuyBrqy2M1crx7RPajaViBatS59EGS:\
Ah55O8cvdkGS4at6AGOKUjy+wrFwAq8iKRJ5xLIb6Xdi3M8WfGOUdMjwZA6GlSkdtlMgEhQPm+r2PMebxKrCBg==:\
36-1076F10A7397715D2BEE82579861999EA1F274AC:lolmouse\n" ]
36-1076F10A7397715D2BEE82579861999EA1F274AC:lolmouse\n"]
cert_inlines = [
"8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:\
"8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:\
0:TgmDuMxZdyutroj9jiLJA8tQp/389JIzDKuxW5+h7GIfjDu1ZbwI7HNm5rlUDhR2KreaV/QJjEaItT4Cf75rCQ==\n",
"9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y:8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:12:\
"9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y:8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:12:\
qn/XNJjaGIwfnR+wGrDME6YviCQbG+ywsQWnETlAsL6q7o3k1UhpR5ZTVY9dvejLKuC+1mUEXVTmH+8Ib55DBA==\n"
]
......@@ -27,20 +26,22 @@ revokation_inline = "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:\
TgmDuMxZdyutroj9jiLJA8tQp/389JIzDKuxW5+h7GIfjDu1ZbwI7HNm5rlUDhR2KreaV/QJjEaItT4Cf75rCQ==\n"
class Test_Certification(unittest.TestCase):
class TestCertification(unittest.TestCase):
def test_self_certification_from_inline(self):
version = 2
currency = "beta_brousouf"
selfcert = Identity.from_inline(version, currency, selfcert_inlines[0])
self.assertEqual(selfcert.pubkey, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk")
self.assertEqual(selfcert.signatures[0], "h/H8tDIEbfA4yxMQcvfOXVDQhi1sUa9qYtPKrM59Bulv97ouwbAvAsEkC1Uyit1IOpeAV+CQQs4IaAyjE8F1Cw==")
self.assertEqual(selfcert.signatures[0],
"h/H8tDIEbfA4yxMQcvfOXVDQhi1sUa9qYtPKrM59Bulv97ouwbAvAsEkC1Uyit1IOpeAV+CQQs4IaAyjE8F1Cw==")
self.assertEqual(str(selfcert.timestamp), "32-DB30D958EE5CB75186972286ED3F4686B8A1C2CD")
self.assertEqual(selfcert.uid, "lolcat")
selfcert = Identity.from_inline(version, currency, selfcert_inlines[1])
self.assertEqual(selfcert.pubkey, "RdrHvL179Rw62UuyBrqy2M1crx7RPajaViBatS59EGS")
self.assertEqual(selfcert.signatures[0], "Ah55O8cvdkGS4at6AGOKUjy+wrFwAq8iKRJ5xLIb6Xdi3M8WfGOUdMjwZA6GlSkdtlMgEhQPm+r2PMebxKrCBg==")
self.assertEqual(selfcert.signatures[0],
"Ah55O8cvdkGS4at6AGOKUjy+wrFwAq8iKRJ5xLIb6Xdi3M8WfGOUdMjwZA6GlSkdtlMgEhQPm+r2PMebxKrCBg==")
self.assertEqual(str(selfcert.timestamp), "36-1076F10A7397715D2BEE82579861999EA1F274AC")
self.assertEqual(selfcert.uid, "lolmouse")
......@@ -75,14 +76,16 @@ J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBf
self.assertEqual(cert.pubkey_to, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk")
self.assertEqual(cert.timestamp.number, 0)
self.assertEqual(cert.timestamp.sha_hash, EMPTY_HASH)
self.assertEqual(cert.signatures[0], "TgmDuMxZdyutroj9jiLJA8tQp/389JIzDKuxW5+h7GIfjDu1ZbwI7HNm5rlUDhR2KreaV/QJjEaItT4Cf75rCQ==")
self.assertEqual(cert.signatures[0],
"TgmDuMxZdyutroj9jiLJA8tQp/389JIzDKuxW5+h7GIfjDu1ZbwI7HNm5rlUDhR2KreaV/QJjEaItT4Cf75rCQ==")
cert = Certification.from_inline(version, currency, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD", cert_inlines[1])
self.assertEqual(cert.pubkey_from, "9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y")
self.assertEqual(cert.pubkey_to, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU")
self.assertEqual(cert.timestamp.number, 12)
self.assertEqual(cert.timestamp.sha_hash, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD")
self.assertEqual(cert.signatures[0], "qn/XNJjaGIwfnR+wGrDME6YviCQbG+ywsQWnETlAsL6q7o3k1UhpR5ZTVY9dvejLKuC+1mUEXVTmH+8Ib55DBA==")
self.assertEqual(cert.signatures[0],
"qn/XNJjaGIwfnR+wGrDME6YviCQbG+ywsQWnETlAsL6q7o3k1UhpR5ZTVY9dvejLKuC+1mUEXVTmH+8Ib55DBA==")
def test_certification_raw(self):
version = 2
......@@ -93,7 +96,7 @@ J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBf
signature = "SoKwoa8PFfCDJWZ6dNCv7XstezHcc2BbKiJgVDXv82R5zYR83nis9dShLgWJ5w48noVUHimdngzYQneNYSMV3rk"
identity = Identity(version, currency, pubkey_to, "lolcat",
BlockUID(32, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD"),
"J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBfCznzyci")
"J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBfCznzyci")
certification = Certification(version, currency, pubkey_from, identity, timestamp, signature)
......@@ -118,17 +121,17 @@ SoKwoa8PFfCDJWZ6dNCv7XstezHcc2BbKiJgVDXv82R5zYR83nis9dShLgWJ5w48noVUHimdngzYQneN
currency = "zeta_brousouf"
revokation = Revocation.from_inline(version, currency, revokation_inline)
self.assertEqual(revokation.pubkey, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU")
self.assertEqual(revokation.signatures[0], "TgmDuMxZdyutroj9jiLJA8tQp/389JIzDKuxW5+h7GIfjDu1ZbwI7HNm5rlUDhR2KreaV/QJjEaItT4Cf75rCQ==")
self.assertEqual(revokation.signatures[0],
"TgmDuMxZdyutroj9jiLJA8tQp/389JIzDKuxW5+h7GIfjDu1ZbwI7HNm5rlUDhR2KreaV/QJjEaItT4Cf75rCQ==")
def test_revokation_raw(self):
version = 2
currency = "beta_brousouf"
pubkey = "HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd"
signature = "SoKwoa8PFfCDJWZ6dNCv7XstezHcc2BbKiJgVDXv82R5zYR83nis9dShLgWJ5w48noVUHimdngzYQneNYSMV3rk"
identity = Identity(version, currency, pubkey, "lolcat",
BlockUID(32, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD"),
"J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBfCznzyci")
"J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBfCznzyci")
revokation = Revocation(version, currency, identity, signature)
result = """Version: 2
......
......@@ -2,7 +2,7 @@ import unittest
from duniterpy.documents.crc_pubkey import CRCPubkey
class Test_CRCPubkey(unittest.TestCase):
class TestCRCPubkey(unittest.TestCase):
def test_from_pubkey(self):
crc_pubkey = CRCPubkey.from_pubkey("J4c8CARmP9vAFNGtHRuzx14zvxojyRWHW2darguVqjtX")
self.assertEqual(crc_pubkey.crc, "KAv")
......@@ -22,7 +22,7 @@ dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu8
"""
class Test_Membership(unittest.TestCase):
class TestMembership(unittest.TestCase):
def test_frominline(self):
membership = Membership.from_inline(2, "zeta_brousouf", 'IN', membership_inline)
self.assertEqual(membership.issuer, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk")
......@@ -31,7 +31,8 @@ class Test_Membership(unittest.TestCase):
self.assertEqual(membership.identity_ts.number, 0)
self.assertEqual(membership.identity_ts.sha_hash, "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709")
self.assertEqual(membership.uid, "cgeek")
self.assertEqual(membership.signatures[0], "dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
self.assertEqual(membership.signatures[0],
"dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
self.assertEqual(membership.membership_type, 'IN')
def test_fromraw(self):
......@@ -42,7 +43,8 @@ class Test_Membership(unittest.TestCase):
self.assertEqual(membership.identity_ts.number, 0)
self.assertEqual(membership.identity_ts.sha_hash, "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709")
self.assertEqual(membership.uid, "cgeek")
self.assertEqual(membership.signatures[0], "dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
self.assertEqual(membership.signatures[0],
"dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
self.assertEqual(membership.membership_type, 'IN')
def test_fromraw_toraw(self):
......@@ -55,7 +57,6 @@ class Test_Membership(unittest.TestCase):
self.assertEqual(membership.identity_ts.number, 0)
self.assertEqual(membership.identity_ts.sha_hash, "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709")
self.assertEqual(from_rendered_membership.uid, "cgeek")
self.assertEqual(from_rendered_membership.signatures[0], "dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
self.assertEqual(from_rendered_membership.signatures[0],
"dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
self.assertEqual(from_rendered_membership.membership_type, 'IN')
This diff is collapsed.
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