Skip to content

Commit

Permalink
Version 0.14
Browse files Browse the repository at this point in the history
 - Handle websockets
 - Write BlockId object in documents
  • Loading branch information
Insoleet committed Jan 28, 2016
2 parents 6f9d7fa + f990f34 commit c123d9b
Show file tree
Hide file tree
Showing 21 changed files with 207 additions and 134 deletions.
72 changes: 36 additions & 36 deletions _ucoinpy_test/api/bma/test_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def test_parameters(self):
jsonschema.validate(json_sample, Parameters.schema)

def test_parameters_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/', handler)
params = Parameters(None)
params.reverse_url = lambda path: url
params.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await params.get()

Expand Down Expand Up @@ -95,28 +95,28 @@ def test_schema_block_0(self):
jsonschema.validate(json_sample, Current.schema)

def test_block_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/100', handler)
block = Block(None, 100)
block.reverse_url = lambda path: url
block.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await block.get()

self.loop.run_until_complete(go())

def test_current_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/', handler)
current = Current(None)
current.reverse_url = lambda path: url
current.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await current.get()

Expand Down Expand Up @@ -169,14 +169,14 @@ def test_schema_hardship(self):
jsonschema.validate(json_sample, Hardship.schema)

def test_hardship_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/fingerprint', handler)
hardship = Hardship(None, "fingerprint")
hardship.reverse_url = lambda path: url
hardship.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await hardship.get()

Expand Down Expand Up @@ -207,14 +207,14 @@ def test_schema_membership(self):
jsonschema.validate(json_sample, Membership.schema)

def test_membership_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/pubkey', handler)
membership = Membership(None, "pubkey")
membership.reverse_url = lambda path: url
membership.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await membership.get()

Expand All @@ -229,14 +229,14 @@ def test_schema_newcomers(self):
jsonschema.validate(json_sample, Newcomers.schema)

def test_newcomers_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/', handler)
newcomers = Newcomers(None)
newcomers.reverse_url = lambda path: url
newcomers.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await newcomers.get()

Expand All @@ -251,14 +251,14 @@ def test_schema_certifications(self):
jsonschema.validate(json_sample, Certifications.schema)

def test_certifications_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/', handler)
certs = Certifications(None)
certs.reverse_url = lambda path: url
certs.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await certs.get()

Expand All @@ -273,14 +273,14 @@ def test_schema_joiners(self):
jsonschema.validate(json_sample, Joiners.schema)

def test_joiners_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/', handler)
joiners = Joiners(None)
joiners.reverse_url = lambda path: url
joiners.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await joiners.get()

Expand All @@ -295,14 +295,14 @@ def test_schema_actives(self):
jsonschema.validate(json_sample, Actives.schema)

def test_actives_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/', handler)
actives = Actives(None)
actives.reverse_url = lambda path: url
actives.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await actives.get()

Expand All @@ -317,14 +317,14 @@ def test_schema_leavers(self):
jsonschema.validate(json_sample, Leavers.schema)

def test_leavers_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/', handler)
leavers = Leavers(None)
leavers.reverse_url = lambda path: url
leavers.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await leavers.get()

Expand All @@ -339,14 +339,14 @@ def test_schema_ud(self):
jsonschema.validate(json_sample, UD.schema)

def test_ud_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/', handler)
ud = UD(None)
ud.reverse_url = lambda path: url
ud.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await ud.get()

Expand All @@ -361,14 +361,14 @@ def test_schema_tx(self):
jsonschema.validate(json_sample, TX.schema)

def test_tx_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/', handler)
tx = TX(None)
tx.reverse_url = lambda path: url
tx.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await tx.get()

Expand Down
18 changes: 9 additions & 9 deletions _ucoinpy_test/api/bma/test_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,28 @@ def test_bma_tx_history(self):
jsonschema.validate(json_sample, Blocks.schema)

def test_bma_tx_history_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/pubkey', handler)
history = History(None, 'pubkey')
history.reverse_url = lambda path: url
history.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await history.get()

self.loop.run_until_complete(go())

def test_bma_tx_history_blocks_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/pubkey/0/100', handler)
blocks = Blocks(None, 'pubkey', 0, 100)
blocks.reverse_url = lambda path: url
blocks.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await blocks.get()

Expand Down Expand Up @@ -172,14 +172,14 @@ def test_bma_tx_sources(self):
jsonschema.validate(json_sample, Sources.schema)

def test_bma_tx_sources_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/pubkey', handler)
sources = Sources(None, 'pubkey')
sources.reverse_url = lambda path: url
sources.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await sources.get()

Expand Down
30 changes: 15 additions & 15 deletions _ucoinpy_test/api/bma/test_wot.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ def test_bma_wot_lookup(self):
jsonschema.validate(json_sample, Lookup.schema)

def test_bma_wot_lookup_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/pubkey', handler)
lookup = Lookup(None, "pubkey")
lookup.reverse_url = lambda path: url
lookup.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await lookup.get()

Expand All @@ -94,14 +94,14 @@ def test_bma_wot_members(self):
jsonschema.validate(Members.schema, json_sample)

def test_bma_wot_members_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/', handler)
members = Members(None)
members.reverse_url = lambda path: url
members.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await members.get()

Expand Down Expand Up @@ -144,21 +144,21 @@ def test_bma_wot_cert(self):
jsonschema.validate(json_sample, CertifiedBy.schema)

def test_bma_wot_certifiers_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/pubkey', handler)
certsof = CertifiersOf(None, 'pubkey')
certsof.reverse_url = lambda path: url
certsof.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await certsof.get()

self.loop.run_until_complete(go())

def test_bma_wot_certifiers_inner_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=bytes(json.dumps({
"pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
Expand All @@ -180,24 +180,24 @@ async def handler(request):
]
}), "utf-8"), content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/pubkey', handler)
certsof = CertifiersOf(None, 'pubkey')
certsof.reverse_url = lambda path: url
certsof.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await certsof.get()

self.loop.run_until_complete(go())

def test_bma_wot_certified_bad(self):
async def handler(request):
async def handler(request):
await request.read()
return web.Response(body=b'{}', content_type='application/json')

async def go():
async def go():
_, srv, url = await self.create_server('GET', '/pubkey', handler)
certby = CertifiedBy(None, 'pubkey')
certby.reverse_url = lambda path: url
certby.reverse_url = lambda scheme, path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
await certby.get()

Expand Down
6 changes: 3 additions & 3 deletions _ucoinpy_test/api/test_bma.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ class Test_BMA_API(unittest.TestCase):
def test_reverse_url_complete(self):
endpoint = BMAEndpoint("test.com", "124.2.2.1", "2001:0db8:0000:85a3:0000:0000:ac1f:8001 ", 9092)
api = API(endpoint.conn_handler(), "any")
self.assertEqual(api.reverse_url("/test/url"), "http://test.com:9092/any/test/url")
self.assertEqual(api.reverse_url("http", "/test/url"), "http://test.com:9092/any/test/url")

def test_reverse_url_only_ipv4(self):
endpoint = BMAEndpoint(None, "124.2.2.1", None, 9092)
api = API(endpoint.conn_handler(), "any")
self.assertEqual(api.reverse_url("/test/url"), "http://124.2.2.1:9092/any/test/url")
self.assertEqual(api.reverse_url("http", "/test/url"), "http://124.2.2.1:9092/any/test/url")

def test_reverse_url_only_ipv6(self):
endpoint = BMAEndpoint(None, None, "2001:0db8:0000:85a3:0000:0000:ac1f:8001", 9092)
api = API(endpoint.conn_handler(), "any")
self.assertEqual(api.reverse_url("/test/url"), "http://2001:0db8:0000:85a3:0000:0000:ac1f:8001:9092/any/test/url")
self.assertEqual(api.reverse_url("http", "/test/url"), "http://2001:0db8:0000:85a3:0000:0000:ac1f:8001:9092/any/test/url")
8 changes: 4 additions & 4 deletions _ucoinpy_test/documents/test_certification.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ def test_certifications(self):
cert = Certification.from_inline(version, currency, blockhash, cert_inlines[0])
self.assertEqual(cert.pubkey_from, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU")
self.assertEqual(cert.pubkey_to, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk")
self.assertEqual(cert.blocknumber, 0)
self.assertEqual(cert.blockhash, blockhash)
self.assertEqual(cert.blockid.number, 0)
self.assertEqual(cert.blockid.sha_hash, blockhash)
self.assertEqual(cert.signatures[0], "TgmDuMxZdyutroj9jiLJA8tQp/389JIzDKuxW5+h7GIfjDu1ZbwI7HNm5rlUDhR2KreaV/QJjEaItT4Cf75rCQ==")

cert = Certification.from_inline(version, currency, blockhash, cert_inlines[1])
self.assertEqual(cert.pubkey_from, "9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y")
self.assertEqual(cert.pubkey_to, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU")
self.assertEqual(cert.blocknumber, 0)
self.assertEqual(cert.blockhash, blockhash)
self.assertEqual(cert.blockid.number, 0)
self.assertEqual(cert.blockid.sha_hash, blockhash)
self.assertEqual(cert.signatures[0], "qn/XNJjaGIwfnR+wGrDME6YviCQbG+ywsQWnETlAsL6q7o3k1UhpR5ZTVY9dvejLKuC+1mUEXVTmH+8Ib55DBA==")
Loading

0 comments on commit c123d9b

Please sign in to comment.