diff --git a/.docker/docker-compose.yml b/.docker/docker-compose.yml index 007bf6f9e9d3a06f67e231667653d456eccefeb8..299a5fc1e11956c41a917884bfa22084e6a868b4 100644 --- a/.docker/docker-compose.yml +++ b/.docker/docker-compose.yml @@ -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: diff --git a/netbox_awx_plugin/tests/__init__.py b/netbox_awx_plugin/tests/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/netbox_awx_plugin/tests/test_models.py b/netbox_awx_plugin/tests/test_models.py new file mode 100644 index 0000000000000000000000000000000000000000..a95c8ed8b514ef531e4a2c66fcccfd6b2afa3d59 --- /dev/null +++ b/netbox_awx_plugin/tests/test_models.py @@ -0,0 +1,55 @@ +# 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)