Пример #1
0
    def test_create_user_duplicate_fail(self):

        email = "*****@*****.**"
        name = ("Ima Test", )
        group_name = ("Ima Test Group", )
        hashed_password = "******"
        admin = True
        user.create(self.database, email, name, group_name, hashed_password,
                    admin)

        with pytest.raises(psycopg2.errors.UniqueViolation):
            user.create(self.database, email, name, group_name,
                        hashed_password, admin)
Пример #2
0
    def create_test_user(self, user_key):

        create_result = user_db_util.create(
            g.database, self.user_data[user_key]["email"],
            self.user_data[user_key]["name"],
            self.user_data[user_key]["group_name"],
            self.user_data[user_key]["hashed_password"],
            self.user_data[user_key]["admin"])
        self.user_data[user_key]["user_id"] = create_result["user_id"]
Пример #3
0
    def post(self):
        """
        Create a new user with provided email, password, and admin flag.
        - If required fields are missing in the request, return 400
        - Password must be 8 or more characters long. Otherwise return 422
        - Email must not already be in use by an existing user.
          Otherwise return 422
        - If success, return 201 with the new user's email, admin flag,
          and creation timestamp.
        """

        data = request.get_json()

        if data is None:
            error(400, "No json data in request body")

        check_data_fields(data,
                          ["email", "name", "group_name", "password", "admin"])

        if len(data["password"]) < 8:
            error(422, "New password is less than 8 characters long!")

        password_hash = generate_password_hash(data["password"])

        try:
            create_user_result = user_db_util.create(
                g.database,
                email=data["email"],
                name=data["name"],
                group_name=data["group_name"],
                password_hash=password_hash,
                admin=data["admin"],
            )

        except UniqueViolation:
            error(422, "User with that email address already exists")

        response_data = {
            "user_id": create_user_result["user_id"],
            "email": create_user_result["email"],
            "admin": create_user_result["admin"],
            "name": create_user_result["name"],
            "group_name": create_user_result["group_name"],
            "timestamp": create_user_result["date_created"],
        }

        return jsonify(response_data), 201
Пример #4
0
    def test_create_user_success(self):

        email = "*****@*****.**"
        name = "Ima Test"
        group_name = "Ima Test Group"
        hashed_password = "******"
        admin = True
        create_result = user.create(self.database, email, name, group_name,
                                    hashed_password, admin)

        assert create_result["email"] == email
        assert create_result["hashed_password"] == hashed_password
        assert create_result["name"] == name
        assert create_result["group_name"] == group_name
        assert create_result["admin"] == admin
        assert create_result["user_id"]
        assert create_result["auth_id"]
        assert create_result["date_created"]
        assert create_result["date_modified"]

        self.verify_user_data(email, name, group_name, hashed_password, admin)
Пример #5
0
    def test_create_user_success(self):

        email = "*****@*****.**"
        name = "Ima Test"
        group_name = "Ima Test Group"
        hashed_password = "******"
        admin = True
        create_result = user.create(self.database, email, name, group_name,
                                    hashed_password, admin)

        assert create_result['email'] == email
        assert create_result['hashed_password'] == hashed_password
        assert create_result['name'] == name
        assert create_result['group_name'] == group_name
        assert create_result['admin'] == admin
        assert create_result['user_id']
        assert create_result['auth_id']
        assert create_result['date_created']
        assert create_result['date_modified']

        self.verify_user_data(email, name, group_name, hashed_password, admin)