Skip to content
This repository has been archived by the owner on Dec 24, 2021. It is now read-only.

Commit

Permalink
Merge c672cf0 into 3a8bc4c
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Buedo committed Jun 24, 2019
2 parents 3a8bc4c + c672cf0 commit ebf2b7b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

1 change: 1 addition & 0 deletions .travis.yml
@@ -1,5 +1,6 @@
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
Expand Down
6 changes: 5 additions & 1 deletion examples/test_merchant_facade.py
Expand Up @@ -5,6 +5,7 @@
import requests
import json
import os.path
import sys

#API_HOST = "https://bitpay.com" #for production, live bitcoin
API_HOST = "https://test.bitpay.com" #for testing, testnet bitcoin
Expand Down Expand Up @@ -38,7 +39,10 @@ def fetch_token(facade):
pairingCode = client.create_token(facade)
print("Creating " + facade + " token.")
print("Please go to: %s/dashboard/merchant/api-tokens then enter \"%s\" then click the \"Find\" button, then click \"Approve\"" % (API_HOST, pairingCode))
input("When you've complete the above, hit enter to continue...")
if int(sys.version[0]) == 3:
input("When you've complete the above, hit enter to continue...")
else:
raw_input("When you've complete the above, hit enter to continue...")
print("token is: %s" % client.tokens[facade])
f = open(TOKEN_FILE + facade, 'w')
f.write(client.tokens[facade])
Expand Down
12 changes: 8 additions & 4 deletions examples/test_payouts.py
Expand Up @@ -5,11 +5,12 @@
import requests
import json
import os.path
import sys

#API_HOST = "https://bitpay.com" #for production, live bitcoin
API_HOST = "https://test.bitpay.com" #for testing, testnet bitcoin
KEY_FILE = "/tmp/key.priv"
TOKEN_FILE = "/tmp/token.priv"
KEY_FILE = "tmp/key.priv"
TOKEN_FILE = "tmp/token.priv"
pp = pprint.PrettyPrinter(indent=4)

# check if there is a preexisting key file
Expand Down Expand Up @@ -37,11 +38,14 @@ def fetch_token(facade):
pairingCode = client.create_token(facade)
print("Creating " + facade + " token.")
print("Please go to: %s/dashboard/merchant/api-tokens then enter \"%s\" then click the \"Find\" button, then click \"Approve\"" % (API_HOST, pairingCode))
input("When you've complete the above, hit enter to continue...")
if int(sys.version[0]) == 3:
input("When you've complete the above, hit enter to continue...")
else:
raw_input("When you've complete the above, hit enter to continue...")
print("token is: %s" % client.tokens[facade])
f = open(TOKEN_FILE + facade, 'w')
f.write(client.tokens[facade])
f.close()
f.close()

def get_from_bitpay_api(client, uri, token):
payload = "?token=%s" % token
Expand Down
25 changes: 19 additions & 6 deletions test/client_test.py
Expand Up @@ -2,31 +2,44 @@
from bitpay.client import Client
from httmock import HTTMock
import unittest
import sys

class TestClient(unittest.TestCase):
def test_pair_code_check(self):
"""tests whether the pairing code is syntatically correct"""
new_client = Client(api_uri="https://test.bitpay.com")
with self.assertRaisesRegex(BitPayArgumentError, "pairing code is not legal"):
new_client.pair_pos_client("abcd")
if int(sys.version[0]) == 3:
with self.assertRaisesRegex(BitPayArgumentError, "pairing code is not legal"):
new_client.pair_pos_client("abcd")
else:
with self.assertRaisesRegexp(BitPayArgumentError, "pairing code is not legal"):
new_client.pair_pos_client("abcd")

def test_passes_errors_when_pairing(self):
"""web errors should be gracefully passed to the client"""
new_client = Client()
def a_request(url, request):
return {'status_code': 403, 'content': b'{"error": "this is a 403 error"}'}
with HTTMock(a_request):
with self.assertRaisesRegex(BitPayBitPayError, "403: this is a 403 error"):
new_client.pair_pos_client("a1B2c3d")
if int(sys.version[0]) == 3:
with self.assertRaisesRegex(BitPayBitPayError, "403: this is a 403 error"):
new_client.pair_pos_client("a1B2c3d")
else:
with self.assertRaisesRegexp(BitPayBitPayError, "403: this is a 403 error"):
new_client.pair_pos_client("a1B2c3d")

def test_passes_errors_when_creating_invoice(self):
"""web errors should be gracefully passed to the client"""
new_client = Client()
def a_request(url, request):
return {'status_code': 403, 'content': b'{"error": "this is a 403 error"}'}
with HTTMock(a_request):
with self.assertRaisesRegex(BitPayBitPayError, "403: this is a 403 error"):
new_client.create_invoice({"price": 20, "currency": "USD"})
if int(sys.version[0]) == 3:
with self.assertRaisesRegex(BitPayBitPayError, "403: this is a 403 error"):
new_client.create_invoice({"price": 20, "currency": "USD"})
else:
with self.assertRaisesRegexp(BitPayBitPayError, "403: this is a 403 error"):
new_client.create_invoice({"price": 20, "currency": "USD"})

def test_unsigned_request_rates(self):
"""tests whether the generic wrapper returns properly
Expand Down

0 comments on commit ebf2b7b

Please sign in to comment.