From 9558a6011bc29c3fdd6db8ed4dace0bc2375176d Mon Sep 17 00:00:00 2001 From: Shai Lachmanovich Date: Mon, 13 Jan 2025 11:59:52 +0100 Subject: [PATCH 1/3] Add workflow to build and test the code --- .github/workflows/python-app.yml | 44 ++++++++++++++++++++++++++ tests/armis_sdk/entities/sites_test.py | 4 +-- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..c1a3205 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,44 @@ +# Based on https://github.com/marketplace/actions/python-poetry-action + +name: Python application + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3.9 + uses: actions/setup-python@v3 + with: + python-version: "3.9" + + - name: Install poetry + uses: abatilo/actions-poetry@v4 + + - name: Setup a local virtual environment (if no poetry.toml file) + run: | + poetry config virtualenvs.create true --local + poetry config virtualenvs.in-project true --local + + - uses: actions/cache@v3 + name: Define a cache for the virtual environment based on the dependencies lock file + with: + path: ./.venv + key: venv-${{ hashFiles('poetry.lock') }} + + - name: Install the project dependencies + run: poetry install + + - name: Run the automated tests (for example) + run: poetry run pytest -vv diff --git a/tests/armis_sdk/entities/sites_test.py b/tests/armis_sdk/entities/sites_test.py index e0c7eec..ec9b430 100644 --- a/tests/armis_sdk/entities/sites_test.py +++ b/tests/armis_sdk/entities/sites_test.py @@ -58,7 +58,7 @@ async def test_get_sites(from_response, expected, httpx_mock: pytest_httpx.HTTPX async def test_get_sites_with_multiple_pages( monkeypatch, httpx_mock: pytest_httpx.HTTPXMock ): - monkeypatch.setenv("ARMIS_PAGE_SIZE", 2) + monkeypatch.setenv("ARMIS_PAGE_SIZE", "2") httpx_mock.add_response( url="https://mock_tenant.armis.com/api/v1/sites/?from=0&length=2", method="GET", @@ -133,7 +133,7 @@ async def test_hierarchy(httpx_mock: pytest_httpx.HTTPXMock): assert hierarchy == [ Site( - id="1", + id="12", name="mock_site_1", children=[ Site( From f963a6bc4fcb4c424d935a172604f89424add2ac Mon Sep 17 00:00:00 2001 From: Shai Lachmanovich Date: Mon, 13 Jan 2025 12:06:28 +0100 Subject: [PATCH 2/3] . --- .github/workflows/python-app.yml | 11 ++++------- tests/armis_sdk/entities/sites_test.py | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index c1a3205..7461a91 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -3,10 +3,7 @@ name: Python application on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] + - push permissions: contents: read @@ -32,13 +29,13 @@ jobs: poetry config virtualenvs.in-project true --local - uses: actions/cache@v3 - name: Define a cache for the virtual environment based on the dependencies lock file + name: Define a cache for the virtual environment based on the lock file with: path: ./.venv key: venv-${{ hashFiles('poetry.lock') }} - - name: Install the project dependencies + - name: Install dependencies run: poetry install - - name: Run the automated tests (for example) + - name: Run tests run: poetry run pytest -vv diff --git a/tests/armis_sdk/entities/sites_test.py b/tests/armis_sdk/entities/sites_test.py index ec9b430..2d36d72 100644 --- a/tests/armis_sdk/entities/sites_test.py +++ b/tests/armis_sdk/entities/sites_test.py @@ -133,7 +133,7 @@ async def test_hierarchy(httpx_mock: pytest_httpx.HTTPXMock): assert hierarchy == [ Site( - id="12", + id="1", name="mock_site_1", children=[ Site( From 6b6bccb7145925a7e71f3c51a7aaafbd4d017445 Mon Sep 17 00:00:00 2001 From: Shai Lachmanovich Date: Mon, 13 Jan 2025 12:08:01 +0100 Subject: [PATCH 3/3] . --- .github/workflows/{python-app.yml => test.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{python-app.yml => test.yml} (97%) diff --git a/.github/workflows/python-app.yml b/.github/workflows/test.yml similarity index 97% rename from .github/workflows/python-app.yml rename to .github/workflows/test.yml index 7461a91..bb7e94e 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,6 @@ # Based on https://github.com/marketplace/actions/python-poetry-action -name: Python application +name: Run tests on: - push