Beispiel #1
0
def add_user(email, password):
    """
    添加用户
    """
    user = User()
    user.email = email
    user.salt = random_str(6)
    user.password = password_encrypt(password, user.salt)
    db_session.add(user)
    db_session.commit()
    return user
def test_create_user_with_used_email(_not_logged_in_client):
    user_name = "test_register5"
    with session_scope() as db_session:
        try:
            user = User()
            user.user = user_name
            user.argon_password = "******"
            user.email = "*****@*****.**"
            payload = user.as_dict()
            payload["confirmation_url"] = "http://phenopolis.org/confirm/"
            response = _not_logged_in_client.post(
                "/user", json=payload, content_type="application/json")
            assert response.status_code == 500
        finally:
            # cleans the database
            _clean_test_users(db_session, user_name)
def test_delete_user(_admin_client):
    user_name = "test_register6"
    with session_scope() as db_session:
        user = User()
        user.user = user_name
        user.argon_password = "******"
        user.email = "*****@*****.**"
        _assert_create_user(db_session, _admin_client, user)

        # deletes user
        response = _admin_client.delete(f"/user/{user_name}",
                                        content_type="application/json")
        assert response.status_code == 200

        # confirms it does not exist
        o_user = db_session.query(User).filter(User.user == user_name).first()
        assert o_user is None, "Deletion was not successful"

        # try to delete non-existent user
        response = _admin_client.delete("/user/not_me",
                                        content_type="application/json")
        assert response.status_code == 404