Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move mypy to test requirements. #24

Merged
merged 5 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 0 additions & 53 deletions .github/workflows/docker.yml

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
python -m pip install --upgrade pip
python -m pip install -r requirement.txt
python -m pip install -r tests/test-requirement.txt
python -m pip install mypy types-click types-protobuf types-redis types-requests types-urllib3 typing_extensions types-cryptography
- name: Running Black.
uses: psf/black@stable
with:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,4 @@ jobs:
- name: Runnning tests with pytest.
run: |
set -o pipefail
pytest -m "not docker" --cov=. | tee pytest-coverage.txt
- name: Comment coverage
uses: coroo/[email protected]
pytest -m "not docker"
11 changes: 10 additions & 1 deletion tests/test-requirement.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
pylint
pylint-quotes
pytest
pytest-cov
requests-mock
pytest-mock

# Typing requirements.
mypy
types-click
types-protobuf
types-redis
types-requests
types-urllib3
typing-extensions
types-cryptography
257 changes: 60 additions & 197 deletions tests/utils/test_ip_range_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,72 @@
import ipaddress
import re

import requests_mock as rq_mock

from agent import ip2geo
from agent.utils.ip_range_visitor import IpRangeVisitor
import requests_mock as rq_mock

ip_range_visitor = IpRangeVisitor()


def testVistor_withMatchingIPAndMaskRecieved_returnsLocations() -> None:
def testVisitor_withMatchingIPAndMaskReceived_returnsLocations(
requests_mock: rq_mock.mocker.Mocker,
) -> None:
requests_mock.get(
re.compile("http://ip-api.com/json//8.8.8.0.*"),
json={
"status": "success",
"continent": "North America",
"continentCode": "NA",
"country": "United States",
"countryCode": "US",
"region": "CA",
"regionName": "California",
"city": "Los Angeles",
"zip": "90009",
"lat": 34.0544,
"lon": -118.2441,
"timezone": "America/Los_Angeles",
"isp": "Google LLC",
"org": "Level 3",
"asname": "GOOGLE",
"mobile": False,
"proxy": False,
"hosting": True,
"query": "8.8.8.0",
},
status_code=200,
)

requests_mock.get(
re.compile("http://ip-api.com/json//8.8.8.1.*"),
json={
"status": "success",
"continent": "North America",
"continentCode": "NA",
"country": "United States",
"countryCode": "US",
"region": "CA",
"regionName": "California",
"city": "Los Angeles",
"zip": "90009",
"lat": 34.0544,
"lon": -118.2441,
"timezone": "America/Los_Angeles",
"isp": "Google LLC",
"org": "Level 3",
"asname": "GOOGLE",
"mobile": False,
"proxy": False,
"hosting": True,
"query": "8.8.8.1",
},
status_code=200,
)

results = []
for result in ip_range_visitor.dichotomy_ip_network_visit(
ipaddress.ip_network("8.8.8.0/22"),
ipaddress.ip_network("8.8.8.0/31"),
ip_range_visitor.is_first_last_ip_same_geolocation,
):
results.append(result[0:2])
Expand All @@ -36,24 +91,7 @@ def testVistor_withMatchingIPAndMaskRecieved_returnsLocations() -> None:
"timezone": "America/Los_Angeles",
},
{
"host": "8.8.11.255",
"version": 4,
"continent": "North America",
"continent_code": "NA",
"country": "United States",
"country_code": "US",
"region": "LA",
"region_name": "Louisiana",
"city": "Monroe",
"zip": "71203",
"latitude": 32.5896,
"longitude": -92.0669,
"timezone": "America/Chicago",
},
),
(
{
"host": "8.8.8.0",
"host": "8.8.8.1",
"version": 4,
"continent": "North America",
"continent_code": "NA",
Expand All @@ -67,182 +105,7 @@ def testVistor_withMatchingIPAndMaskRecieved_returnsLocations() -> None:
"longitude": -118.2441,
"timezone": "America/Los_Angeles",
},
{
"host": "8.8.9.255",
"version": 4,
"continent": "North America",
"continent_code": "NA",
"country": "United States",
"country_code": "US",
"region": "FL",
"region_name": "Florida",
"city": "Fort Lauderdale",
"zip": "33309",
"latitude": 26.2018,
"longitude": -80.1699,
"timezone": "America/New_York",
},
),
(
{
"host": "8.8.8.0",
"version": 4,
"continent": "North America",
"continent_code": "NA",
"country": "United States",
"country_code": "US",
"region": "CA",
"region_name": "California",
"city": "Los Angeles",
"zip": "90009",
"latitude": 34.0544,
"longitude": -118.2441,
"timezone": "America/Los_Angeles",
},
{
"host": "8.8.8.255",
"version": 4,
"continent": "North America",
"continent_code": "NA",
"country": "United States",
"country_code": "US",
"region": "CA",
"region_name": "California",
"city": "Los Angeles",
"zip": "90009",
"latitude": 34.0544,
"longitude": -118.2441,
"timezone": "America/Los_Angeles",
},
),
(
{
"host": "8.8.9.0",
"version": 4,
"continent": "North America",
"continent_code": "NA",
"country": "United States",
"country_code": "US",
"region": "FL",
"region_name": "Florida",
"city": "Fort Lauderdale",
"zip": "33309",
"latitude": 26.2018,
"longitude": -80.1699,
"timezone": "America/New_York",
},
{
"host": "8.8.9.255",
"version": 4,
"continent": "North America",
"continent_code": "NA",
"country": "United States",
"country_code": "US",
"region": "FL",
"region_name": "Florida",
"city": "Fort Lauderdale",
"zip": "33309",
"latitude": 26.2018,
"longitude": -80.1699,
"timezone": "America/New_York",
},
),
(
{
"host": "8.8.10.0",
"version": 4,
"continent": "North America",
"continent_code": "NA",
"country": "United States",
"country_code": "US",
"region": "VA",
"region_name": "Virginia",
"city": "Ashburn",
"zip": "20149",
"latitude": 39.0438,
"longitude": -77.4874,
"timezone": "America/New_York",
},
{
"host": "8.8.11.255",
"version": 4,
"continent": "North America",
"continent_code": "NA",
"country": "United States",
"country_code": "US",
"region": "LA",
"region_name": "Louisiana",
"city": "Monroe",
"zip": "71203",
"latitude": 32.5896,
"longitude": -92.0669,
"timezone": "America/Chicago",
},
),
(
{
"host": "8.8.10.0",
"version": 4,
"continent": "North America",
"continent_code": "NA",
"country": "United States",
"country_code": "US",
"region": "VA",
"region_name": "Virginia",
"city": "Ashburn",
"zip": "20149",
"latitude": 39.0438,
"longitude": -77.4874,
"timezone": "America/New_York",
},
{
"host": "8.8.10.255",
"version": 4,
"continent": "North America",
"continent_code": "NA",
"country": "United States",
"country_code": "US",
"region": "VA",
"region_name": "Virginia",
"city": "Ashburn",
"zip": "20149",
"latitude": 39.0438,
"longitude": -77.4874,
"timezone": "America/New_York",
},
),
(
{
"host": "8.8.11.0",
"version": 4,
"continent": "North America",
"continent_code": "NA",
"country": "United States",
"country_code": "US",
"region": "LA",
"region_name": "Louisiana",
"city": "Monroe",
"zip": "71203",
"latitude": 32.5896,
"longitude": -92.0669,
"timezone": "America/Chicago",
},
{
"host": "8.8.11.255",
"version": 4,
"continent": "North America",
"continent_code": "NA",
"country": "United States",
"country_code": "US",
"region": "LA",
"region_name": "Louisiana",
"city": "Monroe",
"zip": "71203",
"latitude": 32.5896,
"longitude": -92.0669,
"timezone": "America/Chicago",
},
),
)
]


Expand Down