Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #32900 -- Improved migrations questioner prompts. #14607

Closed
wants to merge 3 commits into from

Conversation

mateoradman
Copy link
Contributor

…ive voice and avoid personal pronouns.

@mateoradman mateoradman changed the title Refs #32900 - Rephrased migrations interactive questioner to use pass… Fixed #32900 - Rephrased migrations interactive questioner to use pass… Jul 7, 2021
django/db/migrations/questioner.py Outdated Show resolved Hide resolved
django/db/migrations/questioner.py Outdated Show resolved Hide resolved
django/db/migrations/questioner.py Outdated Show resolved Hide resolved
django/db/migrations/questioner.py Show resolved Hide resolved
@jacobtylerwalls
Copy link
Member

Hiya @mateoradman could you target the main branch? As a UX cleanup, this wouldn't qualify for a backport.

@mateoradman
Copy link
Contributor Author

Hiya @mateoradman could you target the main branch? As a UX cleanup, this wouldn't qualify for a backport.

Sure, no problem! 👍

@mateoradman mateoradman changed the base branch from stable/3.2.x to main July 8, 2021 20:44
@mateoradman mateoradman force-pushed the ticket_32900_django_v3.2 branch 2 times, most recently from d452cf7 to a4516a6 Compare July 8, 2021 20:53
@mateoradman
Copy link
Contributor Author

I think this one is ready to be merged. Thanks for everyone’s suggestions and involvement.

Copy link
Member

@felixxm felixxm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mateoradman Thanks for this patch 👍 I left comments.

django/db/migrations/questioner.py Outdated Show resolved Hide resolved
django/db/migrations/questioner.py Outdated Show resolved Hide resolved
django/db/migrations/questioner.py Outdated Show resolved Hide resolved
django/db/migrations/questioner.py Outdated Show resolved Hide resolved
django/db/migrations/questioner.py Outdated Show resolved Hide resolved
django/db/migrations/questioner.py Outdated Show resolved Hide resolved
django/db/migrations/questioner.py Outdated Show resolved Hide resolved
django/db/migrations/questioner.py Outdated Show resolved Hide resolved
tests/migrations/test_commands.py Outdated Show resolved Hide resolved
tests/migrations/test_questioner.py Outdated Show resolved Hide resolved
@felixxm felixxm self-assigned this Jul 14, 2021
@mateoradman mateoradman force-pushed the ticket_32900_django_v3.2 branch 3 times, most recently from b2e4d64 to 4585290 Compare July 17, 2021 07:57
@smithdc1
Copy link
Member

Hi @mateoradman -- thank you for your efforts here. 👍

If you've fixed all of the review comments you can untick 'needs tests' and 'needs improvement' on trac so it can go back into the review queue.

https://code.djangoproject.com/ticket/32900

@felixxm
Copy link
Member

felixxm commented Aug 19, 2021

I don't see any new tests requested in the #14607 (comment) 🤔

@mateoradman
Copy link
Contributor Author

I don't see any new tests requested in the #14607 (comment) 🤔

Hi @felixxm, I remember that I could not find any other message that can be tested here. If you identify that I missed something, please let me know and I will do it asap.

@jacobtylerwalls
Copy link
Member

Thanks for the quick reply. I was wondering, is this the blocker?

All the functions that contain messages either call sys.exit

If so, no biggie. Just also assert that it raises SystemExit. Something like...

diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index daeeaf8edb..621656429b 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -16,6 +16,7 @@ from django.db.backends.utils import truncate_name
 from django.db.migrations.exceptions import InconsistentMigrationHistory
 from django.db.migrations.recorder import MigrationRecorder
 from django.test import TestCase, override_settings, skipUnlessDBFeature
+from django.test.utils import captured_stdout
 
 from .models import UnicodeModel, UnserializableModel
 from .routers import TestRouter
@@ -1365,6 +1366,22 @@ class MakeMigrationsTests(MigrationTestBase):
             call_command("makemigrations", "migrations", interactive=False, stdout=out)
         self.assertIn("Alter field slug on author", out.getvalue())
 
+    @mock.patch('builtins.input', return_value='2')
+    def test_makemigrations_interactive_not_null_addition(self, mock):
+        class Entry(models.Model):
+            title = models.CharField(max_length=255)
+            archived = models.BooleanField(null=False)
+
+            class Meta:
+                app_label = 'migrations'
+
+        with captured_stdout() as out:
+            # this is the template you patch right above this, possibly find a better one
+            with self.temporary_migration_module(module='migrations.test_auto_now_add'):
+                with self.assertRaises(SystemExit):
+                    call_command('makemigrations', 'migrations', interactive=True)
+        self.assertIn('assertion will fail', out.getvalue())
+
     def test_makemigrations_non_interactive_no_model_rename(self):
         """
         makemigrations adds and removes a possible model rename in

Giving you the opportunity to assert against the messages you changed in this patch:

% python3 tests/runtests.py migrations -k test_makemigrations_interactive_not
Testing against Django installed in '...'
Found 1 test(s).
Creating test database for alias 'default'...
Creating test database for alias 'other'...
System check identified no issues (0 silenced).
F
======================================================================
FAIL: test_makemigrations_interactive_not_null_addition (migrations.test_commands.MakeMigrationsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "../django/tests/migrations/test_commands.py", line 1384, in test_makemigrations_interactive_not_null_addition
    self.assertIn('assertion will fail', out.getvalue())
AssertionError: 'assertion will fail' not found in "You are trying to add the field 'creation_date' with 'auto_now_add=True' to entry without a default; the database needs something to populate existing rows.\n\n 1) Provide a one-off default now (will be set on all existing rows)\n 2) Quit, and let me add a default in models.py\n"

----------------------------------------------------------------------
Ran 1 test in 0.014s

FAILED (failures=1)

The coverage report might be helpful for spotting what's not tested.

At least, that's where I would start. Thanks for giving this module some ❤️ !

@jacobtylerwalls
Copy link
Member

Thanks for the tests, Mateo. If the messages you've edited are now covered by your tests, could you uncheck Needs Tests on the ticket? Thanks.

@mateoradman
Copy link
Contributor Author

Don

Thanks for the tests, Mateo. If the messages you've edited are now covered by your tests, could you uncheck Needs Tests on the ticket? Thanks.

Done, thanks!

@felixxm felixxm changed the title Fixed #32900 - Rephrased migrations interactive questioner to use pass… Fixed #32900 -- Improved migrations questioner prompts. Aug 27, 2021
@felixxm
Copy link
Member

felixxm commented Aug 27, 2021

@mateoradman Thanks 👍

I reorganized commits and pushed edits to tests.

@felixxm
Copy link
Member

felixxm commented Aug 27, 2021

Merged in d00fb4d, 61c5eae, and 02bc716.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants