Completed
Push — master ( e0dbd4...85d261 )
by
unknown
32s
created

test.TestClient   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 24
Duplicated Lines 0 %
Metric Value
dl 0
loc 24
rs 10
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A TestClient.test_passes_errors_when_creating_invoice() 0 8 4
A TestClient.test_passes_errors_when_pairing() 0 8 4
A TestClient.a_request() 0 2 1
A TestClient.test_pair_code_check() 0 5 2
1
import sys
2
import os
3
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'bitpay')))
4
from bitpay_exceptions import *
5
from bitpay_client import Client
6
from httmock import urlmatch, HTTMock
7
import requests
8
import unittest
9
10
class TestClient(unittest.TestCase):
11
  def test_pair_code_check(self):
12
    """tests whether the pairing code is syntatically correct"""
13
    new_client = Client()
14
    with self.assertRaisesRegexp(BitPayArgumentError, "pairing code is not legal"):
15
      new_client.pair_pos_client("abcd")
16
17
  def test_passes_errors_when_pairing(self):
18
    """web errors should be gracefully passed to the client"""
19
    new_client = Client()
20
    def a_request(url, request):
21
      return {'status_code': 403, 'content': b'{"error": "this is a 403 error"}'}
22
    with HTTMock(a_request):
23
      with self.assertRaisesRegexp(BitPayBitPayError, "403: this is a 403 error"):
24
        new_client.pair_pos_client("a1B2c3d")
25
26
  def test_passes_errors_when_creating_invoice(self):
27
    """web errors should be gracefully passed to the client"""
28
    new_client = Client()
29
    def a_request(url, request):
30
      return {'status_code': 403, 'content': b'{"error": "this is a 403 error"}'}
31
    with HTTMock(a_request):
32
      with self.assertRaisesRegexp(BitPayBitPayError, "403: this is a 403 error"):
33
        new_client.create_invoice({"price": 20, "currency": "USD"})
34
35
36