11import unittest
22import jsonschema
3+ from _ucoinpy_test .api .webserver import WebFunctionalSetupMixin , web , asyncio
34from ucoinpy .api .bma .blockchain import Parameters , Block , Current , Hardship , Membership , Newcomers , \
45 Certifications , Joiners , Actives , Leavers , UD , TX
56
67
7- class Test_BMA_Blockchain (unittest .TestCase ):
8+ class Test_BMA_Blockchain (WebFunctionalSetupMixin , unittest .TestCase ):
89 def test_parameters (self ):
910 json_sample = {
1011 "currency" : "meta_brouzouf" ,
@@ -25,6 +26,22 @@ def test_parameters(self):
2526 }
2627 jsonschema .validate (json_sample , Parameters .schema )
2728
29+ def test_parameters_bad (self ):
30+ @asyncio .coroutine
31+ def handler (request ):
32+ yield from request .read ()
33+ return web .Response (body = b'{}' , content_type = 'application/json' )
34+
35+ @asyncio .coroutine
36+ def go ():
37+ _ , srv , url = yield from self .create_server ('GET' , '/' , handler )
38+ params = Parameters (None )
39+ params .reverse_url = lambda path : url
40+ with self .assertRaises (jsonschema .exceptions .ValidationError ):
41+ yield from params .get ()
42+
43+ self .loop .run_until_complete (go ())
44+
2845 def test_schema_block_0 (self ):
2946 json_sample = {
3047 "version" : 1 ,
@@ -79,6 +96,38 @@ def test_schema_block_0(self):
7996 jsonschema .validate (json_sample , Block .schema )
8097 jsonschema .validate (json_sample , Current .schema )
8198
99+ def test_block_bad (self ):
100+ @asyncio .coroutine
101+ def handler (request ):
102+ yield from request .read ()
103+ return web .Response (body = b'{}' , content_type = 'application/json' )
104+
105+ @asyncio .coroutine
106+ def go ():
107+ _ , srv , url = yield from self .create_server ('GET' , '/100' , handler )
108+ block = Block (None , 100 )
109+ block .reverse_url = lambda path : url
110+ with self .assertRaises (jsonschema .exceptions .ValidationError ):
111+ yield from block .get ()
112+
113+ self .loop .run_until_complete (go ())
114+
115+ def test_current_bad (self ):
116+ @asyncio .coroutine
117+ def handler (request ):
118+ yield from request .read ()
119+ return web .Response (body = b'{}' , content_type = 'application/json' )
120+
121+ @asyncio .coroutine
122+ def go ():
123+ _ , srv , url = yield from self .create_server ('GET' , '/' , handler )
124+ current = Current (None )
125+ current .reverse_url = lambda path : url
126+ with self .assertRaises (jsonschema .exceptions .ValidationError ):
127+ yield from current .get ()
128+
129+ self .loop .run_until_complete (go ())
130+
82131 def test_schema_block (self ):
83132 json_sample = {
84133 "version" : 1 ,
@@ -125,6 +174,22 @@ def test_schema_hardship(self):
125174 }
126175 jsonschema .validate (json_sample , Hardship .schema )
127176
177+ def test_hardship_bad (self ):
178+ @asyncio .coroutine
179+ def handler (request ):
180+ yield from request .read ()
181+ return web .Response (body = b'{}' , content_type = 'application/json' )
182+
183+ @asyncio .coroutine
184+ def go ():
185+ _ , srv , url = yield from self .create_server ('GET' , '/fingerprint' , handler )
186+ hardship = Hardship (None , "fingerprint" )
187+ hardship .reverse_url = lambda path : url
188+ with self .assertRaises (jsonschema .exceptions .ValidationError ):
189+ yield from hardship .get ()
190+
191+ self .loop .run_until_complete (go ())
192+
128193 def test_schema_membership (self ):
129194 json_sample = {
130195 "pubkey" : "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU" ,
@@ -149,6 +214,22 @@ def test_schema_membership(self):
149214 }
150215 jsonschema .validate (json_sample , Membership .schema )
151216
217+ def test_membership_bad (self ):
218+ @asyncio .coroutine
219+ def handler (request ):
220+ yield from request .read ()
221+ return web .Response (body = b'{}' , content_type = 'application/json' )
222+
223+ @asyncio .coroutine
224+ def go ():
225+ _ , srv , url = yield from self .create_server ('GET' , '/pubkey' , handler )
226+ membership = Membership (None , "pubkey" )
227+ membership .reverse_url = lambda path : url
228+ with self .assertRaises (jsonschema .exceptions .ValidationError ):
229+ yield from membership .get ()
230+
231+ self .loop .run_until_complete (go ())
232+
152233 def test_schema_newcomers (self ):
153234 json_sample = {
154235 "result" : {
@@ -157,6 +238,22 @@ def test_schema_newcomers(self):
157238 }
158239 jsonschema .validate (json_sample , Newcomers .schema )
159240
241+ def test_newcomers_bad (self ):
242+ @asyncio .coroutine
243+ def handler (request ):
244+ yield from request .read ()
245+ return web .Response (body = b'{}' , content_type = 'application/json' )
246+
247+ @asyncio .coroutine
248+ def go ():
249+ _ , srv , url = yield from self .create_server ('GET' , '/' , handler )
250+ newcomers = Newcomers (None )
251+ newcomers .reverse_url = lambda path : url
252+ with self .assertRaises (jsonschema .exceptions .ValidationError ):
253+ yield from newcomers .get ()
254+
255+ self .loop .run_until_complete (go ())
256+
160257 def test_schema_certifications (self ):
161258 json_sample = {
162259 "result" : {
@@ -165,6 +262,22 @@ def test_schema_certifications(self):
165262 }
166263 jsonschema .validate (json_sample , Certifications .schema )
167264
265+ def test_certifications_bad (self ):
266+ @asyncio .coroutine
267+ def handler (request ):
268+ yield from request .read ()
269+ return web .Response (body = b'{}' , content_type = 'application/json' )
270+
271+ @asyncio .coroutine
272+ def go ():
273+ _ , srv , url = yield from self .create_server ('GET' , '/' , handler )
274+ certs = Certifications (None )
275+ certs .reverse_url = lambda path : url
276+ with self .assertRaises (jsonschema .exceptions .ValidationError ):
277+ yield from certs .get ()
278+
279+ self .loop .run_until_complete (go ())
280+
168281 def test_schema_joiners (self ):
169282 json_sample = {
170283 "result" : {
@@ -173,6 +286,22 @@ def test_schema_joiners(self):
173286 }
174287 jsonschema .validate (json_sample , Joiners .schema )
175288
289+ def test_joiners_bad (self ):
290+ @asyncio .coroutine
291+ def handler (request ):
292+ yield from request .read ()
293+ return web .Response (body = b'{}' , content_type = 'application/json' )
294+
295+ @asyncio .coroutine
296+ def go ():
297+ _ , srv , url = yield from self .create_server ('GET' , '/' , handler )
298+ joiners = Joiners (None )
299+ joiners .reverse_url = lambda path : url
300+ with self .assertRaises (jsonschema .exceptions .ValidationError ):
301+ yield from joiners .get ()
302+
303+ self .loop .run_until_complete (go ())
304+
176305 def test_schema_actives (self ):
177306 json_sample = {
178307 "result" : {
@@ -181,6 +310,22 @@ def test_schema_actives(self):
181310 }
182311 jsonschema .validate (json_sample , Actives .schema )
183312
313+ def test_actives_bad (self ):
314+ @asyncio .coroutine
315+ def handler (request ):
316+ yield from request .read ()
317+ return web .Response (body = b'{}' , content_type = 'application/json' )
318+
319+ @asyncio .coroutine
320+ def go ():
321+ _ , srv , url = yield from self .create_server ('GET' , '/' , handler )
322+ actives = Actives (None )
323+ actives .reverse_url = lambda path : url
324+ with self .assertRaises (jsonschema .exceptions .ValidationError ):
325+ yield from actives .get ()
326+
327+ self .loop .run_until_complete (go ())
328+
184329 def test_schema_leavers (self ):
185330 json_sample = {
186331 "result" : {
@@ -189,6 +334,22 @@ def test_schema_leavers(self):
189334 }
190335 jsonschema .validate (json_sample , Leavers .schema )
191336
337+ def test_leavers_bad (self ):
338+ @asyncio .coroutine
339+ def handler (request ):
340+ yield from request .read ()
341+ return web .Response (body = b'{}' , content_type = 'application/json' )
342+
343+ @asyncio .coroutine
344+ def go ():
345+ _ , srv , url = yield from self .create_server ('GET' , '/' , handler )
346+ leavers = Leavers (None )
347+ leavers .reverse_url = lambda path : url
348+ with self .assertRaises (jsonschema .exceptions .ValidationError ):
349+ yield from leavers .get ()
350+
351+ self .loop .run_until_complete (go ())
352+
192353 def test_schema_ud (self ):
193354 json_sample = {
194355 "result" : {
@@ -197,10 +358,42 @@ def test_schema_ud(self):
197358 }
198359 jsonschema .validate (json_sample , UD .schema )
199360
361+ def test_ud_bad (self ):
362+ @asyncio .coroutine
363+ def handler (request ):
364+ yield from request .read ()
365+ return web .Response (body = b'{}' , content_type = 'application/json' )
366+
367+ @asyncio .coroutine
368+ def go ():
369+ _ , srv , url = yield from self .create_server ('GET' , '/' , handler )
370+ ud = UD (None )
371+ ud .reverse_url = lambda path : url
372+ with self .assertRaises (jsonschema .exceptions .ValidationError ):
373+ yield from ud .get ()
374+
375+ self .loop .run_until_complete (go ())
376+
200377 def test_schema_tx (self ):
201378 json_sample = {
202379 "result" : {
203380 "blocks" : [223 , 813 ]
204381 }
205382 }
206383 jsonschema .validate (json_sample , TX .schema )
384+
385+ def test_tx_bad (self ):
386+ @asyncio .coroutine
387+ def handler (request ):
388+ yield from request .read ()
389+ return web .Response (body = b'{}' , content_type = 'application/json' )
390+
391+ @asyncio .coroutine
392+ def go ():
393+ _ , srv , url = yield from self .create_server ('GET' , '/' , handler )
394+ tx = TX (None )
395+ tx .reverse_url = lambda path : url
396+ with self .assertRaises (jsonschema .exceptions .ValidationError ):
397+ yield from tx .get ()
398+
399+ self .loop .run_until_complete (go ())
0 commit comments