diff options
author | Markus Holtermann <info@markusholtermann.eu> | 2013-01-24 21:32:04 +0100 |
---|---|---|
committer | Markus Holtermann <info@markusholtermann.eu> | 2013-01-24 21:32:04 +0100 |
commit | d6f0b39753f1b55f86a0eba9a822c367a26c45dc (patch) | |
tree | 5bcd204369f967e748d9f014b923e21a06e3261f /tests | |
parent | 0cdc756ff3ef4c4f83739cb6db41b282a24fc152 (diff) | |
download | bvg-grabber-d6f0b39753f1b55f86a0eba9a822c367a26c45dc.tar.gz bvg-grabber-d6f0b39753f1b55f86a0eba9a822c367a26c45dc.tar.bz2 bvg-grabber-d6f0b39753f1b55f86a0eba9a822c367a26c45dc.zip |
Add base QueryApi and Departure classes including simple tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_api.py | 42 |
1 files changed, 42 insertions, 0 deletions
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") |