Skip to content

Commit

Permalink
Merge pull request #116 from flindenberg/develop
Browse files Browse the repository at this point in the history
introduced a few tests cases for model (after travis reinstalled locales)
  • Loading branch information
Doca committed Sep 23, 2015
2 parents 8df59ed + 1b9c043 commit 5a105e8
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/scheduler/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,58 @@ def test_not_conflict_1h_grace(self):
def test_conflict_0h_grace(self):
need = create_need(11, 14)
assert need.get_conflicting_needs(self.needs, grace=datetime.timedelta(hours=0))


class LocationTestCase(TestCase):

def test_get_days_with_needs_at_location_end_later_than_now(self):
"""
checks that get_days_with_needs() returns only dates later than datetime.now()
"""
now = datetime.datetime.now()
yesterday_start = now - datetime.timedelta(1)
yesterday_end = yesterday_start+datetime.timedelta(hours=1)
tomorrow_start = now + datetime.timedelta(1)
tomorrow_end = tomorrow_start+datetime.timedelta(hours=1)

needs = [NeedFactory.create(starting_time=yesterday_start, ending_time=yesterday_end),
NeedFactory.create(starting_time=tomorrow_start, ending_time=tomorrow_end)]

locations = set()
for n in needs:
locations.add(n.location)

assert len(locations) == 1, "test case assumes that needs have been created for the same location, as the NeedFactory indeed does at the time of writing of this test case"
#TODO change this assumption by explicitly creating needs for the same location

for l in locations:
for day in l.get_days_with_needs():
assert isinstance(day[0], datetime.datetime)
assert day[0] > datetime.datetime.now()

def test_get_days_with_needs_at_location_no_duplicates(self):
"""
checks that get_days_with_needs() does not return any duplicate dates
"""
start = datetime.datetime.now()
end = start + datetime.timedelta(hours=1)
needs = [NeedFactory.create(starting_time=start, ending_time=end),
NeedFactory.create(starting_time=start, ending_time=end)]

locations = set()
for n in needs:
locations.add(n.location)

assert len(locations) == 1, "test case assumes that needs have been created for the same location, as the NeedFactory indeed does at the time of writing of this test case"
#TODO change this assumption by explicitly creating needs for the same location

for l in locations:
dates = set()
for d in l.get_days_with_needs():
assert d[0] not in dates
dates.add(d[0])

def test_get_days_with_needs_have_german_formatting(self):
need = create_need(15,16)
for d in need.location.get_days_with_needs():
assert d[0].strftime("%A, %d.%m.%Y") == d[1]

0 comments on commit 5a105e8

Please sign in to comment.