1
1
import unittest
2
2
import jsonschema
3
+ from _ucoinpy_test .api .webserver import WebFunctionalSetupMixin , web , asyncio
3
4
from ucoinpy .api .bma .blockchain import Parameters , Block , Current , Hardship , Membership , Newcomers , \
4
5
Certifications , Joiners , Actives , Leavers , UD , TX
5
6
6
7
7
- class Test_BMA_Blockchain (unittest .TestCase ):
8
+ class Test_BMA_Blockchain (WebFunctionalSetupMixin , unittest .TestCase ):
8
9
def test_parameters (self ):
9
10
json_sample = {
10
11
"currency" : "meta_brouzouf" ,
@@ -25,6 +26,22 @@ def test_parameters(self):
25
26
}
26
27
jsonschema .validate (json_sample , Parameters .schema )
27
28
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
+
28
45
def test_schema_block_0 (self ):
29
46
json_sample = {
30
47
"version" : 1 ,
@@ -79,6 +96,38 @@ def test_schema_block_0(self):
79
96
jsonschema .validate (json_sample , Block .schema )
80
97
jsonschema .validate (json_sample , Current .schema )
81
98
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
+
82
131
def test_schema_block (self ):
83
132
json_sample = {
84
133
"version" : 1 ,
@@ -125,6 +174,22 @@ def test_schema_hardship(self):
125
174
}
126
175
jsonschema .validate (json_sample , Hardship .schema )
127
176
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
+
128
193
def test_schema_membership (self ):
129
194
json_sample = {
130
195
"pubkey" : "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU" ,
@@ -149,6 +214,22 @@ def test_schema_membership(self):
149
214
}
150
215
jsonschema .validate (json_sample , Membership .schema )
151
216
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
+
152
233
def test_schema_newcomers (self ):
153
234
json_sample = {
154
235
"result" : {
@@ -157,6 +238,22 @@ def test_schema_newcomers(self):
157
238
}
158
239
jsonschema .validate (json_sample , Newcomers .schema )
159
240
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
+
160
257
def test_schema_certifications (self ):
161
258
json_sample = {
162
259
"result" : {
@@ -165,6 +262,22 @@ def test_schema_certifications(self):
165
262
}
166
263
jsonschema .validate (json_sample , Certifications .schema )
167
264
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
+
168
281
def test_schema_joiners (self ):
169
282
json_sample = {
170
283
"result" : {
@@ -173,6 +286,22 @@ def test_schema_joiners(self):
173
286
}
174
287
jsonschema .validate (json_sample , Joiners .schema )
175
288
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
+
176
305
def test_schema_actives (self ):
177
306
json_sample = {
178
307
"result" : {
@@ -181,6 +310,22 @@ def test_schema_actives(self):
181
310
}
182
311
jsonschema .validate (json_sample , Actives .schema )
183
312
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
+
184
329
def test_schema_leavers (self ):
185
330
json_sample = {
186
331
"result" : {
@@ -189,6 +334,22 @@ def test_schema_leavers(self):
189
334
}
190
335
jsonschema .validate (json_sample , Leavers .schema )
191
336
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
+
192
353
def test_schema_ud (self ):
193
354
json_sample = {
194
355
"result" : {
@@ -197,10 +358,42 @@ def test_schema_ud(self):
197
358
}
198
359
jsonschema .validate (json_sample , UD .schema )
199
360
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
+
200
377
def test_schema_tx (self ):
201
378
json_sample = {
202
379
"result" : {
203
380
"blocks" : [223 , 813 ]
204
381
}
205
382
}
206
383
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