コード例 #1
0
def test_user_registration(collection, session):
    # given
    user = UserDataFactory()

    session.set_response({'user': user})

    # When
    created_user = collection.register(screen_name=user["screen_name"],
                                       email=user["email"],
                                       position=user["position"],
                                       is_admin=user["is_admin"])

    # Then
    assert 1 == session.num_calls
    expected_call = FakeCall(method='POST',
                             path='/users',
                             json={
                                 'screen_name': user["screen_name"],
                                 'position': user["position"],
                                 'email': user["email"],
                                 'is_admin': user["is_admin"],
                             })

    assert expected_call.json['screen_name'] == created_user.screen_name
    assert expected_call.json['email'] == created_user.email
    assert expected_call.json['position'] == created_user.position
    assert expected_call.json['is_admin'] == created_user.is_admin
コード例 #2
0
def test_list_members(project, session):
    # Given
    user = UserDataFactory()
    session.set_response({'users': [user]})

    # When
    project.list_members()

    # Then
    assert 1 == session.num_calls
    expect_call = FakeCall(method='GET', path='/projects/{}/users'.format(project.uid))
    assert expect_call == session.last_call
コード例 #3
0
def test_remove_user(project, session):
    # Given
    user = UserDataFactory()

    # When
    remove_user_response = project.remove_user(user["id"])

    # Then
    assert 1 == session.num_calls
    expect_call = FakeCall(method="DELETE",
                           path="/projects/{}/users/{}".format(
                               project.uid, user["id"]))
    assert expect_call == session.last_call
    assert remove_user_response is True
コード例 #4
0
def test_update_user_actions(project, session):
    # Given
    user = UserDataFactory()
    session.set_response({'actions': ['READ'], 'role': 'LEAD'})

    # When
    update_user_role_response = project.update_user_role(user["id"], LEAD, [WRITE])

    # Then
    assert 1 == session.num_calls
    expect_call = FakeCall(method="POST", path="/projects/{}/users/{}".format(project.uid, user["id"]),
                           json={'role': LEAD, 'actions': [WRITE]})
    assert expect_call == session.last_call
    assert update_user_role_response is True
コード例 #5
0
def test_list_members(project, session):
    # Given
    user = UserDataFactory()
    user["role"] = MEMBER
    session.set_response({'users': [user]})

    # When
    members = project.list_members()

    # Then
    assert 1 == session.num_calls
    expect_call = FakeCall(method='GET', path='/projects/{}/users'.format(project.uid))
    assert expect_call == session.last_call
    assert isinstance(members[0], ProjectMember)
コード例 #6
0
def test_get_me(collection, session):
    # Given
    user = UserDataFactory()
    user["id"] = user["id"]
    del user["id"]
    session.set_response(user)

    # When
    current_user = collection.me()

    # Then
    expected_call = FakeCall(method="GET", path='/users/me')
    assert 1 == session.num_calls
    assert expected_call == session.last_call
コード例 #7
0
def test_delete_user(collection, session):
    # Given
    user = UserDataFactory()

    # When
    collection.delete(user['id'])

    session.set_response({'message': 'User was deleted'})
    expected_call = FakeCall(
        method="DELETE",
        path='/users/{}'.format(user["id"]),
    )

    assert 1 == session.num_calls
    assert expected_call == session.last_call
コード例 #8
0
def test_set_member(project, session):
    # Given
    user = UserDataFactory()
    session.set_response({'actions': ["READ", "INVITE"], 'role': 'MEMBER'})

    # When
    project.set_member(user["id"], 'MEMBER', ["READ", "INVITE"])

    # Then
    assert 1 == session.num_calls
    expect_call = FakeCall(method="POST", path='/projects/{}/users/{}'.format(project.uid, user["id"]), json={
        "role": "MEMBER",
        "actions": ["READ", "INVITE"]
    })
    assert expect_call == session.last_call
コード例 #9
0
def test_add_user(project, session):
    # Given
    user = UserDataFactory()
    session.set_response({'actions': [], 'role': 'MEMBER'})

    # When
    add_user_response = project.add_user(user["id"])

    # Then
    assert 1 == session.num_calls
    expect_call = FakeCall(method="POST", path='/projects/{}/users/{}'.format(project.uid, user["id"]), json={
        "role": "MEMBER",
        "actions": []
    })
    assert expect_call == session.last_call
    assert add_user_response is True
コード例 #10
0
def test_list_users(collection, session):
    # Given
    user_data = UserDataFactory.create_batch(5)
    session.set_response({'users': user_data})

    # When
    users = list(collection.list())

    # Then
    assert 1 == session.num_calls
    expected_call = FakeCall(method='GET',
                             path='/users',
                             params={'per_page': 100})

    assert expected_call == session.last_call
    assert len(users) == 5
コード例 #11
0
def user() -> User:
    return User.build(UserDataFactory())