Exemplo n.º 1
0
Arquivo: tests.py Projeto: kfarr2/ITS
    def test_clean_errors(self):

        """
        Tests that the clean method does return errors when
        the form is filled out incorrectly.
        """

        data = {
            "possible_owner_found": "1",
            "first_name": "",
            "last_name": "",
            "email": "",
            "username": "******"
        }

        with patch("its.items.forms.ModelForm.clean", return_value=data):
            with patch("its.items.forms.check_ldap", return_value=False):
                with patch("its.items.forms.CheckInForm.add_error") as add_error:
                    form = CheckInForm()
                    form.clean()
                    add_error.assert_any_call_with("first_name", "First name required")
                    add_error.assert_any_call_with("last_name", "Last name required")
                    add_error.assert_any_call_with("email", "Email required")
                    add_error.assert_any_call_with("username", "Invalid username, enter a valid username or leave blank.")
Exemplo n.º 2
0
Arquivo: tests.py Projeto: kfarr2/ITS
    def test_clean_no_errors(self):

        """
        Tests that the clean method does not return errors when
        the form is filled out correctly.
        """

        data = {"possible_owner_found": "1",
                "first_name": "Test",
                "last_name": "Test",
                "email": "*****@*****.**",
                "username": "******", }

        with patch('its.items.forms.ModelForm.clean', return_value=data):
            with patch('its.items.forms.check_ldap', return_value=True):
                form = CheckInForm()
                form.cleaned_data = form.clean()
                self.assertTrue(form.cleaned_data['possible_owner_found'] == data['possible_owner_found'])
                self.assertTrue(form.cleaned_data['username'] == data['username'])
                self.assertTrue(form.cleaned_data['first_name'] == data['first_name'])
                self.assertTrue(form.cleaned_data['last_name'] == data['last_name'])
                self.assertTrue(form.cleaned_data['email'] == data['email'])