mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-05 02:33:28 +02:00
fixed formatting and test with terminal prompting
This commit is contained in:
parent
4ff60817da
commit
9ecb9f3556
2 changed files with 52 additions and 36 deletions
|
@ -21,7 +21,7 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
TerminalHelper.prompt_for_execution(
|
TerminalHelper.prompt_for_execution(
|
||||||
system_exit_on_terminate=True,
|
system_exit_on_terminate=True,
|
||||||
info_to_inspect=f"""
|
info_to_inspect="""
|
||||||
This script will delete all rows from the following tables:
|
This script will delete all rows from the following tables:
|
||||||
* Contact
|
* Contact
|
||||||
* Domain
|
* Domain
|
||||||
|
|
|
@ -788,6 +788,10 @@ class TestCleanTables(TestCase):
|
||||||
def test_command_logs_error_in_production(self):
|
def test_command_logs_error_in_production(self):
|
||||||
"""Test that the handle method does not process in production"""
|
"""Test that the handle method does not process in production"""
|
||||||
with less_console_noise():
|
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")
|
call_command("clean_tables")
|
||||||
self.logger_mock.error.assert_called_with("clean_tables cannot be run in production")
|
self.logger_mock.error.assert_called_with("clean_tables cannot be run in production")
|
||||||
|
|
||||||
|
@ -799,6 +803,10 @@ class TestCleanTables(TestCase):
|
||||||
model_mock = MagicMock()
|
model_mock = MagicMock()
|
||||||
get_model_mock.return_value = model_mock
|
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")
|
call_command("clean_tables")
|
||||||
|
|
||||||
table_names = [
|
table_names = [
|
||||||
|
@ -826,6 +834,10 @@ class TestCleanTables(TestCase):
|
||||||
"""Test that exceptions for non existent models are handled properly within the handle method"""
|
"""Test that exceptions for non existent models are handled properly within the handle method"""
|
||||||
with less_console_noise():
|
with less_console_noise():
|
||||||
with patch("django.apps.apps.get_model", side_effect=LookupError):
|
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")
|
call_command("clean_tables")
|
||||||
# Assert that the error message was logged for any of the table names
|
# 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.")
|
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
|
get_model_mock.return_value = model_mock
|
||||||
model_mock.objects.all().delete.side_effect = Exception("Some error")
|
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")
|
call_command("clean_tables")
|
||||||
|
|
||||||
self.logger_mock.error.assert_any_call("Error cleaning table DomainInformation: Some error")
|
self.logger_mock.error.assert_any_call("Error cleaning table DomainInformation: Some error")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue