From 85abbfbd96bda9701934c673560c7f2862843457 Mon Sep 17 00:00:00 2001 From: rasarkar <105652044+rasarkar@users.noreply.github.com> Date: Thu, 30 May 2024 09:51:05 -0400 Subject: [PATCH] CONCD-730 Unit tests for management commands (#2392) * CONCD-730 Unit tests for management commands (WiP) * CONCD-730 unit test for import_site_reports (WiP) * CONCD-730 added test csv file * CONCD-730 test case where row is missing campaign id * CONCD-730 unit test for ensure_initial_site_configuration management command --------- Co-authored-by: Jennifer Kuenning <72825410+jkueloc@users.noreply.github.com> --- concordia/tests/data/site_reports.csv | 3 ++ concordia/tests/test_management_commands.py | 39 +++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 concordia/tests/data/site_reports.csv create mode 100644 concordia/tests/test_management_commands.py diff --git a/concordia/tests/data/site_reports.csv b/concordia/tests/data/site_reports.csv new file mode 100644 index 000000000..6ae8130f0 --- /dev/null +++ b/concordia/tests/data/site_reports.csv @@ -0,0 +1,3 @@ +created_on,time,campaign +05/27/2024,10:13 PM UTC,1 +05/26/2024,10:12 PM UTC, diff --git a/concordia/tests/test_management_commands.py b/concordia/tests/test_management_commands.py new file mode 100644 index 000000000..672c4dce1 --- /dev/null +++ b/concordia/tests/test_management_commands.py @@ -0,0 +1,39 @@ +from io import StringIO + +from django.core.management import call_command +from django.test import TestCase + +from concordia.tests.utils import create_asset, create_campaign + + +class EnsureInitialSiteConfigurationTests(TestCase): + def test_command_output(self, *args, **kwargs): + out = StringIO() + call_command( + "ensure_initial_site_configuration", admin_email="admin@loc.gov", stdout=out + ) + call_command( + "ensure_initial_site_configuration", site_domain="crowd.loc.gov", stdout=out + ) + + +class ImportSiteReportsTests(TestCase): + def test_command_output(self, *args, **kwargs): + out = StringIO() + create_campaign(id=1) + call_command( + "import_site_reports", + csv_file="concordia/tests/data/site_reports.csv", + stdout=out, + ) + + +class PrintFrontendTestUrlsTests(TestCase): + def test_command_output(self, *args, **kwargs): + out = StringIO() + call_command("print_frontend_test_urls", stdout=out) + self.assertIn("", out.getvalue()) + + create_asset() + call_command("print_frontend_test_urls", stdout=out) + self.assertIn("", out.getvalue())