Skip to content
Snippets Groups Projects
Commit 5c5866e5 authored by Anders Harrisson's avatar Anders Harrisson
Browse files

Merge branch 'feature/INFRA-10376-unit-tests' into 'main'

create testing environment and 4 simple unit tests - INFRA-10376

Closes INFRA-10376

See merge request !3
parents 4c2a7665 e15d28e9
No related branches found
No related tags found
1 merge request!3create testing environment and 4 simple unit tests - INFRA-10376
Pipeline #199850 passed
......@@ -3,10 +3,10 @@ services:
netbox: &netbox
image: docker.io/netboxcommunity/netbox:v3.7.8
depends_on:
- postgres
- redis
- redis-cache
- netbox-worker
- postgres
- redis
- redis-cache
- netbox-worker
environment:
CORS_ORIGIN_ALLOW_ALL: "true"
DB_HOST: postgres
......@@ -59,12 +59,12 @@ services:
<<: *netbox
ports: []
depends_on:
- redis
- redis
entrypoint:
- /opt/netbox/venv/bin/python
- /opt/netbox/netbox/manage.py
- /opt/netbox/venv/bin/python
- /opt/netbox/netbox/manage.py
command:
- rqworker
- rqworker
postgres:
image: postgres:13-alpine
......@@ -78,20 +78,31 @@ services:
redis:
image: redis:6-alpine
command:
- sh
- -c
- redis-server --appendonly yes --requirepass $$REDIS_PASSWORD
- sh
- -c
- redis-server --appendonly yes --requirepass $$REDIS_PASSWORD
environment:
REDIS_PASSWORD: Choopike2aeBee1f
redis-cache:
image: redis:6-alpine
command:
- sh
- -c # this is to evaluate the $REDIS_PASSWORD from the env
- redis-server --requirepass $$REDIS_PASSWORD
- sh
- -c # this is to evaluate the $REDIS_PASSWORD from the env
- redis-server --requirepass $$REDIS_PASSWORD
environment:
REDIS_PASSWORD: eeCae8ai0hua4koK
# New test service for running unit tests
test:
<<: *netbox
depends_on:
- postgres
- redis
entrypoint:
- /opt/netbox/venv/bin/python
- /opt/netbox/netbox/manage.py
command: test netbox_awx_plugin
volumes:
netbox_database:
# netbox_awx_plugin/tests/test_models.py
from django.test import TestCase
from netbox_awx_plugin.models import AWX, AWXInventory
from django.urls import reverse
class AWXModelTestCase(TestCase):
def setUp(self):
self.awx_instance = AWX.objects.create(
name="Test AWX",
url="http://awx.example.com",
token="dummy-token"
)
def test_awx_str(self):
"""Test the string representation of the AWX model."""
self.assertEqual(str(self.awx_instance), "Test AWX")
def test_awx_get_absolute_url(self):
"""Test that get_absolute_url returns the correct URL."""
url = self.awx_instance.get_absolute_url()
expected_url = reverse("plugins:netbox_awx_plugin:awx", args=[self.awx_instance.pk])
self.assertEqual(url, expected_url)
def test_awx_get_headers(self):
"""Test that get_headers returns the correct headers."""
headers = self.awx_instance.get_headers()
expected_headers = {
"Authorization": "Bearer dummy-token",
"Content-type": "application/json",
}
self.assertEqual(headers, expected_headers)
class AWXInventoryModelTestCase(TestCase):
def setUp(self):
self.awx_instance = AWX.objects.create(
name="Test AWX",
url="http://awx.example.com",
token="dummy-token"
)
self.inventory = AWXInventory.objects.create(
awx=self.awx_instance,
inventory_id=1,
enabled=True
)
def test_inventory_get_absolute_url(self):
"""Test that get_absolute_url returns the correct URL."""
url = self.inventory.get_absolute_url()
expected_url = reverse("plugins:netbox_awx_plugin:awxinventory", args=[self.inventory.pk])
self.assertEqual(url, expected_url)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment