1
|
|
|
import unittest |
2
|
|
|
from tube.tflAPI import TFLapi |
3
|
|
|
import vcr |
4
|
|
|
|
5
|
|
|
my_vcr = vcr.VCR( |
6
|
|
|
serializer = 'json', |
7
|
|
|
cassette_library_dir = 'tube/tests/fixtures/cassettes', |
8
|
|
|
record_mode = 'once', |
9
|
|
|
match_on = ['uri', 'method'], |
10
|
|
|
) |
11
|
|
|
|
12
|
|
|
import logging |
13
|
|
|
|
14
|
|
|
logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from vcrpy |
15
|
|
|
vcr_log = logging.getLogger("vcr") |
16
|
|
|
vcr_log.setLevel(logging.ERROR) |
17
|
|
|
|
18
|
|
|
class TestTFLapiByURL(unittest.TestCase): |
19
|
|
|
def setUp(self): |
20
|
|
|
self.api = TFLapi() |
21
|
|
|
|
22
|
|
|
def test_VerifyCorrectURLFetched(self): |
23
|
|
|
with my_vcr.use_cassette('Detail-OXC-B.json'): |
24
|
|
|
detail = self.api.getDetailed(station="OXC", line="B") |
25
|
|
|
self.assertEqual(detail.station, "OXC") |
26
|
|
|
self.assertEqual(detail.line, "B") |
27
|
|
|
|
28
|
|
|
def test_VerifyPlatformsQuantities(self): |
29
|
|
|
#camden town has 4 northern line platforms |
30
|
|
|
with my_vcr.use_cassette('Detail-CTN-N.json'): |
31
|
|
|
detail = self.api.getDetailed(station="CTN", line="N") |
32
|
|
|
self.assertEqual(detail.station, "CTN") |
33
|
|
|
self.assertIsInstance(detail.platforms, list) |
34
|
|
|
self.assertEqual( len(detail.platforms), 4) |
35
|
|
|
|
36
|
|
|
#oxford circus has 2 bakerloo platforms |
37
|
|
|
with my_vcr.use_cassette('Detail-OXC-B.json'): |
38
|
|
|
detail = self.api.getDetailed(station="OXC", line="B") |
39
|
|
|
self.assertEqual(detail.station, "OXC") |
40
|
|
|
self.assertIsInstance(detail.platforms, list) |
41
|
|
|
self.assertEqual( len(detail.platforms), 2) |
42
|
|
|
|
43
|
|
|
def test_VerifyPlatformsIdentified(self): |
44
|
|
|
with my_vcr.use_cassette('Detail-CTN-N.json'): |
45
|
|
|
detail = self.api.getDetailed(station="CTN", line="N") |
46
|
|
|
self.assertEqual(detail.platforms[0].name, "Northbound - Platform 1") |
47
|
|
|
self.assertEqual(detail.platforms[1].name, "Southbound - Platform 2") |
48
|
|
|
self.assertEqual(detail.platforms[2].name, "Northbound - Platform 3") |
49
|
|
|
self.assertEqual(detail.platforms[3].name, "Southbound - Platform 4") |
50
|
|
|
|
51
|
|
|
def test_VerifyTrainsOnPlatforms(self): |
52
|
|
|
#need testcase for no trains on platforms |
53
|
|
|
with my_vcr.use_cassette('Detail-OXC-B(TrainCode).json'): |
54
|
|
|
detail = self.api.getDetailed(station="OXC", line="B") |
55
|
|
|
self.assertIsInstance(detail.platforms[0].trains, list) |
56
|
|
|
|
57
|
|
|
self.assertEqual(detail.platforms[0].trains[0].leadingcar_id, "1031576") |
58
|
|
|
self.assertEqual(detail.platforms[0].trains[0].set_number, "236") |
59
|
|
|
self.assertEqual(detail.platforms[0].trains[0].trip_number, "12") |
60
|
|
|
self.assertEqual(detail.platforms[0].trains[0].arrival_seconds, "24") |
61
|
|
|
self.assertEqual(detail.platforms[0].trains[0].arrival_time, "0:30") |
62
|
|
|
self.assertEqual(detail.platforms[0].trains[0].current_location, "Between Regents Park and Oxford Circus") |
63
|
|
|
self.assertEqual(detail.platforms[0].trains[0].destination, "Elephant and Castle") |
64
|
|
|
self.assertEqual(detail.platforms[0].trains[0].destination_code, "154") |
65
|
|
|
self.assertEqual(detail.platforms[0].trains[0].platform_departure_time, "15:28:23") |
66
|
|
|
self.assertEqual(detail.platforms[0].trains[0].interval_between_previous_train, "24") |
67
|
|
|
self.assertEqual(detail.platforms[0].trains[0].departed_current_station, "0") |
68
|
|
|
self.assertEqual(detail.platforms[0].trains[0].direction, "0") |
69
|
|
|
self.assertEqual(detail.platforms[0].trains[0].track_code, "TB391B") |