예제 #1
0
def xtest_multiple_contacts():
  """ Handle response of multiple contacts found """
  s = Vendor.get("WhitePages", config={"api_key": "1234"})
  lookup_result = s._parse(JSON_GOOD)
  assert len(lookup_result.contacts) == 2
  assert lookup_result.contacts[0] == {"firstname": "Bob", "lastname": "Smith"}
  assert lookup_result.contacts[1] == {"firstname": "Sally", "lastname": "Jones"}
예제 #2
0
def test_multiple_contacts():
  """ Handle response of multiple contacts found """
  s = Vendor.get("pacificeast", config={"public": True, "account_id": "1234", "env": "dev"})
  lookup_result = s._parse(XML_MULTIPLE_CONTACTS)
  assert len(lookup_result.contacts) == 2
  assert lookup_result.contacts[0] == {"firstname": "Bob", "lastname": "Smith"}
  assert lookup_result.contacts[1] == {"firstname": "Sally", "lastname": "Jones"}
예제 #3
0
def get_waterfall(pce_id=None, pce_env=None, whitepages_key=None):
  """
  Create the lookup waterfall

  Args:
    None

  Returns:
    [{}]: list of dicts with keys name (str), config (dict) where
          name is the name of a Vendor provider and config is the associated configuration
  """
  waterfall = [
    #Vendor.get("mock", config={}),
    Vendor.get("PacificEast", config={"public": False, "account_id": pce_id, "env": pce_env}),
    Vendor.get("PacificEast", config={"public": True,  "account_id": pce_id, "env": pce_env}),
    Vendor.get("WhitePages",  config={"api_key": whitepages_key}),
  ]

  return waterfall
예제 #4
0
def test_rad_result():
  """ Ensure that RAD result is parsed correctly """
  s = Vendor.get("pacificeast", config={"public": True, "account_id": "1234", "env": "dev"})
  lookdown_result = s._parse_lookdown(XML_RAD_RESULT)
  assert len(lookdown_result.contacts) == 3
  assert lookdown_result.contacts[0] == XML_RAD_RESULTS[0]
  assert lookdown_result.contacts[1] == XML_RAD_RESULTS[1]
  assert lookdown_result.contacts[2] == XML_RAD_RESULTS[2]

  """
예제 #5
0
def test_config():
  """ Ensure that the config is properly parsed """

  # Create an instance of the vendor
  s = Vendor.get("pacificeast", config={"public": True, "account_id": "1234", "env": "dev"})

  with patch("vendor_pacificeast.requests.post") as mock_post:
    # Configure the mock object
    mock_post.result.status_code = 200
    mock_post.result.text = XML_NO_RESULT

    # Call lookup to ensure that the config passes properly to requests
    s.lookup("3105550000")
    assert mock_post.called
    assert mock_post.call_count == 1
    assert "<cus:accountID>1234</cus:accountID>" in mock_post.call_args[1]["data"]
예제 #6
0
def test_no_name():
  """ Handle response of address but no name """
  s = Vendor.get("WhitePages", config={"api_key": "1234"})
  lookup_result = s._parse(JSON_NO_NAME)
  assert lookup_result.success == True
  assert len(lookup_result.contacts) == 1
  assert lookup_result.contacts[0] == {
    "firstname": None, "lastname": None,
    "formatted_addr": "Mineola NY 11501",
    "address": None,
    "city": "Mineola",
    "state": "NY",
    "country": "US",
    "zip": "11501",
    "geocoded": True,
    "geo_accuracy": "PostalCode",
    "latitude": 40.7469,
    "longitude": -73.6388
  }
예제 #7
0
def test_contact_found():
  """ Handle response of contact found """
  s = Vendor.get("WhitePages", config={"api_key": "1234"})
  lookup_result = s._parse(JSON_GOOD)
  assert lookup_result.success == True
  assert len(lookup_result.contacts) == 1
  assert lookup_result.contacts[0] == {
    "firstname": None, "lastname": "Whitepages",
    "formatted_addr": "Seattle WA 98115",
    "address": None,
    "city": "Seattle",
    "state": "WA",
    "country": "US",
    "zip": "98115",
    "geocoded": True,
    "geo_accuracy": "PostalCode",
    "latitude": 47.6851,
    "longitude": -122.2926
  }
예제 #8
0
def test_best_location():
  """ Handle response of address but no name """
  s = Vendor.get("WhitePages", config={"api_key": "1234"})
  lookup_result = s._parse(JSON_BEST_LOCATION)
  assert lookup_result.success == True
  assert len(lookup_result.contacts) == 1
  log.debug(lookup_result.contacts)
  assert lookup_result.contacts[0] == {
    "firstname": "Bob", "lastname": "Bobson",
    "formatted_addr": "3434 Bubble Ct, Anytown CA 01234-4444",
    "address": "3434 Bubble Ct",
    "city": "Anytown",
    "state": "CA",
    "country": "US",
    "zip": "01234-4444",
    "geocoded": True,
    "geo_accuracy": "RoofTop",
    "latitude":24.688217,
    "longitude":-106.167145,
  }
예제 #9
0
def main():
  """
  Do it
  """

  # Parse the command line args
  parser = argparse.ArgumentParser(description="Phone Lookup")
  # What to do
  parser.add_argument("--lookup",   action="store_true", help="Perform phone lookup")
  parser.add_argument("--geocode",  action="store_true", help="Perform geocoding")
  parser.add_argument("--server",   action="store_true", help="Perform reverse address serving")

  # Server params
  parser.add_argument("--server_sid",   type=str, help="sid for server")
  parser.add_argument("--server_token", type=str, help="token for server")

  # Which geocoder to use
  parser.add_argument("--geocoder", type=str, default="mock", help="Which geocoder ('mock' or 'google')")

  # Vendor params
  parser.add_argument("--pce_id",    type=str,            help="PacificEast Account ID/Key")
  parser.add_argument("--pce_env",   type=str,            help="PacificEast environment ('dev' or 'prod')")
  parser.add_argument("--wp_key",    type=str,            help="WhitePages API Key")

  parser.add_argument("--runall",   action="store_true", help="Run all numbers without prompting")
  args = parser.parse_args()

  # Perform actions
  if not (args.lookup or args.geocode or args.server):
    log.warn("No actions specified. Use '--lookup' and/or '--geocode' or '--server' to do something.")
  elif args.server and (args.lookup or args.geocode):
    log.warn("Cannot use '--server' with '--lookup' or '--geocode'.")
  elif args.server:
    # Use normal SIGINT handling
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    # Run the server
    if args.pce_id:
      vendors = [
        Vendor.get("PacificEast", config={"public": False, "account_id": args.pce_id, "env": args.pce_env}),
      ]
    else:
      vendors = [
        Vendor.get("mock", config={}),
      ]

    # Configure and run the Pyramid app
    server.serve(vendors, sid=args.server_sid, token=args.server_token)
    
  else:
    # Load the number data and perform the lookups
    log.debug("Loading numbers.json")
    numbers = load_numbers("numbers.json")

    ############
    # Lookups
    if args.lookup:
      log.info("Performing lookups")

      # Get the waterfall
      waterfall = get_waterfall(
        pce_id=args.pce_id,
        pce_env=args.pce_env,
        whitepages_key=args.wp_key)
  
      do_lookups(numbers, waterfall, "numbers.json", runall=args.runall)

    ############
    # Geocoding
    if args.geocode:
      log.info("Performing geocoding")
      geocoder = Geocoder.get(args.geocoder, config={})
      do_geocoding(numbers, geocoder, "numbers.json", runall=args.runall)
예제 #10
0
def test_no_result():
  """ Handle response of no contacts found """
  s = Vendor.get("pacificeast", config={"public": True, "account_id": "1234", "env": "dev"})
  lookup_result = s._parse(XML_NO_RESULT)
  assert lookup_result.success == False