def test_select_bot_user_fail(service: UpdateReservationCache, context: Context, house, reservation): service._members_repo = Mock(get_bot_user=Mock(return_value=Nothing)) context.house = house context.reservations = [reservation] result = service.select_bot_user(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.missed_user
def test_select_bot_user_ok(service: UpdateReservationCache, context: Context, house, reservation, user): service._members_repo = Mock(get_bot_user=Mock(return_value=Some(user))) context.house = house context.reservations = [reservation] result = service.select_bot_user(context) assert is_successful(result), result.failure() assert result.unwrap().user == user
def test_select_bot_user_error(service: UpdateReservationCache, context: Context, house, reservation): service._members_repo = Mock(get_bot_user=Mock( side_effect=RuntimeError('ERR'))) context.house = house context.reservations = [reservation] result = service.select_bot_user(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.error assert str(result.failure().exc) == 'ERR'
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)