コード例 #1
0
ファイル: test_settings.py プロジェクト: wrestrtdr/Inboxen
    def test_form_good_data(self):
        username = self.user.username

        params = {"username": self.user.username + "1", "username2": self.user.username + "1"}
        form = UsernameChangeForm(data=params)

        self.assertTrue(form.is_valid(), form.errors)
        form.save()

        new_user = get_user_model().objects.get(pk=form.instance.pk)
        self.assertEqual(new_user.username, username + "1")
コード例 #2
0
ファイル: test_settings.py プロジェクト: Inboxen/Inboxen
    def test_form_good_data(self):
        username = self.user.username

        params = {"username": self.user.username + "1", "username2": self.user.username + "1"}
        form = UsernameChangeForm(data=params)

        self.assertTrue(form.is_valid(), form.errors)
        form.save()

        new_user = get_user_model().objects.get(pk=form.instance.pk)
        self.assertEqual(new_user.username, username + "1")
コード例 #3
0
ファイル: test_settings.py プロジェクト: Inboxen/Inboxen
    def test_form_bad_data(self):
        params = {"username": self.user.username, "username2": self.user.username}
        form = UsernameChangeForm(data=params)
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors["username"], [u"A user with that username already exists."])

        params = {"username": self.user.username + "1", "username2": self.user.username}
        form = UsernameChangeForm(data=params)
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors["username2"], [u"The two username fields don't match."])

        params = {"username": "******", "username2": "username\x00"}
        form = UsernameChangeForm(data=params)
        self.assertFalse(form.is_valid())
        self.assertEqual(
            form.errors["username"],
            [u"Enter a valid username. This value may contain only letters, numbers, and @/./+/-/_ characters."],
        )

        params = {"username": "******", "username2": "username€"}
        form = UsernameChangeForm(data=params)
        self.assertFalse(form.is_valid())
        expected_errors = [u"Enter a valid username. This value may contain only letters, numbers, and @/./+/-/_ characters."]  # noqa: E501
        self.assertEqual(form.errors["username"], expected_errors)
コード例 #4
0
ファイル: test_settings.py プロジェクト: wrestrtdr/Inboxen
    def test_form_bad_data(self):
        params = {"username": self.user.username, "username2": self.user.username}
        form = UsernameChangeForm(data=params)
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors["username"], [u"A user with that username already exists."])

        params = {"username": self.user.username + "1", "username2": self.user.username}
        form = UsernameChangeForm(data=params)
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors["username2"], [u"The two username fields don't match."])

        params = {"username": "******", "username2": "username\x00"}
        form = UsernameChangeForm(data=params)
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors["username"], [u"Null characters are not allowed."])

        params = {"username": "******", "username2": "username€"}
        form = UsernameChangeForm(data=params)
        self.assertFalse(form.is_valid())
        if six.PY3:
            expected_errors = [u"Enter a valid username. This value may contain only letters, numbers, and @/./+/-/_ characters."]  # noqa: E501
        else:
            expected_errors = [u"Enter a valid username. This value may contain only English letters, numbers, and @/./+/-/_ characters."]  # noqa: E501
        self.assertEqual(form.errors["username"], expected_errors)