Exemplo n.º 1
0
def test_should_get_NotAuthorizedError_if_the_user_doesnt_have_an_admin_role(
        database):
    user_repository = UserRepository(
        None,
        database,
        get_current_user_id=lambda: "user-1",
    )
    user_interactor = UserInteractor(None, user_repository)
    data = {"user_id": "test-id"}
    with pytest.raises(NotAuthorizedError) as exception:
        user_interactor.unassign_user(data)
    assert exception.value.data == {"msg": "This operation is not authorized."}
Exemplo n.º 2
0
def test_should_get_NotAuthorizedError_if_the_admin_is_not_logged_in(database):
    user_repository = UserRepository(
        None,
        database,
        get_current_user_id=lambda: None,
    )
    user_interactor = UserInteractor(None, user_repository)
    data = {"user_id": "test-id"}
    with pytest.raises(NotAuthorizedError) as exception:
        user_interactor.unassign_user(data)
    assert exception.value.data == {
        "msg": "This operation is not authorized. Please, log in."
    }
Exemplo n.º 3
0
def test_should_raise_NotFoundError_if_the_user_doesnt_exist(database):
    user_repository = UserRepository(
        None,
        database,
        get_current_user_id=lambda: "admin-1",
    )
    user_interactor = UserInteractor(None, user_repository)
    data = {"user_id": "test-user-doesnt-exist"}
    with pytest.raises(NotFoundError) as exception:
        user_interactor.unassign_user(data)
    assert exception.value.data == {
        "msg": "User with id 'test-user-doesnt-exist' not found.",
    }
Exemplo n.º 4
0
def test_should_raise_BadRequestError_if_there_are_not_the_required_fields_in_the_request(
        database):
    user_repository = UserRepository(
        None,
        database,
        get_current_user_id=lambda: "admin-1",
    )
    user_interactor = UserInteractor(None, user_repository)
    data = {}
    with pytest.raises(BadRequestError) as exception:
        user_interactor.unassign_user(data)
    assert exception.value.data == {
        "user_id": "REQUIRED",
    }
Exemplo n.º 5
0
def test_should_unassign_the_user_if_the_request_is_OK_and_the_admin_is_logged_in(
        database):
    user_repository = UserRepository(
        None,
        database,
        get_current_user_id=lambda: "admin-1",
    )
    user_interactor = UserInteractor(None, user_repository)
    data = {"user_id": "user-1"}
    user_interactor.assign_user(data)
    assigned_users_before = user_interactor.get_all_assigned_users()
    assert len(assigned_users_before) == 1
    assert assigned_users_before[0].id == "user-1"
    user_interactor.unassign_user(data)
    assigned_users_after = user_interactor.get_all_assigned_users()
    assert assigned_users_after == []