コード例 #1
0
ファイル: test_forms.py プロジェクト: abhiabhi94/idea-fare
    def test_last_name_alphabetic(self):
        """
        Test whether last name either accepts
            - accepts blank value
            - invalidates non alphabet values
                raises a validation error if it fails
        """
        field = 'last_name'
        data = ''
        form_1 = UserRegisterForm(data={field: data})

        self.assertFalse(form_1.is_valid())

        data = 'Bulb2'
        form_2 = UserRegisterForm(data={field: data})

        self.assertFalse(form_2.is_valid())
        self.assertEqual(
            form_2.has_error(field, code='invalid'),
            True,
            f'Are you sure {data} is a valid name. Names can only have alphabets.')

        data = '$Bulb_'
        form_3 = UserRegisterForm(data={field: data})
        self.assertFalse(form_3.is_valid())
        self.assertEqual(
            form_3.has_error(field, code='invalid'),
            True,
            msg=f'Are you sure {data} is a valid name. Names can only have alphabets.')
コード例 #2
0
ファイル: test_forms.py プロジェクト: abhiabhi94/idea-fare
    def test_username_anonymous_is_not_allowed(self):
        """Test whether email field invalidates dummy emails and raises a validation error"""
        field = 'username'

        form = UserRegisterForm(data={field: 'anonymous'})
        self.assertFalse(form.is_valid())
        self.assertEqual(form.has_error(field, code='invalid'), True, msg='This username is already taken')
コード例 #3
0
    def test_register_form_bad_email(self):
        test_data = self.register_form_data['bad_email']
        form_data = {k: test_data[k] for k in self.register_form_fields}

        form = UserRegisterForm(data=form_data)

        assert form.has_error('email') == True
        assert form.is_valid() == test_data['valid']
コード例 #4
0
    def test_register_form_duplicate(self):
        test_data = self.register_form_data['duplicate']
        form_data = {k: test_data[k] for k in self.register_form_fields}

        form = UserRegisterForm(data=form_data)

        assert form.has_error('username') == True
        assert form.is_valid() == test_data['valid']
コード例 #5
0
    def test_register_form_pass_mismatch(self):
        test_data = self.register_form_data['pass_mismatch']
        form_data = {k: test_data[k] for k in self.register_form_fields}

        form = UserRegisterForm(data=form_data)

        assert form.is_valid() == test_data['valid']
        assert form.has_error('password2') == True
        assert "password_mismatch" in form.error_messages
コード例 #6
0
ファイル: test_forms.py プロジェクト: abhiabhi94/idea-fare
    def test_first_name_alphabetic(self):
        """Test whether first name invalidates non alphabets and raises a validation error"""
        field = 'first_name'
        data = 'Bulb2'

        form_1 = UserRegisterForm(data={field: data})
        self.assertFalse(form_1.is_valid())
        self.assertEqual(
            form_1.has_error(field, code='invalid'),
            True,
            msg=f'Are you sure {data} is a valid name. Names can only have alphabets.')

        form_2 = UserRegisterForm(data={field: '$Bulb_'})
        self.assertFalse(form_2.is_valid())
        self.assertEqual(
            form_2.has_error(field, code='invalid'),
            True,
            msg=f'Are you sure {data} is a valid name. Names can only have alphabets.')
コード例 #7
0
ファイル: test_forms.py プロジェクト: abhiabhi94/idea-fare
    def test_email_invalidates_dummy_emails(self, mocked_attr):
        """Test whether email field invalidates dummy emails and raises a validation error"""
        mocked_attr.return_value = False
        field = 'email'
        data = '*****@*****.**'
        form = UserRegisterForm(data={field: data})

        self.assertFalse(form.is_valid())
        self.assertEqual(
            form.has_error(field, code='invalid'),
            True,
            msg=f'Are you sure %{data} is a valid email address? We suspect you made a typing error')