def test_select_house_error(service: UpdateReservationCache, context: Context):
    service._houses_repo = Mock(get=Mock(side_effect=RuntimeError('ERR')))

    result = service.select_house(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == 'ERR'
def test_select_house_ok(service: UpdateReservationCache, context: Context,
                         house):
    service._houses_repo = Mock(get=Mock(return_value=Some(house)))

    result = service.select_house(context)
    assert is_successful(result)
    assert result.unwrap().house == house
def test_success(service: UpdateReservationCache, house, reservation,
                 rate_plan, user):
    service._houses_repo = Mock(get=Mock(return_value=Some(house)))
    service._reservations_repo = Mock(select=Mock(return_value=[reservation]))
    service._cache_repo = Mock(save=Mock(return_value=True),
                               delete=Mock(return_value=None))
    service._prices_repo = Mock(select_plans=Mock(return_value=[rate_plan]))
    service._members_repo = Mock(get_bot_user=Mock(return_value=Some(user)))
    service.get_rpc_api = Mock(return_value=Mock(
        select_invoices_for_order=Mock(return_value=[
            Mock(id=987, amount_total=50.0, amount_residual=20.0)
        ])))

    result = service.execute(house_id=house.id)
    assert is_successful(result)
def test_select_house_fail(service: UpdateReservationCache, context: Context):
    service._houses_repo = Mock(get=Mock(return_value=Nothing))

    result = service.select_house(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_house