python-restx / flask-restx

Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
https://flask-restx.readthedocs.io/en/latest/
Other
2.14k stars 333 forks source link

Unit Test "EmailTest.test_invalid_values_check" is failing #602

Closed StellaContrail closed 1 month ago

StellaContrail commented 4 months ago

Summary

The unit test case "EmailTest.test_invalid_values_check" fails because the not-found .fr was registered a few weeks ago and doesn't throw a ValueError exception anymore. This affects the CI process. (Tests #2026)

For test cases, reserved domain names should be used instead, as described in RFC 2606.

Code

The EmailTest.test_invalid_values_check testcase expects all the domain names to be invalid although the not-found .fr one is actually valid. (ICANN Lookup)

    @pytest.mark.parametrize(
        "value",
        [
            "coucou@not-found.fr",
            "me@localhost",
            "me@127.0.0.1",
            "me@127.1.2.3",
            "me@::1",
            "me@200.8.9.10",
            "me@2001:db8:85a3::8a2e:370:7334",
        ],
    )
    def test_invalid_values_check(self, value):
        email = inputs.email(check=True)
        self.assert_bad_email(email, value)

Expected Behavior

All unit tests should be passing.

Actual Behavior

The EmailTest.test_invalid_values_check testcase fails.

Error Messages/Stack Trace

Here's a partial result from tox command.

======================================================= FAILURES =======================================================
_______________________________ EmailTest.test_invalid_values_check[coucou@not-found.fr] _______________________________

self = <tests.test_inputs.EmailTest object at 0x7f5816d65150>, value = 'coucou@not-found.fr'

    @pytest.mark.parametrize(
        "value",
        [
            "coucou@not-found.fr",
            "me@localhost",
            "me@127.0.0.1",
            "me@127.1.2.3",
            "me@::1",
            "me@200.8.9.10",
            "me@2001:db8:85a3::8a2e:370:7334",
        ],
    )
    def test_invalid_values_check(self, value):
        email = inputs.email(check=True)
>       self.assert_bad_email(email, value)

tests/test_inputs.py:667:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <tests.test_inputs.EmailTest object at 0x7f5816d65150>
validator = <flask_restx.inputs.email object at 0x7f5816d648b0>, value = 'coucou@not-found.fr'
msg = '{0} is not a valid email'

    def assert_bad_email(self, validator, value, msg=None):
        msg = msg or "{0} is not a valid email"
>       with pytest.raises(ValueError) as cm:
E       Failed: DID NOT RAISE <class 'ValueError'>

tests/test_inputs.py:605: Failed

Environment

Additional Context

StellaContrail commented 4 months ago

Lint fix also included, so all checks can pass before merging.