-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Run tests under netbox | ||
on: [push] | ||
jobs: | ||
test-netbox: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
netbox-version: ["v3.6.7"] | ||
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 | ||
pdns: | ||
image: powerdns/pdns-auth-master | ||
env: | ||
PDNS_AUTH_API_KEY: 1234567890a | ||
ports: | ||
- 8081:8081 | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
with: | ||
path: netbox-inventory | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Checkout netbox ${{ matrix.netbox-version }} | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: "netbox-community/netbox" | ||
ref: ${{ matrix.netbox-version }} | ||
path: netbox | ||
|
||
- name: install netbox_powerdns_sync | ||
working-directory: netbox-powerdns-sync | ||
run: | | ||
pip install . | ||
- name: Install dependencies & set up configuration | ||
working-directory: netbox | ||
run: | | ||
ln -s $(pwd)/../netbox-powerdns-sync/testing/configuration.testing.py netbox/netbox/configuration.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_powerdns_sync.tests -v 2 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#### | ||
#### Taken from https://github.com/auroraresearchlab/netbox-dns/blob/main/netbox_dns/tests/custom.py | ||
#### | ||
#### Makes it so Netbox test utils work with plugins | ||
#### | ||
|
||
from django.urls import reverse | ||
|
||
from utilities.testing.api import APITestCase as NetBoxAPITestCase | ||
from utilities.testing.views import ModelViewTestCase as NetBoxModelViewTestCase | ||
|
||
|
||
class ModelViewTestCase(NetBoxModelViewTestCase): | ||
""" | ||
Customized ModelViewTestCase for work with plugins | ||
""" | ||
|
||
def _get_base_url(self): | ||
""" | ||
Return the base format for a URL for the test's model. Override this to test for a model which belongs | ||
to a different app (e.g. testing Interfaces within the virtualization app). | ||
""" | ||
return ( | ||
f"plugins:{self.model._meta.app_label}:{self.model._meta.model_name}_{{}}" | ||
) | ||
|
||
|
||
class APITestCase(NetBoxAPITestCase): | ||
""" | ||
Customized APITestCase for work with plugins | ||
""" | ||
|
||
def _get_detail_url(self, instance): | ||
viewname = f"plugins-api:{self._get_view_namespace()}:{instance._meta.model_name}-detail" | ||
return reverse(viewname, kwargs={"pk": instance.pk}) | ||
|
||
def _get_list_url(self): | ||
viewname = f"plugins-api:{self._get_view_namespace()}:{self.model._meta.model_name}-list" | ||
return reverse(viewname) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from django.urls import reverse | ||
from django.test import SimpleTestCase | ||
|
||
from netbox_powerdns_sync import __version__ | ||
from netbox_powerdns_sync.tests.custom import APITestCase | ||
|
||
|
||
class NetboxDnsVersionTestCase(SimpleTestCase): | ||
""" | ||
Test for netbox_inventory package | ||
""" | ||
|
||
def test_version(self): | ||
assert __version__ == "0.0.8" | ||
|
||
|
||
class AppTest(APITestCase): | ||
""" | ||
Test the availability of the plugin API root | ||
""" | ||
|
||
def test_root(self): | ||
url = reverse("plugins-api:netbox_powerdns_sync-api:api-root") | ||
response = self.client.get(f"{url}?format=api", **self.header) | ||
|
||
self.assertEqual(response.status_code, 200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
##################################### | ||
# # | ||
# Config used to run unit tests # | ||
# # | ||
##################################### | ||
|
||
ALLOWED_HOSTS = ["*",] | ||
|
||
DATABASE = { | ||
'NAME': 'netbox', # Database name | ||
'USER': 'netbox', # PostgreSQL username | ||
'PASSWORD': 'netbox', # PostgreSQL password | ||
'HOST': 'localhost', # Database server | ||
'PORT': '', # Database port (leave blank for default) | ||
'CONN_MAX_AGE': 300, # Max database connection age | ||
} | ||
|
||
REDIS = { | ||
'tasks': { | ||
'HOST': 'localhost', | ||
'PORT': 6379, | ||
'PASSWORD': '', | ||
'DATABASE': 0, | ||
'SSL': False, | ||
}, | ||
'caching': { | ||
'HOST': 'localhost', | ||
'PORT': 6379, | ||
'PASSWORD': '', | ||
'DATABASE': 1, | ||
'SSL': False, | ||
} | ||
} | ||
|
||
SECRET_KEY = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' | ||
|
||
PLUGINS = [ | ||
'netbox_powerdns_sync', | ||
] |