示例#1
0
async def test_create_user_as_supervisor(users, supervisor1_client):
    new_user = get_fake_user()
    new_user.pop("id")

    # Valid
    res = await supervisor1_client.post("/users", json=new_user)
    assert res.status == 200

    body = await res.json()
    assert "data" in body
    assert isinstance(body["data"], dict)

    all_users = await User.query.gino.all()
    assert len(all_users) == len(users) + 1
    assert profile_created_from_origin(new_user, all_users[-1].to_dict())

    # Valid
    new_user = get_fake_user()
    new_user.pop("id")
    res = await supervisor1_client.post("/users", json=new_user)
    assert res.status == 200

    body = await res.json()
    assert "data" in body
    assert isinstance(body["data"], dict)

    all_users = await User.query.gino.all()
    assert len(all_users) == len(users) + 2
    assert profile_created_from_origin(new_user, all_users[-1].to_dict())

    # Create an existing user
    res = await supervisor1_client.post("/users", json=new_user)
    assert res.status == 400
async def test_create_internal_id_users(supervisor1_client):
    """Ensure that `internal_id` cannot be created"""
    new_user = get_fake_user()
    new_user.pop("id")

    res = await supervisor1_client.post("/users", json={**new_user, "internal_id": 3})
    assert res.status == 400
示例#3
0
async def test_create_user_without_token(client):
    new_user = get_fake_user()
    new_user.pop("id")

    # Missing token
    res = await client.post("/users", json=new_user)
    assert res.status == 401
示例#4
0
        "is_anonymous": True
    },
    {
        "id": generate_uuid(),
        "name": "Visitor 1",
        "email": "*****@*****.**",
        "password": "******",
    },
    {
        "id": generate_uuid(),
        "name": "Visitor 2",
        "email": "*****@*****.**",
        "password": "******",
    },
]
users = [get_fake_user() for _ in range(number_of_users)]
users += [
    {
        "id": generate_uuid(),
        "full_name": "Agent 1",
        "email": "*****@*****.**",
        "password": "******",
        "disabled": False,
    },
    {
        "id": generate_uuid(),
        "full_name": "Agent 2",
        "email": "*****@*****.**",
        "password": "******",
        "disabled": False,
    },
示例#5
0
async def test_create_user_as_agent(agent1_client):
    # An agent cannot create another agent
    new_user = get_fake_user()
    new_user.pop("id")
    res = await agent1_client.post("/users", json=new_user)
    assert res.status == 403