diff --git a/.github/workflows/lint-tests.yaml b/.github/workflows/lint-tests.yaml new file mode 100644 index 0000000..fcedae3 --- /dev/null +++ b/.github/workflows/lint-tests.yaml @@ -0,0 +1,97 @@ +name: Lint and tests +on: + workflow_dispatch: + pull_request: + push: + branches: + - "!release" + +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: false + +permissions: + contents: write + checks: write + pull-requests: write + +jobs: + lint: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install . + pip install .[dev] + pip install .[test] + - name: Build documentation + run: mkdocs build + - name: Lint with Ruff + run: | + ruff check --output-format=github netbox_branching/ + continue-on-error: true + tests: + runs-on: ubuntu-latest + timeout-minutes: 10 + strategy: + matrix: + python-version: [ "3.10", "3.11", "3.12" ] + services: + redis: + image: redis + ports: + - 6379:6379 + postgres: + image: postgres + env: + POSTGRES_USER: netbox + POSTGRES_PASSWORD: netbox + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + steps: + - name: Checkout netbox-branching + uses: actions/checkout@v4 + with: + path: netbox-branching + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Checkout netbox + uses: actions/checkout@v4 + with: + repository: "netbox-community/netbox" + path: netbox + - name: Install netbox-branching + working-directory: netbox-branching + run: | + # Include tests directory for test + sed -i 's/exclude-package-data/#exclude-package-data/g' pyproject.toml + python -m pip install --upgrade pip + pip install . + pip install .[test] + - name: Install dependencies & configure plugin + working-directory: netbox + run: | + ln -s $(pwd)/../netbox-branching/testing/configuration.py netbox/netbox/configuration.py + ln -s $(pwd)/../netbox-branching/testing/local_settings.py netbox/netbox/local_settings.py + + python -m pip install --upgrade pip + pip install -r requirements.txt -U + - name: Run tests + working-directory: netbox + run: | + python netbox/manage.py test netbox_branching.tests --keepdb diff --git a/testing/configuration.py b/testing/configuration.py new file mode 100644 index 0000000..2721e48 --- /dev/null +++ b/testing/configuration.py @@ -0,0 +1,38 @@ +################################################################### +# This file serves as a base configuration for testing purposes # +# only. It is not intended for production use. # +################################################################### + +ALLOWED_HOSTS = ["*"] + +DATABASE = { + "NAME": "netbox", + "USER": "netbox", + "PASSWORD": "netbox", + "HOST": "localhost", + "PORT": "", + "CONN_MAX_AGE": 300, +} + +PLUGINS = [ + "netbox_branching", +] + +REDIS = { + "tasks": { + "HOST": "localhost", + "PORT": 6379, + "PASSWORD": "", + "DATABASE": 0, + "SSL": False, + }, + "caching": { + "HOST": "localhost", + "PORT": 6379, + "PASSWORD": "", + "DATABASE": 1, + "SSL": False, + }, +} + +SECRET_KEY = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" diff --git a/testing/local_settings.py b/testing/local_settings.py new file mode 100644 index 0000000..10de74b --- /dev/null +++ b/testing/local_settings.py @@ -0,0 +1,12 @@ +from netbox_branching.utilities import DynamicSchemaDict +from .configuration import DATABASE + +# Wrap DATABASES with DynamicSchemaDict for dynamic schema support +DATABASES = DynamicSchemaDict({ + 'default': DATABASE, +}) + +# Employ our custom database router +DATABASE_ROUTERS = [ + 'netbox_branching.database.BranchAwareRouter', +]