From 667df5b332a743f3d386199e45c8f1cf56076e06 Mon Sep 17 00:00:00 2001 From: Johnathan Clementi Date: Mon, 12 Aug 2024 12:43:54 -0400 Subject: [PATCH] Add test for no matching collection --- .../management/commands/controlled_lists.py | 4 ++-- tests/cli_tests.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/arches_references/management/commands/controlled_lists.py b/arches_references/management/commands/controlled_lists.py index d810229..e04530f 100644 --- a/arches_references/management/commands/controlled_lists.py +++ b/arches_references/management/commands/controlled_lists.py @@ -1,4 +1,4 @@ -from arches.app.models.models import Concept, Value +from arches.app.models.models import Value from django.core.management.base import BaseCommand @@ -99,7 +99,7 @@ def migrate_collections_to_controlled_lists( ] if len(failed_collections) > 0: - self.stdout.write( + self.stderr.write( "Failed to find the following collections in the database: %s" % ", ".join(failed_collections) ) diff --git a/tests/cli_tests.py b/tests/cli_tests.py index 293b199..8feb761 100644 --- a/tests/cli_tests.py +++ b/tests/cli_tests.py @@ -96,3 +96,18 @@ def test_migrate_collections_to_controlled_lists(self): imported_list = List.objects.get(name="Concept Label Import Test") imported_items = imported_list.list_items.all() self.assertEqual(len(imported_items), 3) + + def test_no_matching_collection_error(self): + expected_output = "Failed to find the following collections in the database: Collection That Doesn't Exist" + with captured_stdout() as output: + management.call_command( + "controlled_lists", + operation="migrate_collections_to_controlled_lists", + collections_to_migrate=["Collection That Doesn't Exist"], + host="http://localhost:8000/plugins/controlled-list-manager/item/", + preferred_sort_language="en", + overwrite=False, + stdout=output, + stderr=output, + ) + self.assertIn(expected_output, output.getvalue().strip())