Skip to content

Commit

Permalink
Fix schemas in websockets
Browse files Browse the repository at this point in the history
  • Loading branch information
Insoleet committed Jan 29, 2016
1 parent c123d9b commit 23a08a2
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 4 deletions.
58 changes: 58 additions & 0 deletions _ucoinpy_test/api/bma/test_ws.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import unittest
from _ucoinpy_test.api.webserver import WebFunctionalSetupMixin
from ucoinpy.api.bma.ws import Block, Peer


class Test_BMA_Websocket(WebFunctionalSetupMixin, unittest.TestCase):

def test_block_014(self):
json_sample = """
{
"documentType":"block",
"version":1,
"currency":"meta_brouzouf",
"nonce":567093,
"number":49191,
"parameters":"",
"previousHash":"0000084665ABA60118B6D302C9A9BA4BCCA94852",
"previousIssuer":"HBSSmqZjT4UQKsCntTSmZbu7iRP14HYtifLE6mW1PsBD",
"issuer":"HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk",
"identities":[],"joiners":[],"actives":[],"leavers":[],"excluded":[],
"membersCount":18,
"certifications":[],
"transactions":[],
"powMin":5,
"medianTime":1454058545,
"time":1454072945,
"signature":"Bk2lo/MAVgEwCr7pEopMs9DdN3TylwPH45MZg80h/V5IsuYwcVmPOstty6Z8XXqFCSfiCuYPUS7NhxGHOcnxDw==",
"hash":"0000011D7A92E746F9B2D5B7035B98867F4A95A2",
"fork":false,
"monetaryMass":15431388469457603000,
"dividend":0,
"UDTime":1453979780,
"wrong":false
}
"""
block = Block(None)
block.parse_text(json_sample)

def test_peer(self):
json_sample = """{
"version": "1",
"currency": "beta_brouzouf",
"pubkey": "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY",
"endpoints": [
"BASIC_MERKLED_API some.dns.name 88.77.66.55 2001:0db8:0000:85a3:0000:0000:ac1f 9001",
"BASIC_MERKLED_API some.dns.name 88.77.66.55 2001:0db8:0000:85a3:0000:0000:ac1f 9002",
"OTHER_PROTOCOL 88.77.66.55 9001"
],
"signature": "42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r"
}
"""
peer = Peer(None)
data = peer.parse_text(json_sample)
self.assertEqual(data["version"], "1")
self.assertEqual(data["currency"], "beta_brouzouf")
self.assertEqual(data["pubkey"], "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY")
self.assertEqual(len(data["endpoints"]), 3)
self.assertEqual(data["signature"], "42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r")
28 changes: 24 additions & 4 deletions ucoinpy/api/bma/ws/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,37 @@ class Block(Websocket):
schema = _Block.schema

def connect(self):

r = self.connect_ws('/block')
return r


class Peer(Websocket):
"""Connect to block websocket."""
schema = _Peers.schema
schema = {
"type": "object",
"properties": {
"version": {
"type": "string"
},
"currency": {
"type": "string"
},
"pubkey": {
"type": "string"
},
"endpoints": {
"type": "array",
"items": {
"type": "string"
}
},
"signature": {
"type": "string"
}
},
"required": ["version", "currency", "pubkey", "endpoints", "signature"]
}

def connect(self):

r = self.connect_ws('/peer')
return r

0 comments on commit 23a08a2

Please sign in to comment.