def test_quirks(): geodata = pysyge.GeoLocator(DATABASE_CITY_FILE, pysyge.MODE_MEMORY) result = geodata.get_location('49.206.213.75', detailed=True) assert result['city'] == '' assert result['country_iso'] == 'US' assert result['tz'] == '' assert result['info']['country']['name_en'] == 'United States'
def test_location_detailed(self): geodata = pysyge.GeoLocator(DATABASE_CITY_FILE) location = geodata.get_location(BASE_IP, detailed=True) assert_location(location, detailed=True) locations = geodata.get_locations(BASE_IP) assert locations[0]['country_iso'] == 'RU'
def test_location_detailed(self): geodata = pysyge.GeoLocator(DATABASE_CITY_FILE) location = geodata.get_location(BASE_IP, detailed=True) self.assertIn('city', location) self.assertIn('country_id', location) self.assertIn('country_iso', location) self.assertIn('lon', location) self.assertIn('lat', location) self.assertIn('fips', location) self.assertIn('region_id', location) self.assertIn('region', location) self.assertIn('tz', location) self.assertEqual(location['city'], u'Москва') self.assertEqual(location['country_id'], 185) self.assertEqual(location['country_iso'], 'RU') self.assertEqual(location['lon'], 37.61556) self.assertEqual(location['lat'], 55.75222) self.assertEqual(location['fips'], '0') self.assertEqual(location['region_id'], 524894) self.assertEqual(location['region'], u'Москва') self.assertEqual(location['tz'], 'Europe/Moscow')
def test_location_basic(self): geodata = pysyge.GeoLocator(DATABASE_CITY_FILE, pysyge.MODE_MEMORY) location = geodata.get_location(BASE_IP) self.assertIn('city', location) self.assertIn('country_id', location) self.assertIn('country_iso', location) self.assertIn('lon', location) self.assertIn('lat', location) self.assertIn('fips', location) self.assertIn('region_id', location) self.assertNotIn('region', location) self.assertNotIn('tz', location) self.assertEqual(location['city'], u'Москва') self.assertEqual(location['country_id'], 185) self.assertEqual(location['country_iso'], 'RU') self.assertEqual(location['lon'], 37.61556) self.assertEqual(location['lat'], 55.75222) self.assertEqual(location['fips'], '0') self.assertEqual(location['region_id'], 0)
def test_location_detailed(self): geodata = pysyge.GeoLocator(DATABASE_CITY_FILE, pysyge.MODE_BATCH) location = geodata.get_location(BASE_IP, detailed=True) assert_location(location, detailed=True)
def test_location_basic(self): geodata = pysyge.GeoLocator(DATABASE_CITY_FILE, pysyge.MODE_BATCH) location = geodata.get_location(BASE_IP) assert_location(location)
def test_localhost(self): geodata = pysyge.GeoLocator(DATABASE_CITY_FILE) assert geodata.get_location('127.0.0.1') is False
def test_db_date(self): geodata = pysyge.GeoLocator(DATABASE_CITY_FILE) assert isinstance(geodata.get_db_date(), datetime.datetime)
def test_db_version(self): geodata = pysyge.GeoLocator(DATABASE_CITY_FILE) assert geodata.get_db_version() >= 21
def test_wrong_file(self): with pytest.raises(pysyge.GeoLocatorException): pysyge.GeoLocator('tests/test_module.py')
def test_file_not_found(self): with pytest.raises(IOError): pysyge.GeoLocator('nosuchfile.dat')
def test_invalid_ips(self): geodata = pysyge.GeoLocator(DATABASE_CITY_FILE) assert geodata.get_location('127.0.0.1') == {} assert geodata.get_location('80.8qeqw') == {}
def test_wrong_file(self): with pytest.raises(pysyge.GeoLocatorException): pysyge.GeoLocator(path.join(DIR_CURRENT, 'test_module.py'))
def test_localhost(self): geodata = pysyge.GeoLocator(DATABASE_CITY_FILE) self.assertEqual(geodata.get_location('127.0.0.1'), False)
def test_db_version(self): geodata = pysyge.GeoLocator(DATABASE_CITY_FILE) self.assertGreaterEqual(geodata.get_db_version(), 21)