Skip to content

Commit

Permalink
Migrates session removal complete test
Browse files Browse the repository at this point in the history
  • Loading branch information
href committed Nov 25, 2014
1 parent 37af98a commit ee80982
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 37 additions & 1 deletion libres/tests/test_scheduler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from datetime import datetime, timedelta
from libres.db.models import Reservation
from libres.db.models import Reservation, Allocation, ReservedSlot
from libres.modules import calendar, errors, events
from mock import Mock
from sqlalchemy.orm.exc import MultipleResultsFound
Expand Down Expand Up @@ -51,6 +51,10 @@ def test_managed_allocations(scheduler):
assert scheduler.managed_allocations().count() == 1
assert s2.managed_allocations().count() == 1

# be sure to clean up afterwards as this won't be done automatically
s2.extinguish_managed_records()
s2.commit()


def test_reserve(scheduler):

Expand Down Expand Up @@ -468,3 +472,35 @@ def test_session_expiration(scheduler):
expiration_date=created + timedelta(microseconds=2)
)
assert len(expired) == 1


def test_session_removal_is_complete(scheduler):
start, end = datetime(2013, 9, 27, 9, 0), datetime(2013, 9, 27, 10)
scheduler.allocate(dates=(start, end))
session_id = new_uuid()

token = scheduler.reserve(
u'test@example.org', (start, end), session_id=session_id
)

scheduler.commit()

assert scheduler.session.query(Reservation).count() == 1
assert scheduler.session.query(Allocation).count() == 1
assert scheduler.session.query(ReservedSlot).count() == 0

scheduler.approve_reservations(token)
scheduler.commit()

assert scheduler.session.query(Reservation).count() == 1
assert scheduler.session.query(Allocation).count() == 1
assert scheduler.session.query(ReservedSlot).count() == 1

scheduler.queries.remove_expired_reservation_sessions(
expiration_date=calendar.utcnow() + timedelta(seconds=15 * 60)
)
scheduler.commit()

assert scheduler.session.query(Reservation).count() == 0
assert scheduler.session.query(Allocation).count() == 1
assert scheduler.session.query(ReservedSlot).count() == 0
2 changes: 2 additions & 0 deletions libres/tests/test_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from datetime import datetime
from libres.db.models import Allocation


@pytest.mark.parametrize('execution_number', range(2))
Expand All @@ -25,3 +26,4 @@ def test_independence(
scheduler.commit()

assert scheduler.managed_allocations().count() == 1
assert scheduler.session.query(Allocation).count() == 1

0 comments on commit ee80982

Please sign in to comment.