Exemplo n.º 1
0
def test_reservation_form_quota():
    allocation = Allocation()

    allocation.quota = 1
    allocation.quota_limit = 1
    form = ReservationForm.for_allocation(allocation)()
    assert not hasattr(form, 'quota')

    allocation.quota = 2
    allocation.quota_limit = 1
    form = ReservationForm.for_allocation(allocation)()
    assert not hasattr(form, 'quota')

    allocation.quota = 1
    allocation.quota_limit = 2
    form = ReservationForm.for_allocation(allocation)()
    assert not hasattr(form, 'quota')

    allocation.quota = 2
    allocation.quota_limit = 2
    form = ReservationForm.for_allocation(allocation)()
    assert hasattr(form, 'quota')

    allocation.quota = 2
    allocation.quota_limit = 0
    form = ReservationForm.for_allocation(allocation)()
    assert hasattr(form, 'quota')
Exemplo n.º 2
0
def get_reservation_form_class(model, request):
    if isinstance(model, Allocation):
        return ReservationForm.for_allocation(model)

    if isinstance(model, Reservation):
        allocation = model._target_allocations().first()
        return ReservationForm.for_allocation(allocation)

    raise NotImplementedError
Exemplo n.º 3
0
def test_reservation_form_partly_available():
    allocation = Allocation()

    allocation.timezone = 'Europe/Zurich'
    allocation.start = datetime(2015, 1, 1, 10)
    allocation.end = datetime(2015, 1, 1, 16)

    allocation.partly_available = True
    form = ReservationForm.for_allocation(allocation)()
    assert hasattr(form, 'start')
    assert hasattr(form, 'end')
    assert form.start.default == time(10, 00)
    assert form.end.default == time(16, 00)

    allocation.partly_available = False
    form = ReservationForm.for_allocation(allocation)()
    assert not hasattr(form, 'start')
    assert not hasattr(form, 'end')