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")
def step_impl(context):
  badAddress = ROOT_ADDRESS.split(":")
  badAddress = badAddress[0] + ":" + badAddress[1] + ":999"
  newclient = Client(api_uri=badAddress, insecure=True)
  try:
    newclient.pair_pos_client("1a2C3d4")
    raise "That should totally not have worked"
  except Exception as error:
    global exception
    exception = error
Exemple #3
0
def step_impl(context):
    badAddress = ROOT_ADDRESS.split(":")
    badAddress = badAddress[0] + ":" + badAddress[1] + ":999"
    newclient = Client(api_uri=badAddress, insecure=True)
    try:
        newclient.pair_pos_client("1a2C3d4")
        raise "That should totally not have worked"
    except Exception as error:
        global exception
        exception = error
def step_impl(context):
  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']
 def test_pair_code_check(self):
     """tests whether the pairing code is syntatically correct"""
     new_client = Client(api_uri="https://test.bitpay.com")
     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")
Exemple #6
0
def step_impl(context):
    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']
Exemple #7
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.assertRaisesRegex(BitPayBitPayError,
                                        "403: this is a 403 error"):
                new_client.pair_pos_client("a1B2c3d")
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
Exemple #9
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
Exemple #10
0
 def test_pair_code_check(self):
     """tests whether the pairing code is syntatically correct"""
     new_client = Client()
     with self.assertRaisesRegex(BitPayArgumentError,
                                 "pairing code is not legal"):
         new_client.pair_pos_client("abcd")
 def test_pair_code_check(self):
   """tests whether the pairing code is syntatically correct"""
   new_client = Client()
   with self.assertRaisesRegex(BitPayArgumentError, "pairing code is not legal"):
     new_client.pair_pos_client("abcd")