def test_itemToLocation(): location = Location( '171a0329-f8b2-499c-867d-1942384ddd5f', '0.0.0.0', 'US', 'California', 'Westlake Village', 34.141944, -118.819444, None, '-08:00', [ 'cpe-75-82-84-171.socal.res.rr.com', '75-140-17-78.static.rvsd.ca.charter.com' ], { 'asn': 20001, 'name': 'Charter Communications (20001)', 'route': '75.82.0.0/15', 'domain': 'https://www.spectrum.com', 'type': 'Cable/DSL/ISP' }, 'Charter Communications', False, False, False) newLocation = itemToLocation(location.toItem()) assert location.id == newLocation.id assert location.ip == newLocation.ip assert location.country == newLocation.country assert location.region == newLocation.region assert location.city == newLocation.city assert location.latitude == newLocation.latitude assert location.longitude == newLocation.longitude assert location.postalCode == newLocation.postalCode assert location.timeZone == newLocation.timeZone assert location.domains == newLocation.domains assert location.autonomousSystem == newLocation.autonomousSystem assert location.isp == newLocation.isp assert location.proxy == newLocation.proxy assert location.vpn == newLocation.vpn assert location.tor == newLocation.tor
def test_pk(): location = Location( '0.0.0.0', 'US', 'California', 'Westlake Village', 34.141944, -118.819444, '91361', '-08:00', ['cpe-75-82-84-171.socal.res.rr.com'], { 'asn': 20001, 'name': 'Charter Communications (20001)', 'route': '75.82.0.0/15', 'domain': 'https://www.spectrum.com', 'type': 'Cable/DSL/ISP' }, 'Charter Communications', False, False, False ) assert location.pk() == { 'S': 'VISITOR#0.0.0.0' }
def locations(): '''Properly formatted locations.''' return [ Location( visitor_id, '0.0.0.0', 'US', 'California', 'Stockton', 37.9577, -121.29078, '95201', '-08:00', ['c-73-66-102-206.hsd1.ca.comcast.net'], { 'asn': 7922, 'name': 'Comcast', 'route': '73.0.0.0/8', 'type': 'Cable/DSL/ISP', 'domain': 'https://corporate.comcast.com/' }, 'Comcast Cable Communications, LLC', False, False, False, '2020-12-29T17:40:00.144Z'), Location( '171a0329-f8b2-499c-867d-1942384ddd5r', '0.0.0.1', 'US', 'California', 'San Francisco', 37.77493, -122.41942, '94102', '-08:00', ['c-73-222-141-27.hsd1.ca.comcast.net'], { 'asn': 7922, 'name': 'Comcast', 'route': '73.0.0.0/8', 'type': 'Cable/DSL/ISP', 'domain': 'https://corporate.comcast.com/' }, 'Comcast Cable Communications, Inc.', False, False, False, '2020-12-29T17:40:00.144Z'), Location( '171a0329-f8b2-499c-867d-1942384ddd5a', '0.0.0.2', 'US', 'Washington', 'Redmond', 47.67399, -122.12151, '98052', '-08:00', None, { 'asn': 3598, 'name': 'MICROSOFT-CORP-AS', 'route': '131.107.0.0/16', 'type': None, 'domain': None }, 'Microsoft Corporation', False, False, False, '2020-12-29T17:40:00.144Z'), Location( '171a0329-f8b2-499c-867d-1942384ddd5e', '0.0.0.3', 'US', 'California', 'North Cucamonga', 34.09334, -117.58172, None, '-08:00', [ '075-140-017-078.biz.spectrum.com', '75-140-17-78.static.rvsd.ca.charter.com' ], { 'asn': 20115, 'name': 'Charter Communications', 'route': '75.140.0.0/19', 'type': 'Cable/DSL/ISP', 'domain': 'https://www.spectrum.com' }, 'Charter Communications', False, False, False, '2020-12-29T07:23:37.952Z') ]
def test_init(): currentTime = datetime.datetime.now() location = Location( '171a0329-f8b2-499c-867d-1942384ddd5f', '0.0.0.0', 'US', 'California', 'Westlake Village', 34.141944, -118.819444, '91361', '-08:00', ['cpe-75-82-84-171.socal.res.rr.com'], { 'asn': 20001, 'name': 'Charter Communications (20001)', 'route': '75.82.0.0/15', 'domain': 'https://www.spectrum.com', 'type': 'Cable/DSL/ISP' }, 'Charter Communications', False, False, False, currentTime) assert location.id == '171a0329-f8b2-499c-867d-1942384ddd5f' assert location.ip == '0.0.0.0' assert location.country == 'US' assert location.region == 'California' assert location.city == 'Westlake Village' assert location.latitude == 34.141944 assert location.longitude == -118.819444 assert location.postalCode == '91361' assert location.timeZone == '-08:00' assert location.domains == ['cpe-75-82-84-171.socal.res.rr.com'] assert location.autonomousSystem == { 'asn': 20001, 'name': 'Charter Communications (20001)', 'route': '75.82.0.0/15', 'domain': 'https://www.spectrum.com', 'type': 'Cable/DSL/ISP' } assert location.isp == 'Charter Communications' assert not location.proxy assert not location.vpn assert not location.tor assert location.dateAdded == currentTime
def test_dict(): currentTime = datetime.datetime.now() location = Location( '0.0.0.0', 'US', 'California', 'Westlake Village', 34.141944, -118.819444, '91361', '-08:00', ['cpe-75-82-84-171.socal.res.rr.com'], { 'asn': 20001, 'name': 'Charter Communications (20001)', 'route': '75.82.0.0/15', 'domain': 'https://www.spectrum.com', 'type': 'Cable/DSL/ISP' }, 'Charter Communications', False, False, False, currentTime ) assert dict( location ) == { 'ip': '0.0.0.0', 'country': 'US', 'region': 'California', 'city': 'Westlake Village', 'lat': 34.141944, 'lng': -118.819444, 'postalCode': '91361', 'timezone': '-08:00', 'domains': ['cpe-75-82-84-171.socal.res.rr.com'], 'as': { 'asn': 20001, 'name': 'Charter Communications (20001)', 'route': '75.82.0.0/15', 'domain': 'https://www.spectrum.com', 'type': 'Cable/DSL/ISP' }, 'isp': 'Charter Communications', 'proxy': False, 'vpn': False, 'tor': False, 'dateAdded': currentTime }
def test_key(): location = Location( '171a0329-f8b2-499c-867d-1942384ddd5f', '0.0.0.0', 'US', 'California', 'Westlake Village', 34.141944, -118.819444, '91361', '-08:00', ['cpe-75-82-84-171.socal.res.rr.com'], { 'asn': 20001, 'name': 'Charter Communications (20001)', 'route': '75.82.0.0/15', 'domain': 'https://www.spectrum.com', 'type': 'Cable/DSL/ISP' }, 'Charter Communications', False, False, False) assert location.key() == { 'PK': { 'S': 'VISITOR#171a0329-f8b2-499c-867d-1942384ddd5f' }, 'SK': { 'S': '#LOCATION' } }
def test_toItem(): currentTime = datetime.datetime.now() location = Location( '171a0329-f8b2-499c-867d-1942384ddd5f', '0.0.0.0', 'US', 'California', 'Westlake Village', 34.141944, -118.819444, '91361', '-08:00', ['cpe-75-82-84-171.socal.res.rr.com'], { 'asn': 20001, 'name': 'Charter Communications (20001)', 'route': '75.82.0.0/15', 'domain': 'https://www.spectrum.com', 'type': 'Cable/DSL/ISP' }, 'Charter Communications', False, False, False, currentTime) assert location.toItem() == { 'PK': { 'S': 'VISITOR#171a0329-f8b2-499c-867d-1942384ddd5f' }, 'SK': { 'S': '#LOCATION' }, 'Type': { 'S': 'location' }, 'IP': { 'S': '0.0.0.0' }, 'Country': { 'S': 'US' }, 'Region': { 'S': 'California' }, 'City': { 'S': 'Westlake Village' }, 'Latitude': { 'N': '34.141944' }, 'Longitude': { 'N': '-118.819444' }, 'PostalCode': { 'S': '91361' }, 'TimeZone': { 'S': '-08:00' }, 'Domains': { 'SS': ['cpe-75-82-84-171.socal.res.rr.com'] }, 'AutonomousSystem': { 'M': { 'asn': { 'N': '20001' }, 'name': { 'S': 'Charter Communications (20001)' }, 'route': { 'S': '75.82.0.0/15' }, 'domain': { 'S': 'https://www.spectrum.com' }, 'type': { 'S': 'Cable/DSL/ISP' } } }, 'ISP': { 'S': 'Charter Communications' }, 'Proxy': { 'BOOL': False }, 'VPN': { 'BOOL': False }, 'TOR': { 'BOOL': False }, 'DateAdded': { 'S': currentTime.strftime( '%Y-%m-%dT%H:%M:%S.' ) \ + currentTime.strftime('%f')[:3] + 'Z' } }
def location(): '''Properly formatted location.''' return Location( '0.0.0.0', 'US', 'California', 'Stockton', 37.9577, -121.29078, '95201', '-08:00', ['c-73-66-102-206.hsd1.ca.comcast.net'], { 'asn': 7922, 'name': 'Comcast', 'route': '73.0.0.0/8', 'type': 'Cable/DSL/ISP', 'domain': 'https://corporate.comcast.com/' }, 'Comcast Cable Communications, LLC', False, False, False, '2020-12-29T17:40:00.144Z')