django1/tests/migrations/test_questioner.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
1.2 KiB
Python
Raw Normal View History

import datetime
from unittest import mock
from django.db.migrations.questioner import (
InteractiveMigrationQuestioner,
MigrationQuestioner,
)
from django.db.models import NOT_PROVIDED
from django.test import SimpleTestCase
from django.test.utils import captured_stdout, override_settings
class QuestionerTests(SimpleTestCase):
@override_settings(
INSTALLED_APPS=["migrations"],
MIGRATION_MODULES={"migrations": None},
)
def test_ask_initial_with_disabled_migrations(self):
questioner = MigrationQuestioner()
self.assertIs(False, questioner.ask_initial("migrations"))
@mock.patch("builtins.input", return_value="datetime.timedelta(days=1)")
def test_timedelta_default(self, mock):
questioner = InteractiveMigrationQuestioner()
with captured_stdout():
value = questioner._ask_default()
self.assertEqual(value, datetime.timedelta(days=1))
@mock.patch("builtins.input", return_value="2")
def test_ask_not_null_alteration_not_provided(self, mock):
questioner = InteractiveMigrationQuestioner()
with captured_stdout():
question = questioner.ask_not_null_alteration("field_name", "model_name")
self.assertEqual(question, NOT_PROVIDED)