From d6f0b39753f1b55f86a0eba9a822c367a26c45dc Mon Sep 17 00:00:00 2001 From: Markus Holtermann Date: Thu, 24 Jan 2013 21:32:04 +0100 Subject: Add base QueryApi and Departure classes including simple tests --- tests/test_api.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/test_api.py (limited to 'tests') diff --git a/tests/test_api.py b/tests/test_api.py new file mode 100644 index 0000000..dafe598 --- /dev/null +++ b/tests/test_api.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- + +import time +import unittest + +from datetime import datetime + +from bvggrabber.api import QueryApi, Departure + + +class TestQueryApi(unittest.TestCase): + + def test_call(self): + q = QueryApi() + self.assertRaises(NotImplementedError, q.call) + + +class TestDeparture(unittest.TestCase): + + 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) + + def test_string_futur(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) + + def test_datetime_futur(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) + + def test_error(self): + self.assertRaises(ValueError, Departure, "from", "to", "foo", "line") -- cgit v1.2.3