diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index 8c22f69..0000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,53 +0,0 @@ -#name: Build and Publish -# -#on: -# # run it on push to the default repository branch -# push: -# branches: [ main ] -# # run it during pull request -# pull_request: -# -#defaults: -# # define job to build and publish docker image -# build-and-push-docker-image: -# name: Build Docker image and push to repositories -# # run only when code is compiling and tests are passing -# runs-on: ubuntu-latest -# -# # steps to perform in job -# steps: -# - name: Checkout code -# uses: actions/checkout@v2 -# -# # setup Docker buld action -# - name: Set up Docker Buildx -# id: buildx -# uses: docker/setup-buildx-action@v1 -# -# - name: Login to DockerHub -# uses: docker/login-action@v1 -# with: -# username: ${{ secrets.DOCKERHUB_USERNAME }} -# password: ${{ secrets.DOCKERHUB_TOKEN }} -# -# - name: Login to Github Packages -# uses: docker/login-action@v1 -# with: -# registry: ghcr.io -# username: ${{ github.actor }} -# password: ${{ secrets.GHCR_PAT }} -# -# - name: Build image and push to Docker Hub and GitHub Container Registry -# uses: docker/build-push-action@v2 -# with: -# # relative path to the place where source code with Dockerfile is located -# context: ./agent/samples/simple -# # Note: tags has to be all lower-case -# tags: | -# oskardudycz/eventsourcing.nodejs.simple:latest -# ghcr.io/oskardudycz/eventsourcing.nodejs/simple:latest -# # build on feature branches, push only on main branch -# push: ${{ github.ref == 'refs/heads/main' }} -# -# - name: Image digest -# run: echo ${{ steps.docker_build.outputs.digest }} \ No newline at end of file diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 96a4f96..44b74fc 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -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: diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 390024b..39997dc 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -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/pytest-coverage-commentator@v1.0.2 + pytest -m "not docker" diff --git a/tests/test-requirement.txt b/tests/test-requirement.txt index c4c1e99..06574d0 100644 --- a/tests/test-requirement.txt +++ b/tests/test-requirement.txt @@ -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 diff --git a/tests/utils/test_ip_range_visitor.py b/tests/utils/test_ip_range_visitor.py index e03d8b2..ff6fe18 100644 --- a/tests/utils/test_ip_range_visitor.py +++ b/tests/utils/test_ip_range_visitor.py @@ -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]) @@ -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", @@ -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", - }, - ), + ) ]