예제 #1
0
    def test_signin_form(self):
        """
        Check that the ``SigninForm`` requires both identification and password

        """
        invalid_data_dicts = [
            {'data': {'identification': '',
                      'password': '******'},
             'error': ('identification', ['Either supply us with your email or username.'])},
            {'data': {'identification': 'john',
                      'password': '******'},
             'error': ('__all__', ['Please enter a correct username or email and password. Note that both fields are case-sensitive.'])}
        ]

        # Override locale settings since we are checking for existence of error
        # messaged written in english. Note: it should not be necessasy but
        # we have experienced such locale issues during tests on Travis builds.
        # See: https://github.com/bread-and-pepper/django-userena/issues/446
        with override('en'):
            for invalid_dict in invalid_data_dicts:
                form = forms.AuthenticationForm(data=invalid_dict['data'])
                self.assertFalse(form.is_valid())
                self.assertEqual(form.errors[invalid_dict['error'][0]],
                                 invalid_dict['error'][1])

        valid_data_dicts = [
            {'identification': 'john',
             'password': '******'},
            {'identification': '*****@*****.**',
             'password': '******'}
        ]

        for valid_dict in valid_data_dicts:
            form = forms.AuthenticationForm(valid_dict)
            self.assertTrue(form.is_valid())
예제 #2
0
    def test_signin_form(self):
        """
        Check that the ``SigninForm`` requires both identification and password

        """
        invalid_data_dicts = [{
            'data': {
                'identification': '',
                'password': '******'
            },
            'error': ('identification', [u'Please supply your email.'])
        }, {
            'data': {
                'identification': 'john',
                'password': '******'
            },
            'error': ('__all__', [
                u'Please enter a correct email and password. Note that fields are case-sensitive.'
            ])
        }]

        for invalid_dict in invalid_data_dicts:
            form = forms.AuthenticationForm(data=invalid_dict['data'])
            self.failIf(form.is_valid())
            self.assertEqual(form.errors[invalid_dict['error'][0]],
                             invalid_dict['error'][1])

        valid_data_dicts = [{
            'identification': '*****@*****.**',
            'password': '******'
        }]

        for valid_dict in valid_data_dicts:
            form = forms.AuthenticationForm(valid_dict)
            self.failUnless(form.is_valid())
예제 #3
0
    def test_signin_form(self):
        """
        Check that the ``SigninForm`` requires both identification and password

        """
        invalid_data_dicts = [
            {
                "data": {
                    "identification": "",
                    "password": "******"
                },
                "error": (
                    "identification",
                    ["Either supply us with your email or username."],
                ),
            },
            {
                "data": {
                    "identification": "john",
                    "password": "******"
                },
                "error": (
                    "__all__",
                    [
                        "Please enter a correct username or email and password. Note that both fields are case-sensitive."
                    ],
                ),
            },
        ]

        # Override locale settings since we are checking for existence of error
        # messaged written in english. Note: it should not be necessasy but
        # we have experienced such locale issues during tests on Travis builds.
        # See: https://github.com/bread-and-pepper/django-userena/issues/446
        with override("en"):
            for invalid_dict in invalid_data_dicts:
                form = forms.AuthenticationForm(data=invalid_dict["data"])
                self.assertFalse(form.is_valid())
                self.assertEqual(form.errors[invalid_dict["error"][0]],
                                 invalid_dict["error"][1])

        valid_data_dicts = [
            {
                "identification": "john",
                "password": "******"
            },
            {
                "identification": "*****@*****.**",
                "password": "******"
            },
        ]

        for valid_dict in valid_data_dicts:
            form = forms.AuthenticationForm(valid_dict)
            self.assertTrue(form.is_valid())
예제 #4
0
    def test_signin_form_email(self):
        """
        Test that the signin form has a different label is
        ``USERENA_WITHOUT_USERNAME`` is set to ``True``

        """
        userena_settings.USERENA_WITHOUT_USERNAMES = True

        form = forms.AuthenticationForm(data={'identification': "john",
                                              'password': "******"})

        correct_label = "Email"
        self.assertEqual(form.fields['identification'].label,
                         correct_label)

        # Restore default settings
        userena_settings.USERENA_WITHOUT_USERNAMES = False