Skip to content

Commit ba2cfff

Browse files
authored
Add tox linting and placeholder unit test (#399)
1 parent d944e97 commit ba2cfff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+3843
-3266
lines changed

.codespellignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rackit

.github/workflows/test-pr.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ concurrency:
1818
cancel-in-progress: true
1919

2020
jobs:
21+
# Run the unit tests on every PR, even from external repos
22+
unit_tests:
23+
uses: ./.github/workflows/tox.yaml
24+
with:
25+
ref: ${{ github.event.pull_request.head.sha }}
26+
2127
# This job exists so that PRs from outside the main repo are rejected
2228
fail_on_remote:
2329
runs-on: ubuntu-latest
@@ -26,7 +32,7 @@ jobs:
2632
run: exit ${{ github.event.pull_request.head.repo.full_name == 'azimuth-cloud/azimuth' && '0' || '1' }}
2733

2834
publish_artifacts:
29-
needs: [fail_on_remote]
35+
needs: [unit_tests, fail_on_remote]
3036
uses: ./.github/workflows/build-push-artifacts.yaml
3137
with:
3238
ref: ${{ github.event.pull_request.head.sha }}

.github/workflows/tox.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Tox unit tests
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
ref:
7+
type: string
8+
description: The ref to build.
9+
required: true
10+
11+
jobs:
12+
build:
13+
name: Tox unit tests and linting
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
python-version: ['3.10','3.12']
18+
19+
steps:
20+
- name: Check out the repository
21+
uses: actions/checkout@v4
22+
with:
23+
ref: ${{ inputs.ref || github.ref }}
24+
25+
- name: Set up Python ${{ matrix.python-version }}
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
30+
- name: Install dependencies
31+
run: |
32+
python -m pip install --upgrade pip
33+
python -m pip install tox
34+
35+
- name: Test with tox
36+
run: tox
37+
38+
- name: Generate coverage reports
39+
run: tox -e cover
40+
41+
- name: Archive code coverage results
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: "code-coverage-report-${{ matrix.python-version }}"
45+
path: cover/

.stestr.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[DEFAULT]
2+
test_path=./api/tests
3+
top_dir=./

api/azimuth/acls/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .acls import allowed_by_acls
1+
from .acls import allowed_by_acls # noqa: F401

api/azimuth/acls/acls.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import re
21
import logging
2+
import re
33

44
LOG = logging.getLogger(__name__)
55

@@ -61,6 +61,5 @@ def allowed_by_acls(raw, tenancy):
6161

6262
# If either 'allow' annotation is present and non-empty then default to deny
6363
return not (
64-
annotations.get(ACL_ALLOW_IDS_KEY) or
65-
annotations.get(ACL_ALLOW_PATTERN_KEY)
64+
annotations.get(ACL_ALLOW_IDS_KEY) or annotations.get(ACL_ALLOW_PATTERN_KEY)
6665
)

api/azimuth/acls/test_acls.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
from unittest import TestCase
2+
3+
from ..provider.dto import Tenancy # noqa: TID252
24
from .acls import (
3-
ACL_KEYS,
45
ACL_ALLOW_IDS_KEY,
56
ACL_ALLOW_PATTERN_KEY,
67
ACL_DENY_IDS_KEY,
78
ACL_DENY_PATTERN_KEY,
9+
ACL_KEYS,
810
allowed_by_acls,
911
)
1012

11-
from ..provider.dto import Tenancy
12-
1313

1414
class ACLTestCase(TestCase):
15-
1615
def assert_allowed(self, resource, tenancy):
1716
"""Helper method to make logic clearer"""
1817
self.assertTrue(allowed_by_acls(resource, tenancy))
@@ -28,7 +27,8 @@ def test_no_annotations(self):
2827
for t in tenancies:
2928
self.assert_allowed(test_resource, t)
3029

31-
# Check that all tenancies are allowed when all ACL annotations are present but empty
30+
# Check that all tenancies are allowed when all ACL annotations are present but
31+
# empty
3232
def test_empty_annotations(self):
3333
tenancies = [Tenancy(id=f"test-id-{i}", name=f"name-{i}") for i in range(3)]
3434
test_resource = {"metadata": {"annotations": {k: "" for k in ACL_KEYS}}}
@@ -61,16 +61,16 @@ def test_allow_ids(self):
6161
# Check that filtering by allowed name pattern works
6262
def test_allow_pattern(self):
6363
test_resource = {"metadata": {"annotations": {ACL_ALLOW_PATTERN_KEY: "prod-"}}}
64-
self.assert_allowed(test_resource, Tenancy(id="", name=f"prod-123"))
65-
self.assert_allowed(test_resource, Tenancy(id="", name=f"test-prod-2"))
66-
self.assert_denied(test_resource, Tenancy(id="", name=f"staging"))
64+
self.assert_allowed(test_resource, Tenancy(id="", name="prod-123"))
65+
self.assert_allowed(test_resource, Tenancy(id="", name="test-prod-2"))
66+
self.assert_denied(test_resource, Tenancy(id="", name="staging"))
6767

6868
# Check that filtering by denied name patterm works
6969
def test_deny_pattern(self):
7070
test_resource = {"metadata": {"annotations": {ACL_DENY_PATTERN_KEY: "prod-"}}}
7171
self.assert_denied(test_resource, Tenancy(id="", name="prod-123"))
72-
self.assert_denied(test_resource, Tenancy(id="", name=f"test-prod-2"))
73-
self.assert_allowed(test_resource, Tenancy(id="", name=f"staging-123"))
72+
self.assert_denied(test_resource, Tenancy(id="", name="test-prod-2"))
73+
self.assert_allowed(test_resource, Tenancy(id="", name="staging-123"))
7474

7575
# Check that presence of any 'allow' key triggers deny by default
7676
def test_default_deny_with_allows(self):

0 commit comments

Comments
 (0)