From 5df9f4e0a3793152d11af55fb506af42376af9ee Mon Sep 17 00:00:00 2001 From: Paul Traylor Date: Thu, 25 Jul 2024 16:19:03 +0900 Subject: [PATCH] Add a disabled exporter to our test case To ensure that disabled exporters are not rendered, we want to update our fixture with a disabled exporter, and ensure the rest of the tests still work. --- promgen/fixtures/testcases.yaml | 7 +++++++ promgen/tests/test_cli.py | 6 +++--- promgen/tests/test_routes.py | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/promgen/fixtures/testcases.yaml b/promgen/fixtures/testcases.yaml index 7ee469cee..31b0d427e 100644 --- a/promgen/fixtures/testcases.yaml +++ b/promgen/fixtures/testcases.yaml @@ -63,3 +63,10 @@ project: 1 job: node port: 9100 +- model: promgen.exporter + pk: 2 + fields: + project: 2 + job: node + port: 9100 + enabled: false diff --git a/promgen/tests/test_cli.py b/promgen/tests/test_cli.py index 5c14a16b4..b5cfd7b8a 100644 --- a/promgen/tests/test_cli.py +++ b/promgen/tests/test_cli.py @@ -22,15 +22,15 @@ def test_register_job(self, mock_signal): management.call_command("register-job", "test-project", "example", 1234) # Ensure the jobs we expect exist - self.assertCount(models.Exporter, 2, "Import a new exporter") + self.assertCount(models.Exporter, 3, "Import a new exporter") # Registering the same job again shouldn't change our count management.call_command("register-job", "test-project", "example", 1234) - self.assertCount(models.Exporter, 2, "Import additional exporter") + self.assertCount(models.Exporter, 3, "Import additional exporter") # But registering a new one will management.call_command("register-job", "test-project", "example", 4321) - self.assertCount(models.Exporter, 3, 'Import additional exporter') + self.assertCount(models.Exporter, 4, 'Import additional exporter') @mock.patch("promgen.signals._trigger_write_config") def test_register_host(self, mock_signal): diff --git a/promgen/tests/test_routes.py b/promgen/tests/test_routes.py index bb0b2e58f..32f05f2df 100644 --- a/promgen/tests/test_routes.py +++ b/promgen/tests/test_routes.py @@ -30,7 +30,7 @@ def test_import(self, mock_write, mock_reload): self.assertRoute(response, views.Import, 302, "Redirect to imported object") self.assertCount(models.Service, 3, "Import one service (Fixture has two services)") self.assertCount(models.Project, 4, "Import two projects") - self.assertCount(models.Exporter, 3, "Import two more exporters") + self.assertCount(models.Exporter, 4, "Import two more exporters") self.assertCount(models.Host, 3, "Import three hosts") @override_settings(PROMGEN=TEST_SETTINGS) @@ -50,7 +50,7 @@ def test_replace(self, mock_write, mock_reload): self.assertCount(models.Service, 3, "Import one service (Fixture has two services)") self.assertCount(models.Project, 4, "Import two projects (Fixture has 2 projectsa)") - self.assertCount(models.Exporter, 3, "Import two more exporters") + self.assertCount(models.Exporter, 4, "Import two more exporters") self.assertCount( models.Farm, 4, "Original two farms and one new farm (fixture has one farm)" )