Exemple #1
0
def test_new_user():
    username = "******"
    password = "******"
    role = "admin"
    user = User.new_user(username, password, role)
    assert user.username == "test-new"
    assert user.check_password(password)
    assert user.json()["username"] == username
    assert user.role == role
Exemple #2
0
    def post(self):
        args = self.parser.parse_args()

        username = args["username"]
        password = args["password"]
        role = args["role"]

        if role == None:
            role = "customer"

        if username == None or password == None:
            return error("Request must contain username and password.", 400)

        if not User.username_available(username):
            return error(f"Username '{username}' has been taken.", 400)

        try:
            user = User.new_user(username, password, role)
            db.session.add(user)
            db.session.commit()
            return user.json(), 201

        except Exception as e:
            return error(str(e), 400)
Exemple #3
0
def test_salt():
    a = User.new_user("a", "pass")
    b = User.new_user("b", "pass")
    assert a.hash != b.hash