fixed formatting and test with terminal prompting

This commit is contained in:
David Kennedy 2024-06-03 17:23:34 -04:00
parent 4ff60817da
commit 9ecb9f3556
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
2 changed files with 52 additions and 36 deletions

View file

@ -21,7 +21,7 @@ class Command(BaseCommand):
TerminalHelper.prompt_for_execution(
system_exit_on_terminate=True,
info_to_inspect=f"""
info_to_inspect="""
This script will delete all rows from the following tables:
* Contact
* Domain

View file

@ -788,6 +788,10 @@ class TestCleanTables(TestCase):
def test_command_logs_error_in_production(self):
"""Test that the handle method does not process in production"""
with less_console_noise():
with patch(
"registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa
return_value=True,
):
call_command("clean_tables")
self.logger_mock.error.assert_called_with("clean_tables cannot be run in production")
@ -799,6 +803,10 @@ class TestCleanTables(TestCase):
model_mock = MagicMock()
get_model_mock.return_value = model_mock
with patch(
"registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa
return_value=True,
):
call_command("clean_tables")
table_names = [
@ -826,6 +834,10 @@ class TestCleanTables(TestCase):
"""Test that exceptions for non existent models are handled properly within the handle method"""
with less_console_noise():
with patch("django.apps.apps.get_model", side_effect=LookupError):
with patch(
"registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa
return_value=True,
):
call_command("clean_tables")
# Assert that the error message was logged for any of the table names
self.logger_mock.error.assert_any_call("Model for table DomainInformation not found.")
@ -848,6 +860,10 @@ class TestCleanTables(TestCase):
get_model_mock.return_value = model_mock
model_mock.objects.all().delete.side_effect = Exception("Some error")
with patch(
"registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa
return_value=True,
):
call_command("clean_tables")
self.logger_mock.error.assert_any_call("Error cleaning table DomainInformation: Some error")