1
|
|
|
from bitpay.exceptions import * |
2
|
|
|
from bitpay.client import Client |
3
|
|
|
from httmock import urlmatch, HTTMock |
4
|
|
|
import requests |
5
|
|
|
import unittest |
6
|
|
|
|
7
|
|
|
class TestClient(unittest.TestCase): |
8
|
|
|
def test_pair_code_check(self): |
9
|
|
|
"""tests whether the pairing code is syntatically correct""" |
10
|
|
|
new_client = Client() |
11
|
|
|
with self.assertRaisesRegex(BitPayArgumentError, "pairing code is not legal"): |
12
|
|
|
new_client.pair_pos_client("abcd") |
13
|
|
|
|
14
|
|
|
def test_passes_errors_when_pairing(self): |
15
|
|
|
"""web errors should be gracefully passed to the client""" |
16
|
|
|
new_client = Client() |
17
|
|
|
def a_request(url, request): |
18
|
|
|
return {'status_code': 403, 'content': b'{"error": "this is a 403 error"}'} |
19
|
|
|
with HTTMock(a_request): |
20
|
|
|
with self.assertRaisesRegex(BitPayBitPayError, "403: this is a 403 error"): |
21
|
|
|
new_client.pair_pos_client("a1B2c3d") |
22
|
|
|
|
23
|
|
|
def test_passes_errors_when_creating_invoice(self): |
24
|
|
|
"""web errors should be gracefully passed to the client""" |
25
|
|
|
new_client = Client() |
26
|
|
|
def a_request(url, request): |
27
|
|
|
return {'status_code': 403, 'content': b'{"error": "this is a 403 error"}'} |
28
|
|
|
with HTTMock(a_request): |
29
|
|
|
with self.assertRaisesRegex(BitPayBitPayError, "403: this is a 403 error"): |
30
|
|
|
new_client.create_invoice({"price": 20, "currency": "USD"}) |
31
|
|
|
|
32
|
|
|
def test_unsigned_request_rates(self): |
33
|
|
|
"""tests whether the generic wrapper returns properly |
34
|
|
|
when asked for rates |
35
|
|
|
""" |
36
|
|
|
new_client = Client() |
37
|
|
|
request = new_client.unsigned_request('/rates/EUR') |
38
|
|
|
self.assertIn('rate', request.json()['data']) |
39
|
|
|
|