Example #1
0
def client_from_stored_values():
  for f in ["local.pem", "tokens.json"]:
    try:
      open("temp/" + f)
      exists = True
    except:
      exists = False
      break
  if exists:
    f = open("temp/local.pem", 'r')
    pem = f.read()
    f = open("temp/tokens.json", 'r')
    token = f.read()
    token = json.loads(token)
    client = Client(api_uri=ROOT_ADDRESS, insecure=True, pem=pem, tokens=token)
  else:
    claim_code = get_claim_code_from_server()
    pem = key_utils.generate_pem()
    client = Client(api_uri=ROOT_ADDRESS, insecure=True, pem=pem)
    token = json.dumps(client.pair_pos_client(claim_code))
    if not os.path.exists("temp"):
      os.makedirs("temp")
    f = open("temp/local.pem", 'w')
    f.write(pem)
    f = open("temp/tokens.json", 'w')
    f.write(token)
  return client
Example #2
0
def client_from_stored_values():
    for f in ["local.pem", "tokens.json"]:
        try:
            open("temp/" + f)
            exists = True
        except:
            exists = False
            break
    if exists:
        f = open("temp/local.pem", 'r')
        pem = f.read()
        f = open("temp/tokens.json", 'r')
        token = f.read()
        token = json.loads(token)
        client = Client(api_uri=ROOT_ADDRESS,
                        insecure=True,
                        pem=pem,
                        tokens=token)
    else:
        claim_code = get_claim_code_from_server()
        pem = key_utils.generate_pem()
        client = Client(api_uri=ROOT_ADDRESS, insecure=True, pem=pem)
        token = json.dumps(client.pair_pos_client(claim_code))
        if not os.path.exists("temp"):
            os.makedirs("temp")
        f = open("temp/local.pem", 'w')
        f.write(pem)
        f = open("temp/tokens.json", 'w')
        f.write(token)
    return client
Example #3
0
 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.assertRaisesRegexp(BitPayBitPayError, "403: this is a 403 error"):
       new_client.create_invoice({"price": 20, "currency": "USD"})
Example #4
0
 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.assertRaisesRegexp(BitPayBitPayError, "403: this is a 403 error"):
       new_client.pair_pos_client("a1B2c3d")
Example #5
0
def step_impl(context):
  global pairing_code
  time.sleep(1)
  client = Client(api_uri=ROOT_ADDRESS, insecure=True, pem=PEM)
  try:
    pairing_code = client.create_token("merchant")
  except Exception as error:
    if error.args[0] == "500: Unable to create token because of too many requests.":
      time.sleep(60)
      pairing_code = client.create_token("merchant")
Example #6
0
def step_impl(context):
    global pairing_code
    time.sleep(1)
    client = Client(api_uri=ROOT_ADDRESS, insecure=True, pem=PEM)
    try:
        pairing_code = client.create_token("merchant")
    except Exception as error:
        if error.args[
                0] == "500: Unable to create token because of too many requests.":
            time.sleep(60)
            pairing_code = client.create_token("merchant")
Example #7
0
def step_impl(context):
  time.sleep(1)
  claim_code = get_claim_code_from_server()
  global client
  client = Client(api_uri=ROOT_ADDRESS, insecure=True, pem=PEM)
  try: 
    client.pair_pos_client(claim_code)
  except Exception as error:
    if error.args[0] == "500: Unable to create token because of too many requests.":
      time.sleep(60)
      client.pair_pos_client(claim_code)
  assert client.tokens['pos']
Example #8
0
    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.assertRaisesRegexp(BitPayBitPayError,
                                         "403: this is a 403 error"):
                new_client.create_invoice({"price": 20, "currency": "USD"})
Example #9
0
    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.assertRaisesRegexp(BitPayBitPayError,
                                         "403: this is a 403 error"):
                new_client.pair_pos_client("a1B2c3d")
Example #10
0
def step_impl(context):
    time.sleep(1)
    claim_code = get_claim_code_from_server()
    global client
    client = Client(api_uri=ROOT_ADDRESS, insecure=True, pem=PEM)
    try:
        client.pair_pos_client(claim_code)
    except Exception as error:
        if error.args[
                0] == "500: Unable to create token because of too many requests.":
            time.sleep(60)
            client.pair_pos_client(claim_code)
    assert client.tokens['pos']
Example #11
0
 def test_pair_code_check(self):
   """tests whether the pairing code is syntatically correct"""
   new_client = Client()
   with self.assertRaisesRegexp(BitPayArgumentError, "pairing code is not legal"):
     new_client.pair_pos_client("abcd")
Example #12
0
 def test_pair_code_check(self):
     """tests whether the pairing code is syntatically correct"""
     new_client = Client()
     with self.assertRaisesRegexp(BitPayArgumentError,
                                  "pairing code is not legal"):
         new_client.pair_pos_client("abcd")
Example #13
0
sys.path.append(
    os.path.abspath(
        os.path.join(os.path.dirname(__file__), '..', '..', 'bitpay')))
from splinter import Browser
import time
import six
import json
from bitpay_client import Client
import bitpay_key_utils as key_utils
import re

ROOT_ADDRESS = os.environ['RCROOTADDRESS']
USER_NAME = os.environ['RCTESTUSER']
PASSWORD = os.environ['RCTESTPASSWORD']
PEM = '-----BEGIN EC PRIVATE KEY-----\nMHQCAQEEICg7E4NN53YkaWuAwpoqjfAofjzKI7Jq1f532dX+0O6QoAcGBSuBBAAK\noUQDQgAEjZcNa6Kdz6GQwXcUD9iJ+t1tJZCx7hpqBuJV2/IrQBfue8jh8H7Q/4vX\nfAArmNMaGotTpjdnymWlMfszzXJhlw==\n-----END EC PRIVATE KEY-----\n'
client = Client()
invoice = None
exception = None


@given(u'the user pairs with BitPay with a valid pairing code')
def step_impl(context):
    time.sleep(1)
    claim_code = get_claim_code_from_server()
    global client
    client = Client(api_uri=ROOT_ADDRESS, insecure=True, pem=PEM)
    try:
        client.pair_pos_client(claim_code)
    except Exception as error:
        if error.args[
                0] == "500: Unable to create token because of too many requests.":