From 23a08a2a347c6531f02845b63b21dd26cf852b67 Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Fri, 29 Jan 2016 19:05:51 +0100
Subject: [PATCH] Fix schemas in websockets

---
 _ucoinpy_test/api/bma/test_ws.py | 58 ++++++++++++++++++++++++++++++++
 ucoinpy/api/bma/ws/__init__.py   | 28 ++++++++++++---
 2 files changed, 82 insertions(+), 4 deletions(-)
 create mode 100644 _ucoinpy_test/api/bma/test_ws.py

diff --git a/_ucoinpy_test/api/bma/test_ws.py b/_ucoinpy_test/api/bma/test_ws.py
new file mode 100644
index 00000000..2a0a6483
--- /dev/null
+++ b/_ucoinpy_test/api/bma/test_ws.py
@@ -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")
diff --git a/ucoinpy/api/bma/ws/__init__.py b/ucoinpy/api/bma/ws/__init__.py
index 8aaeab65..a932fd67 100644
--- a/ucoinpy/api/bma/ws/__init__.py
+++ b/ucoinpy/api/bma/ws/__init__.py
@@ -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
-
-- 
GitLab