Skip to content
Snippets Groups Projects
Commit e15d28e9 authored by Fahrudin Halilovic's avatar Fahrudin Halilovic
Browse files

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

parent 4c2a7665
No related branches found
No related tags found
1 merge request!3create testing environment and 4 simple unit tests - INFRA-10376
Pipeline #199846 passed
...@@ -3,10 +3,10 @@ services: ...@@ -3,10 +3,10 @@ services:
netbox: &netbox netbox: &netbox
image: docker.io/netboxcommunity/netbox:v3.7.8 image: docker.io/netboxcommunity/netbox:v3.7.8
depends_on: depends_on:
- postgres - postgres
- redis - redis
- redis-cache - redis-cache
- netbox-worker - netbox-worker
environment: environment:
CORS_ORIGIN_ALLOW_ALL: "true" CORS_ORIGIN_ALLOW_ALL: "true"
DB_HOST: postgres DB_HOST: postgres
...@@ -59,12 +59,12 @@ services: ...@@ -59,12 +59,12 @@ services:
<<: *netbox <<: *netbox
ports: [] ports: []
depends_on: depends_on:
- redis - redis
entrypoint: entrypoint:
- /opt/netbox/venv/bin/python - /opt/netbox/venv/bin/python
- /opt/netbox/netbox/manage.py - /opt/netbox/netbox/manage.py
command: command:
- rqworker - rqworker
postgres: postgres:
image: postgres:13-alpine image: postgres:13-alpine
...@@ -78,20 +78,31 @@ services: ...@@ -78,20 +78,31 @@ services:
redis: redis:
image: redis:6-alpine image: redis:6-alpine
command: command:
- sh - sh
- -c - -c
- redis-server --appendonly yes --requirepass $$REDIS_PASSWORD - redis-server --appendonly yes --requirepass $$REDIS_PASSWORD
environment: environment:
REDIS_PASSWORD: Choopike2aeBee1f REDIS_PASSWORD: Choopike2aeBee1f
redis-cache: redis-cache:
image: redis:6-alpine image: redis:6-alpine
command: command:
- sh - sh
- -c # this is to evaluate the $REDIS_PASSWORD from the env - -c # this is to evaluate the $REDIS_PASSWORD from the env
- redis-server --requirepass $$REDIS_PASSWORD - redis-server --requirepass $$REDIS_PASSWORD
environment: environment:
REDIS_PASSWORD: eeCae8ai0hua4koK 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: volumes:
netbox_database: 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