fix flake8 defects
All checks were successful
Bandit / audit-runtime-security (3.11) (pull_request) Successful in 10m3s
Mypy / audit-typing (3.11) (pull_request) Successful in 11m0s
pip-audit / audit-dependency-security (3.11) (pull_request) Successful in 11m2s
Pylint / audit-runtime-security (3.11) (pull_request) Successful in 10m32s
Python Coverage / test-and-coverage (3.11) (pull_request) Successful in 10m24s
Flake8 / audit (3.11) (pull_request) Successful in 10m1s
All checks were successful
Bandit / audit-runtime-security (3.11) (pull_request) Successful in 10m3s
Mypy / audit-typing (3.11) (pull_request) Successful in 11m0s
pip-audit / audit-dependency-security (3.11) (pull_request) Successful in 11m2s
Pylint / audit-runtime-security (3.11) (pull_request) Successful in 10m32s
Python Coverage / test-and-coverage (3.11) (pull_request) Successful in 10m24s
Flake8 / audit (3.11) (pull_request) Successful in 10m1s
This commit is contained in:
@ -90,83 +90,12 @@ def get_mock_reader(test_data):
|
||||
return mock_reader
|
||||
|
||||
|
||||
def mock_reader_city(ip):
|
||||
'''
|
||||
Must throw geoip2.errors.AddressNotFoundError when not in our mocked data
|
||||
Must return
|
||||
geoip2.models.City(['en'], continent={'code': 'EU', 'geoname_id': 6255148,
|
||||
'names': {'de': 'Europa', 'en': 'Europe', 'es': 'Europa', 'fr': 'Europe', 'ja':
|
||||
'ヨーロッパ', 'pt-BR': 'Europa', 'ru': 'Европа', 'zh-CN': '欧洲'}},
|
||||
country={'geoname_id': 2750405, 'is_in_european_union': True, 'iso_code': 'NL',
|
||||
'names': {'de': 'Niederlande', 'en': 'The Netherlands', 'es': 'Holanda', 'fr':
|
||||
'Pays-Bas', 'ja': 'オランダ王国', 'pt-BR': 'Holanda', 'ru': 'Нидерланды',
|
||||
'zh-CN': '荷兰'}}, registered_country={'geoname_id': 2750405,
|
||||
'is_in_european_union': True, 'iso_code': 'NL', 'names': {'de': 'Niederlande',
|
||||
'en': 'The Netherlands', 'es': 'Holanda', 'fr': 'Pays-Bas', 'ja':
|
||||
'オランダ王国', 'pt-BR': 'Holanda', 'ru': 'Нидерланды', 'zh-CN': '荷兰'}},
|
||||
traits={'ip_address': '2a02:898:96::5e8e:f508', 'network': '2a02:898::/32'},
|
||||
city={'geoname_id': 2759794, 'names': {'de': 'Amsterdam', 'en': 'Amsterdam',
|
||||
'es': 'Ámsterdam', 'fr': 'Amsterdam', 'ja': 'Amusuterudamu', 'pt-BR':
|
||||
'Amesterdã', 'ru': 'Амстердам', 'zh-CN': '阿姆斯特丹'}},
|
||||
location={'accuracy_radius': 20, 'latitude': 52.3759, 'longitude': 4.8975,
|
||||
'time_zone': 'Europe/Amsterdam'}, postal={'code': '1012'},
|
||||
subdivisions=[{'geoname_id': 2749879, 'iso_code': 'NH', 'names': {'de':
|
||||
'Nordholland', 'en': 'North Holland', 'es': 'Holanda Septentrional', 'fr':
|
||||
'Hollande-Septentrionale', 'ja': '
|
||||
北ホラント州', 'pt-BR': 'Holanda do Norte', 'ru': 'Северная Голландия', 'zh-CN': '北荷兰省'}}])
|
||||
geoip2.models.City(
|
||||
locales: Optional[collections.abc.Sequence[str]],
|
||||
*,
|
||||
city: Optional[dict] = None,
|
||||
continent: Optional[dict] = None,
|
||||
country: Optional[dict] = None,
|
||||
location: Optional[dict] = None,
|
||||
ip_address: Union[str, ipaddress.IPv6Address, ipaddress.IPv4Address, NoneType] = None,
|
||||
maxmind: Optional[dict] = None,
|
||||
postal: Optional[dict] = None,
|
||||
prefix_len: Optional[int] = None,
|
||||
registered_country: Optional[dict] = None,
|
||||
represented_country: Optional[dict] = None,
|
||||
subdivisions: Optional[list[dict]] = None,
|
||||
traits: Optional[dict] = None,
|
||||
**_,
|
||||
) -> None
|
||||
Docstring: Model for the City Plus web service and the City database.
|
||||
File: /usr/local/lib/python3.11/site-packages/geoip2/models.py
|
||||
Type: ABCMeta
|
||||
Subclasses: Insights, Enterprise
|
||||
'''
|
||||
pass
|
||||
|
||||
def mock_reader_asn():
|
||||
'''
|
||||
Must throw geoip2.errors.AddressNotFoundError when not in our mocked data
|
||||
Must return
|
||||
geoip2.models.ASN('2a02:898:96::5e8e:f508', autonomous_system_number=8283, autonomous_system_organization='Netwerkvereniging Coloclue', network='2a02:898::/32')
|
||||
Init signature:
|
||||
geoip2.models.ASN(
|
||||
ip_address: Union[str, ipaddress.IPv6Address, ipaddress.IPv4Address],
|
||||
*,
|
||||
autonomous_system_number: Optional[int] = None,
|
||||
autonomous_system_organization: Optional[str] = None,
|
||||
network: Optional[str] = None,
|
||||
prefix_len: Optional[int] = None,
|
||||
**_,
|
||||
) -> None
|
||||
Docstring: Model class for the GeoLite2 ASN.
|
||||
File: /usr/local/lib/python3.11/site-packages/geoip2/models.py
|
||||
Type: ABCMeta
|
||||
Subclasses: ISP
|
||||
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
def test_no_query():
|
||||
"""Test searching without a query parameter"""
|
||||
test_data = gen_testdata()
|
||||
|
||||
with patch('geoip2.database.Reader', return_value=get_mock_reader(test_data)):
|
||||
with patch('geoip2.database.Reader',
|
||||
return_value=get_mock_reader(test_data)):
|
||||
|
||||
response = client.get("/")
|
||||
|
||||
@ -181,7 +110,8 @@ def test_single_query():
|
||||
"""Test searching with an ip address"""
|
||||
test_data = gen_testdata()
|
||||
|
||||
with patch('geoip2.database.Reader', return_value=get_mock_reader(test_data)):
|
||||
with patch('geoip2.database.Reader',
|
||||
return_value=get_mock_reader(test_data)):
|
||||
fake_ipv4 = fake.ipv4_public()
|
||||
|
||||
response = client.get(f"/{fake_ipv4}")
|
||||
@ -197,8 +127,10 @@ def test_multi_query():
|
||||
"""Test searching with an ip address"""
|
||||
test_data = gen_testdata()
|
||||
|
||||
with patch('geoip2.database.Reader', return_value=get_mock_reader(test_data)):
|
||||
fake_ips = [{'ip': fake.ipv6() if random.random() > 0.5 else fake.ipv4()}
|
||||
with patch('geoip2.database.Reader',
|
||||
return_value=get_mock_reader(test_data)):
|
||||
fake_ips = [{'ip': fake.ipv6() if random.random() > 0.5
|
||||
else fake.ipv4()}
|
||||
for _ in range(16)]
|
||||
|
||||
response = client.post("/", json=fake_ips)
|
||||
@ -217,7 +149,8 @@ def test_invalid_query():
|
||||
"""Test searching with an invalid ip address"""
|
||||
test_data = gen_testdata()
|
||||
|
||||
with patch('geoip2.database.Reader', return_value=get_mock_reader(test_data)):
|
||||
with patch('geoip2.database.Reader',
|
||||
return_value=get_mock_reader(test_data)):
|
||||
invalid_ip = '500.312.77.31337'
|
||||
test_pattern = 'Input is not a valid IPv[46] address'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user