コード例 #1
0
def test_success(service: UpdateRoomClose, context: Context, house, room,
                 reservation):
    _reservation = attr.evolve(reservation, is_verified=True)
    service._houses_repo = Mock(get=Mock(return_value=Some(house)))
    service._rooms_repo = Mock(get=Mock(return_value=Some(room)))
    service._reservations_repo = Mock(
        accept=Mock(return_value=Some(_reservation)),
        get=Mock(return_value=Some(reservation)),
        is_room_busy=Mock(return_value=False),
        save=Mock(
            return_value=(Some(attr.evolve(reservation, is_verified=False)),
                          True)),
    )

    result = service.execute(
        '111-222-1',
        house.id,
        room.id,
        context.start_date,
        context.end_date,
        RoomCloseReasons.MAINTENANCE,
        context.user,
    )
    assert is_successful(result), result.failure()

    ctx = result.unwrap()
    assert isinstance(ctx, ReservationUpdateContext)
    assert ctx.reservation == _reservation
    assert ctx.start_date == datetime.date.today()
    assert ctx.end_date == datetime.date.today() + datetime.timedelta(days=2)
コード例 #2
0
def test_select_house_error(service: UpdateRoomClose, 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"
コード例 #3
0
def test_select_house_fail(service: UpdateRoomClose, 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
コード例 #4
0
def test_select_house_ok(service: UpdateRoomClose, 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