예제 #1
0
def test_select_user_fail(service: CancelReservationInOdoo, context: Context,
                          house):
    service._members_repo = Mock(get_user_by_id=Mock(return_value=Nothing))
    context.house = house

    result = service.select_user(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_user
예제 #2
0
def test_select_user_ok(service: CancelReservationInOdoo, context: Context,
                        house, user):
    service._members_repo = Mock(get_user_by_id=Mock(return_value=Some(user)))
    context.house = house

    result = service.select_user(context)
    assert is_successful(result)
    assert result.unwrap().user == user
예제 #3
0
def test_select_user_error(service: CancelReservationInOdoo, context: Context,
                           house):
    service._members_repo = Mock(get_user_by_id=Mock(
        side_effect=RuntimeError('ERR')))
    context.house = house

    result = service.select_user(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_user
    assert str(result.failure().exc) == 'ERR'
예제 #4
0
def test_success(service: CancelReservationInOdoo, house, reservation, user):
    service._houses_repo = Mock(get=Mock(return_value=Some(house)))
    service._reservations_repo = Mock(get=Mock(return_value=Some(reservation)))
    service._members_repo = Mock(get_user_by_id=Mock(return_value=Some(user)))
    service.get_rpc_api = Mock(
        return_value=Mock(cancel_opportunity=Mock(return_value=None),
                          cancel_quotation=Mock(return_value=None)))

    result = service.execute(house.id, reservation.id, user_id=user.id)
    assert is_successful(result)
    assert result.unwrap()