def test_valid_username(self):
        test_user = User(email=None,
                         user=username,
                         password=None,
                         confirm_password=None)

        self.assertTrue(RegisterForm(test_user).check_username_valid())
    def test_empty_password(self):
        test_user = User(email=email,
                         user=username,
                         password="",
                         confirm_password="")

        self.assertFalse(RegisterForm(test_user).check_password_valid())
    def test_username_more_than_max_length(self):
        test_user = User(email=email,
                         user="******",
                         password=password,
                         confirm_password=password)

        self.assertFalse(RegisterForm(test_user).check_username_valid())
Beispiel #4
0
def create_user():
    body_data = request.json

    email = body_data.get("email")
    username = body_data.get("username")
    password = body_data.get("password")
    confirm_password = body_data.get("confirm_password")

    user = User(email, username, password, confirm_password)
    new_user = RegisterForm(user)

    if new_user.check_email_valid() is False:
        return jsonify({"errors": [ErrorMessage.REGISTER["INVALID_EMAIL"]]}), 401

    if None or "" in (email, username, password, confirm_password):
        return jsonify({"errors": [ErrorMessage.REGISTER["INVALID_REQUEST"]]}), 400

    if new_user.check_username_exists() is True:
        return jsonify({"errors": [ErrorMessage.REGISTER["USERNAME_EXISTS"]]}), 409

    if new_user.validate() is False:
        return jsonify({"errors": [ErrorMessage.REGISTER["INVALID_CREDENTIALS"]]}), 401

    new_user.create_username()

    return jsonify(SuccessMessage(user).create_username()), 201
    def setUp(self):

        print(self._testMethodName)

        self.user = User(email=email,
                         user=username,
                         password=password,
                         confirm_password=password)
        RegisterForm(self.user).create_username()
 def test_valid_email(self):
     test_user = User(email=email,
                      user=None,
                      password=None,
                      confirm_password=None)
     self.assertTrue(RegisterForm(test_user).check_email_valid())