#36280: Replace cm.exception.messages with assertRaisesMessage() in tests
-------------------------------------+-------------------------------------
     Reporter:  Tim Graham           |                    Owner:  Georgii
         Type:                       |  (George) Randiuk
  Cleanup/optimization               |                   Status:  assigned
    Component:  Core (Other)         |                  Version:  dev
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Georgii (George) Randiuk):

 * has_patch:  0 => 1
 * needs_better_patch:  0 => 1


Old description:

> I haven't audited each instance, but most likely many of the uses of
> `cm.exception.messages` could be made more consistent with the rest of
> the Django test suite by instead using `self.assertRaisesMessage()`.
>
> {{{
> tests/composite_pk/test_models.py:
> self.assertSequenceEqual(ctx.exception.messages, messages)
> tests/composite_pk/test_models.py:            ctx.exception.messages,
> ("User with this Email already exists.",)
> tests/validation/test_error_messages.py:
> self.assertEqual(cm.exception.messages, expected)
> tests/auth_tests/test_validators.py:
> self.assertEqual(cm.exception.messages, [msg_too_short])
> tests/auth_tests/test_validators.py:            cm.exception.messages,
> ["This password is too common.", msg_too_short]
> tests/auth_tests/test_validators.py:
> self.assertEqual(cm.exception.messages, [expected_error % 8])
> tests/auth_tests/test_validators.py:
> self.assertEqual(cm.exception.messages, [expected_error % 3])
> tests/auth_tests/test_validators.py:
> self.assertEqual(cm.exception.messages, [expected_error % "username"])
> tests/auth_tests/test_validators.py:
> self.assertEqual(cm.exception.messages, [expected_error % "email
> address"])
> tests/auth_tests/test_validators.py:
> self.assertEqual(cm.exception.messages, [expected_error % "first name"])
> tests/auth_tests/test_validators.py:
> self.assertEqual(cm.exception.messages, [expected_error % "first name"])
> tests/auth_tests/test_validators.py:            cm.exception.messages,
> ["The password is too similar to the username."]
> tests/auth_tests/test_validators.py:
> self.assertEqual(cm.exception.messages, [expected_error])
> tests/auth_tests/test_validators.py:
> self.assertEqual(cm.exception.messages, [expected_error])
> tests/auth_tests/test_validators.py:
> self.assertEqual(cm.exception.messages, [expected_error])
> tests/auth_tests/test_validators.py:
> self.assertEqual(cm.exception.messages, [expected_error])
> tests/forms_tests/tests/test_error_messages.py:
> self.assertEqual(cm.exception.messages, expected)
> tests/forms_tests/tests/test_validators.py:        self.assertEqual(2,
> len(e.exception.messages))
> tests/test_exceptions/test_validation_error.py:
> self.assertEqual(sorted(exception.messages), [])
> tests/test_exceptions/test_validation_error.py:
> self.assertEqual(sorted(exception.messages), ["E1", "E2"])
> tests/test_exceptions/test_validation_error.py:
> self.assertEqual(sorted(exception.messages), ["E1", "E2", "E3", "E4"])
> tests/postgres_tests/test_array.py:            cm.exception.messages[0],
> tests/postgres_tests/test_array.py:            cm.exception.messages[0],
> "Nested arrays must have the same length."
> tests/postgres_tests/test_array.py:            cm.exception.messages[0],
> tests/postgres_tests/test_array.py:            cm.exception.messages[0],
> tests/postgres_tests/test_array.py:            cm.exception.messages[0],
> tests/postgres_tests/test_array.py:            cm.exception.messages[0],
> tests/postgres_tests/test_array.py:            cm.exception.messages[0],
> tests/postgres_tests/test_array.py:
> self.assertEqual(cm.exception.messages[0], "This field is required.")
> tests/postgres_tests/test_array.py:            cm.exception.messages,
> tests/postgres_tests/test_array.py:            cm.exception.messages,
> tests/postgres_tests/test_hstore.py:
> self.assertEqual(cm.exception.messages[0], "Could not load JSON data.")
> tests/postgres_tests/test_hstore.py:
> self.assertEqual(cm.exception.messages[0], "Some keys were missing: b")
> tests/postgres_tests/test_hstore.py:
> self.assertEqual(cm.exception.messages[0], "Some unknown keys were
> provided: c")
> tests/postgres_tests/test_hstore.py:
> self.assertEqual(cm.exception.messages[0], "Foobar")
> tests/postgres_tests/test_hstore.py:
> self.assertEqual(cm.exception.messages[0], "Some unknown keys were
> provided: c")
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], msg)
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], msg)
> tests/postgres_tests/test_ranges.py:            cm.exception.messages[0],
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], "Enter two whole numbers.")
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], "Enter a whole number.")
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], "Enter a whole number.")
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], "This field is required.")
> tests/postgres_tests/test_ranges.py:            cm.exception.messages[0],
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], "Enter two numbers.")
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], "Enter a number.")
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], "Enter a number.")
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], "This field is required.")
> tests/postgres_tests/test_ranges.py:            cm.exception.messages[0],
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], "Enter two valid dates.")
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], "Enter a valid date.")
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], "Enter a valid date.")
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], "This field is required.")
> tests/postgres_tests/test_ranges.py:            cm.exception.messages[0],
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], "Enter two valid date/times.")
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], "Enter a valid date/time.")
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], "Enter a valid date/time.")
> tests/postgres_tests/test_ranges.py:
> self.assertEqual(cm.exception.messages[0], "This field is required.")
> }}}

New description:

 I haven't audited each instance, but most likely many of the uses of
 `cm.exception.messages` could be made more consistent with the rest of the
 Django test suite by instead using `self.assertRaisesMessage()`.

 {{{
 tests/composite_pk/test_models.py:
 self.assertSequenceEqual(ctx.exception.messages, messages)
 tests/composite_pk/test_models.py:            ctx.exception.messages,
 ("User with this Email already exists.",)
 tests/validation/test_error_messages.py:
 self.assertEqual(cm.exception.messages, expected)
 tests/auth_tests/test_validators.py:
 self.assertEqual(cm.exception.messages, [msg_too_short])
 tests/auth_tests/test_validators.py:            cm.exception.messages,
 ["This password is too common.", msg_too_short]
 tests/auth_tests/test_validators.py:
 self.assertEqual(cm.exception.messages, [expected_error % 8])
 tests/auth_tests/test_validators.py:
 self.assertEqual(cm.exception.messages, [expected_error % 3])
 tests/auth_tests/test_validators.py:
 self.assertEqual(cm.exception.messages, [expected_error % "username"])
 tests/auth_tests/test_validators.py:
 self.assertEqual(cm.exception.messages, [expected_error % "email
 address"])
 tests/auth_tests/test_validators.py:
 self.assertEqual(cm.exception.messages, [expected_error % "first name"])
 tests/auth_tests/test_validators.py:
 self.assertEqual(cm.exception.messages, [expected_error % "first name"])
 tests/auth_tests/test_validators.py:            cm.exception.messages,
 ["The password is too similar to the username."]
 tests/auth_tests/test_validators.py:
 self.assertEqual(cm.exception.messages, [expected_error])
 tests/auth_tests/test_validators.py:
 self.assertEqual(cm.exception.messages, [expected_error])
 tests/auth_tests/test_validators.py:
 self.assertEqual(cm.exception.messages, [expected_error])
 tests/auth_tests/test_validators.py:
 self.assertEqual(cm.exception.messages, [expected_error])
 tests/forms_tests/tests/test_error_messages.py:
 self.assertEqual(cm.exception.messages, expected)
 tests/forms_tests/tests/test_validators.py:        self.assertEqual(2,
 len(e.exception.messages))
 tests/test_exceptions/test_validation_error.py:
 self.assertEqual(sorted(exception.messages), [])
 tests/test_exceptions/test_validation_error.py:
 self.assertEqual(sorted(exception.messages), ["E1", "E2"])
 tests/test_exceptions/test_validation_error.py:
 self.assertEqual(sorted(exception.messages), ["E1", "E2", "E3", "E4"])
 tests/postgres_tests/test_array.py:            cm.exception.messages[0],
 tests/postgres_tests/test_array.py:            cm.exception.messages[0],
 "Nested arrays must have the same length."
 tests/postgres_tests/test_array.py:            cm.exception.messages[0],
 tests/postgres_tests/test_array.py:            cm.exception.messages[0],
 tests/postgres_tests/test_array.py:            cm.exception.messages[0],
 tests/postgres_tests/test_array.py:            cm.exception.messages[0],
 tests/postgres_tests/test_array.py:            cm.exception.messages[0],
 tests/postgres_tests/test_array.py:
 self.assertEqual(cm.exception.messages[0], "This field is required.")
 tests/postgres_tests/test_array.py:            cm.exception.messages,
 tests/postgres_tests/test_array.py:            cm.exception.messages,
 tests/postgres_tests/test_hstore.py:
 self.assertEqual(cm.exception.messages[0], "Could not load JSON data.")
 tests/postgres_tests/test_hstore.py:
 self.assertEqual(cm.exception.messages[0], "Some keys were missing: b")
 tests/postgres_tests/test_hstore.py:
 self.assertEqual(cm.exception.messages[0], "Some unknown keys were
 provided: c")
 tests/postgres_tests/test_hstore.py:
 self.assertEqual(cm.exception.messages[0], "Foobar")
 tests/postgres_tests/test_hstore.py:
 self.assertEqual(cm.exception.messages[0], "Some unknown keys were
 provided: c")
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], msg)
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], msg)
 tests/postgres_tests/test_ranges.py:            cm.exception.messages[0],
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], "Enter two whole numbers.")
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], "Enter a whole number.")
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], "Enter a whole number.")
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], "This field is required.")
 tests/postgres_tests/test_ranges.py:            cm.exception.messages[0],
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], "Enter two numbers.")
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], "Enter a number.")
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], "Enter a number.")
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], "This field is required.")
 tests/postgres_tests/test_ranges.py:            cm.exception.messages[0],
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], "Enter two valid dates.")
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], "Enter a valid date.")
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], "Enter a valid date.")
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], "This field is required.")
 tests/postgres_tests/test_ranges.py:            cm.exception.messages[0],
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], "Enter two valid date/times.")
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], "Enter a valid date/time.")
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], "Enter a valid date/time.")
 tests/postgres_tests/test_ranges.py:
 self.assertEqual(cm.exception.messages[0], "This field is required.")
 }}}

 PR link: https://github.com/django/django/pull/19317

--
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36280#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070195e30a46cd-e7fde09c-6347-4e8f-847b-143aab4aab27-000000%40eu-central-1.amazonses.com.

Reply via email to