diff options
Diffstat (limited to 'tests/test_api.py')
-rw-r--r-- | tests/test_api.py | 66 |
1 files changed, 57 insertions, 9 deletions
diff --git a/tests/test_api.py b/tests/test_api.py index bf50865..8493524 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -2,7 +2,7 @@ import time import unittest -from datetime import datetime +from datetime import datetime, timedelta from bvggrabber.api import QueryApi, Departure @@ -16,26 +16,74 @@ class TestQueryApi(unittest.TestCase): class TestDeparture(unittest.TestCase): + def setUp(self): + self.td = timedelta(minutes=10) + def test_timestamp_futur(self): when = time.time() + 10 * 60 dep = Departure("from", "to", when, "line") - self.assertLessEqual(dep.remaining().total_seconds(), 600) - self.assertGreaterEqual(dep.remaining().total_seconds(), 590) + diff = dep.remaining.total_seconds() + self.assertLessEqual(diff, 600) + self.assertGreaterEqual(diff, 590) + + def test_timestamp_now(self): + when = time.time() + dep = Departure("from", "to", when, "line") + diff = dep.remaining.total_seconds() + self.assertLessEqual(diff, 5) + self.assertGreaterEqual(diff, -5) + + def test_timestamp_past(self): + when = time.time() - 10 * 60 + dep = Departure("from", "to", when, "line") + diff = dep.remaining.total_seconds() + self.assertLessEqual(diff, -600) + self.assertGreaterEqual(diff, -610) def test_string_futur(self): + when = datetime.now() + self.td + when = when.strftime('%Y-%m-%d %H:%M:%S') + dep = Departure("from", "to", when, "line") + diff = dep.remaining.total_seconds() + self.assertLessEqual(diff, 600) + self.assertGreaterEqual(diff, 590) + + def test_string_now(self): when = datetime.now() - when = when.replace(minute=when.minute + 10) when = when.strftime('%Y-%m-%d %H:%M:%S') dep = Departure("from", "to", when, "line") - self.assertLessEqual(dep.remaining().total_seconds(), 600) - self.assertGreaterEqual(dep.remaining().total_seconds(), 590) + diff = dep.remaining.total_seconds() + self.assertLessEqual(diff, 5) + self.assertGreaterEqual(diff, -5) + + def test_string_past(self): + when = datetime.now() - self.td + when = when.strftime('%Y-%m-%d %H:%M:%S') + dep = Departure("from", "to", when, "line") + diff = dep.remaining.total_seconds() + self.assertLessEqual(diff, -600) + self.assertGreaterEqual(diff, -610) def test_datetime_futur(self): + when = datetime.now() + self.td + dep = Departure("from", "to", when, "line") + diff = dep.remaining.total_seconds() + self.assertLessEqual(diff, 600) + self.assertGreaterEqual(diff, 590) + + def test_datetime_now(self): when = datetime.now() - when = when.replace(minute=when.minute + 10) dep = Departure("from", "to", when, "line") - self.assertLessEqual(dep.remaining().total_seconds(), 600) - self.assertGreaterEqual(dep.remaining().total_seconds(), 590) + diff = dep.remaining.total_seconds() + self.assertLessEqual(diff, 5) + self.assertGreaterEqual(diff, -5) + + def test_datetime_past(self): + when = datetime.now() - self.td + dep = Departure("from", "to", when, "line") + diff = dep.remaining.total_seconds() + self.assertLessEqual(diff, -600) + self.assertGreaterEqual(diff, -610) def test_error(self): self.assertRaises(ValueError, Departure, "from", "to", "foo", "line") |