From e1981063359b0910614e5ea3f861a5ce1e54970d Mon Sep 17 00:00:00 2001 From: Christian Struck Date: Sat, 2 Feb 2013 04:17:03 +0100 Subject: Added a new object to return which is easier to handle an implements a merge function if it is wished to mix actualdeparture with scheduleddeparture departures. --- tests/test_api.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_api.py b/tests/test_api.py index cf111d7..113bbbf 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -3,7 +3,7 @@ import datetime import json import unittest -from bvggrabber.api import QueryApi, Departure, compute_remaining +from bvggrabber.api import QueryApi, Departure, Response, compute_remaining from bvggrabber.utils.format import fullformat @@ -42,6 +42,36 @@ class TestFunctions(unittest.TestCase): 1357092240, 1357092241) +class TestResponse(unittest.TestCase): + + def test_merge(self): + departures = [ Departure("ERP", + "HBF", + datetime.datetime(2013, 1, 2, 3, 4, 1), + "U2"), + Departure("HBF", + "ERP", + datetime.datetime(2013, 2, 1, 3, 4, 1), + "U55")] + departures2 = [ Departure("ERP", + "HBF", + datetime.datetime(2013, 1, 2, 3, 4, 1), + "U6"), + Departure("HBF", + "ERP", + datetime.datetime(2013, 2, 1, 3, 4, 1), + "U9")] + allDepartures = departures + departures2 + r1 = Response(True, departures) + r2 = Response(True, departures2) + r3 = Response(False, []) + self.assertRaises(ValueError, r1.merge, r3) + self.assertRaises(ValueError, r3.merge, r2) + self.assertRaises(TypeError, r1.merge, departures) + r1.merge(r2) + self.assertEqual(r1.departures, allDepartures) + + class TestQueryApi(unittest.TestCase): def test_call(self): -- cgit v1.2.3