From 120707b5d7b777d9c2bf72ba3790601216b7a5f6 Mon Sep 17 00:00:00 2001 From: Nex Sabre Date: Tue, 25 Oct 2022 15:35:01 +0200 Subject: [PATCH] perf: Update Python to stable v3.11 & add smoke test (#90) * Add smoke test to the separate directory * Enable smoke-test on the pipeline, like the last step --- .github/workflows/ci.yml | 6 +++++- Dockerfile | 2 +- Makefile | 9 +++++++-- tests/{routers/api => }/__init__.py | 0 tests/integration/__init__.py | 0 tests/integration/routers/__init__.py | 0 tests/integration/routers/api/__init__.py | 0 tests/{ => integration}/routers/api/test_create.py | 0 tests/{ => integration}/routers/api/test_hex.py | 0 tests/{ => integration}/routers/api/test_packets.py | 0 tests/{ => integration}/test_main.py | 0 tests/smoke/__init__.py | 0 tests/smoke/conftest.py | 13 +++++++++++++ tests/smoke/test_smoke_prod.py | 12 ++++++++++++ 14 files changed, 38 insertions(+), 4 deletions(-) rename tests/{routers/api => }/__init__.py (100%) create mode 100644 tests/integration/__init__.py create mode 100644 tests/integration/routers/__init__.py create mode 100644 tests/integration/routers/api/__init__.py rename tests/{ => integration}/routers/api/test_create.py (100%) rename tests/{ => integration}/routers/api/test_hex.py (100%) rename tests/{ => integration}/routers/api/test_packets.py (100%) rename tests/{ => integration}/test_main.py (100%) create mode 100644 tests/smoke/__init__.py create mode 100644 tests/smoke/conftest.py create mode 100644 tests/smoke/test_smoke_prod.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d887a93..1bc0538 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v4 with: - python-version: '3.11.0-rc.2' + python-version: '3.11' cache: 'pip' - name: Install Python dependencies (pip) run: | @@ -153,3 +153,7 @@ jobs: export GIT_VERSION_TAG=`git describe --tags --abbrev=0` export SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8` python check_deployment.py https://www.packethelper.com $GIT_VERSION_TAG $SHORT_SHA + - name: Run Smoke tests + run: | + pip install requests pytest + make test-smoke diff --git a/Dockerfile b/Dockerfile index 4355479..c2e3043 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ COPY . . RUN yarn build # build stage (backend & package) -FROM python:3.11-rc-buster +FROM python:3.11-buster # Install tshark/wireshark dependecies RUN echo "wireshark-common wireshark-common/install-setuid boolean true" | debconf-set-selections diff --git a/Makefile b/Makefile index c760221..c3d6056 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ format-ui: format: @echo "Formatting..." python3 -m isort ph/ tests/ --profile black - python3 -m black -t py310 ph/ tests/ + python3 -m black -t py311 ph/ tests/ prettier --write src/ @echo "Formatting... Done" @@ -45,9 +45,14 @@ format: run-back: uvicorn --port 8080 ph.main:app +.PHONY: test test: mkdir -p static && touch static/index.html - PYTHONPATH=${PWD} pytest + PYTHONPATH=${PWD} pytest tests/integration + +.PHONY: test-smoke +test-smoke: + PYTHONPATH=${PWD} pytest tests/smoke .PHONY: init init: diff --git a/tests/routers/api/__init__.py b/tests/__init__.py similarity index 100% rename from tests/routers/api/__init__.py rename to tests/__init__.py diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/integration/routers/__init__.py b/tests/integration/routers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/integration/routers/api/__init__.py b/tests/integration/routers/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/routers/api/test_create.py b/tests/integration/routers/api/test_create.py similarity index 100% rename from tests/routers/api/test_create.py rename to tests/integration/routers/api/test_create.py diff --git a/tests/routers/api/test_hex.py b/tests/integration/routers/api/test_hex.py similarity index 100% rename from tests/routers/api/test_hex.py rename to tests/integration/routers/api/test_hex.py diff --git a/tests/routers/api/test_packets.py b/tests/integration/routers/api/test_packets.py similarity index 100% rename from tests/routers/api/test_packets.py rename to tests/integration/routers/api/test_packets.py diff --git a/tests/test_main.py b/tests/integration/test_main.py similarity index 100% rename from tests/test_main.py rename to tests/integration/test_main.py diff --git a/tests/smoke/__init__.py b/tests/smoke/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/smoke/conftest.py b/tests/smoke/conftest.py new file mode 100644 index 0000000..c736a7d --- /dev/null +++ b/tests/smoke/conftest.py @@ -0,0 +1,13 @@ +import os + +import pytest + + +@pytest.fixture +def instance_uri() -> str: + return os.getenv("PACKET_HELPER_URI", "https://www.packethelper.com") + + +@pytest.fixture +def api_uri(instance_uri: str) -> str: + return f"{instance_uri}/api" diff --git a/tests/smoke/test_smoke_prod.py b/tests/smoke/test_smoke_prod.py new file mode 100644 index 0000000..7ebc15f --- /dev/null +++ b/tests/smoke/test_smoke_prod.py @@ -0,0 +1,12 @@ +from http import HTTPStatus + +import requests + + +def test_smoke(api_uri: str) -> None: + simple_packet = ( + "00001Cffffff0000000000000800450000340001000040047cc37f0000017f00000" + "14500002000010000402f7cac7f0000017f00000100000000" + ) # Ethernet / IP / IPv6 / GRE + response = requests.get(f"{api_uri}/hex/{simple_packet}") + assert response.status_code == HTTPStatus.OK