django-rest-framework icon indicating copy to clipboard operation
django-rest-framework copied to clipboard

Fix NullBooleanField deprecations in test suite

Open rpkilby opened this issue 5 years ago • 3 comments

Supersedes #7432.

Merged the field behavior tests for NullBooleanField and nullable BooleanField, as NullBooleanField no longer has a distinct implementation. Added separate tests for the deprecation warning and disallowed allow_null argument.

rpkilby avatar Aug 18 '20 03:08 rpkilby

How about something like this?

class TestNullBooleanField(TestCase):
    @pytest.mark.filterwarnings('ignore::rest_framework.RemovedInDRF314Warning')
    def test_allow_null(self):
        msg = '`allow_null` is not a valid option.'
        with self.assertRaisesMessage(AssertionError, msg):
            serializers.NullBooleanField(allow_null=False)

    def test_deprecation_warning(self):
        msg = "The `NullBooleanField` is deprecated"  # require full msg?
        with self.assertWarnsMessage(rest_framework.RemovedInDRF314Warning, msg):
            serializers.NullBooleanField()

Could also use the two assert....Message from pytest-django rather than subclassing from TestCase. 🤔

smithdc1 avatar Aug 18 '20 06:08 smithdc1

How have I never heard of assertWarns and assertWarnsMessage?? 😄 ✨

rpkilby avatar Aug 24 '20 10:08 rpkilby

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 02 '22 03:05 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 02 '23 23:04 stale[bot]

it is safe to close this now

auvipy avatar Apr 08 '23 15:04 auvipy