Beispiel #1
0
    def test_reg_passmatch(self):
        tmp = dict(MOCK_REGISTER_DATA)
        tmp["username"] += "_new"
        tmp["password_confirm"] = "bad match"
        reg = RegisterForm(tmp)

        self.assertEqual(reg.is_valid(), False)
        self.assertTrue(errors.get_error(
            "register_password_mismatch") in reg.errors.get("password"))
        self.assertTrue(errors.get_error(
            "register_password_mismatch") in reg.errors.get("password_confirm"))
Beispiel #2
0
    def test_reg_passmatch(self):
        tmp = dict(MOCK_REGISTER_DATA)
        tmp["username"] += "_new"
        tmp["password_confirm"] = "bad match"
        reg = RegisterForm(tmp)

        self.assertEqual(reg.is_valid(), False)
        self.assertTrue(
            errors.get_error("register_password_mismatch") in reg.errors.get(
                "password"))
        self.assertTrue(
            errors.get_error("register_password_mismatch") in reg.errors.get(
                "password_confirm"))
Beispiel #3
0
    def wrapper(request, *args):
        if "authorized" not in request.session:
            return HttpResponse(
                jsonify(errors.make_error(errors.get_error("auth"), 403,
                                          None)))

        return fn(request, *args)
Beispiel #4
0
    def clean(self):
        cleaned_data = super(forms.Form, self).clean()
        self.error_code = 200

        if cleaned_data["password"] != cleaned_data["password_confirm"]:
            self.add_error("password", forms.ValidationError(
                errors.get_error("register_password_mismatch")))
            self.add_error("password_confirm", forms.ValidationError(
                errors.get_error("register_password_mismatch")))
            self.error_code = 409   # Conflict

        else:
            tmp = dict(cleaned_data)
            tmp.pop("password_confirm")
            cleaned_data["user_object"] = models.User.objects.create(**tmp)

        return cleaned_data
Beispiel #5
0
    def test_login_badusername(self):
        login = LoginForm({
            "username": "******",
            "password": MOCK_USER_DATA["password"]
        })

        self.assertEqual(login.is_valid(), False)
        self.assertTrue(errors.get_error("login") in login.errors.get("__all__"))
Beispiel #6
0
    def clean_username(self):
        if models.User.objects.filter(
            username=self.cleaned_data["username"]
        ).count() != 0:
            self.error_code = 409    # Conflict
            raise forms.ValidationError(
                errors.get_error("register_username_exists"))

        return self.cleaned_data["username"]
Beispiel #7
0
    def test_login_badusername(self):
        login = LoginForm({
            "username": "******",
            "password": MOCK_USER_DATA["password"]
        })

        self.assertEqual(login.is_valid(), False)
        self.assertTrue(
            errors.get_error("login") in login.errors.get("__all__"))
Beispiel #8
0
    def test_reg_userexists(self):
        # First, register a user.
        self.test_register_works()

        # Then, try to register a user with the same name.
        reg = RegisterForm(MOCK_REGISTER_DATA)

        self.assertEqual(reg.is_valid(), False)
        self.assertTrue(errors.get_error(
            "register_username_exists") in reg.errors.get("username"))
Beispiel #9
0
    def test_reg_userexists(self):
        # First, register a user.
        self.test_register_works()

        # Then, try to register a user with the same name.
        reg = RegisterForm(MOCK_REGISTER_DATA)

        self.assertEqual(reg.is_valid(), False)
        self.assertTrue(
            errors.get_error("register_username_exists") in reg.errors.get(
                "username"))
Beispiel #10
0
    def clean(self):
        cleaned_data = super(forms.Form, self).clean()

        try:
            user = models.User.objects.get(
                username=cleaned_data.get("username"),
                password=cleaned_data.get("password"))
            cleaned_data["user_object"] = user

        except models.User.DoesNotExist:
            raise forms.ValidationError(errors.get_error("login"))

        return cleaned_data
Beispiel #11
0
    def test_login_view_notok(self):
        client = RequestFactory()
        response = client.post("/login", {
            "username": MOCK_USER_DATA["username"],
            "password": "******"
        })

        self.assertNotEqual(views.login(response).content,
                            self.user.asJSON().encode())
        self.assertEqual(views.login(response).content,
                         utils.jsonify(errors.make_error(
                            errors.get_error("login"),
                            401,
                            None)).encode())
Beispiel #12
0
    def test_login_view_notok(self):
        client = RequestFactory()
        response = client.post("/login", {
            "username": MOCK_USER_DATA["username"],
            "password": "******"
        })

        self.assertNotEqual(
            views.login(response).content,
            self.user.asJSON().encode())
        self.assertEqual(
            views.login(response).content,
            utils.jsonify(
                errors.make_error(errors.get_error("login"), 401,
                                  None)).encode())
Beispiel #13
0
    def wrapper(request, *args):
        if "authorized" not in request.session:
            return HttpResponse(jsonify(
                errors.make_error(errors.get_error("auth"), 403, None)))

        return fn(request, *args)