示例#1
0
class TestStationLibrary(TestCase):
    def setUp(self):
        self.query_strategy = StubQueryStrategy()
        self.lib = StationLibrary(self.query_strategy)

    def test_find_nearby(self):
        stations = self.lib.find_nearby(Position(0, 0))
        other = [
            Station(self.lib, 8600626, "København H",
                    Position(55673063, 12565796)),
            Station(self.lib, 10844, "Hovedbanegården, Tivoli",
                    Position(55672838, 12566191)),
            Station(self.lib, 100240000,
                    "København, Bernstorffsgade (fjernbus)",
                    Position(55673899, 12565112))
        ]

        self.assertEqual(other, stations)

    def test_strategy_find_called_with_right_parameters(self):
        self.lib.find_nearby(Position(1, 2))
        self.assertEqual([('find_nearby', [1, 2, 100, 50])],
                         self.query_strategy.called)

    def test_station_from_id_is_empty(self):
        self.assertEqual(Station(self.lib, 123, '', Position(0, 0)),
                         self.lib.station_from_id(123))
示例#2
0
class TestStation(TestCase):
    def setUp(self):
        self.query_strategy = StubQueryStrategy()
        self.lib = StationLibrary(self.query_strategy)
        self.station = self.lib.find_nearby(Position(0, 0))[0]
        self.query_strategy.called = []

    def test_station_departure_times(self):
        departures = self.station.departures()
        other = [
            Departure(self.station, "ØR 2037", "TOG",
                      datetime(2015, 7, 7, 10, 12)),
            Departure(self.station,
                      "ØR 1036",
                      "TOG",
                      datetime(2015, 7, 7, 10, 12),
                      direction='Hässleholm C og Kalmar C'),
            Departure(self.station, "Re 2221", "REG",
                      datetime(2015, 7, 8, 10, 20), "Nykøbing F St.")
        ]
        self.assertEqual(other, departures)

    def test_strategy_called_right(self):
        self.station.departures()
        self.assertEqual([('departure_time', [8600626, True, True, True])],
                         self.query_strategy.called)
class TestRESTHandler(unittest.TestCase):
    def setUp(self):
        self.query_strategy = StubQueryStrategy()
        self.lib = StationLibrary(self.query_strategy)
        self.station = self.lib.find_nearby(Position(0, 0))[0]
        self.handler = RESTHandler(self.query_strategy)

    def test_station_library_find_nearby(self):
        self.assertEqual(self.lib.find_nearby(Position(0, 0), 1000),
                         self.handler.handle(['1.0', 'Stations', 'findNearby'],
                                             {'long': '0', 'lat': 0, 'radius': 1000}))

    def test_get_station_from_name(self):
        s1 = self.lib.station_from_id(603330500).departures()
        s2 = self.handler.handle(['1.0', 'Stations', 'departures', '603330500'])
        self.assertEqual(s1, s2)
class TestStationLibrary(TestCase):
    def setUp(self):
        self.query_strategy = StubQueryStrategy()
        self.lib = StationLibrary(self.query_strategy)

    def test_find_nearby(self):
        stations = self.lib.find_nearby(Position(0, 0))
        other = [Station(self.lib, 8600626, "København H", Position(55673063, 12565796)),
                 Station(self.lib, 10844, "Hovedbanegården, Tivoli", Position(55672838, 12566191)),
                 Station(self.lib, 100240000, "København, Bernstorffsgade (fjernbus)",
                         Position(55673899, 12565112))]

        self.assertEqual(other, stations)

    def test_strategy_find_called_with_right_parameters(self):
        self.lib.find_nearby(Position(1, 2))
        self.assertEqual([('find_nearby', [1, 2, 100, 50])], self.query_strategy.called)

    def test_station_from_id_is_empty(self):
        self.assertEqual(Station(self.lib, 123, '', Position(0, 0)), self.lib.station_from_id(123))
示例#5
0
class RESTHandler(Handler):
    def __init__(self, query_strategy: QueryStrategy):
        super().__init__(None)
        self.library = StationLibrary(query_strategy)
        self.setup_v1_0()

    def setup_v1_0(self):
        """
        Sets up v1.0 of the API
        :return:
        """
        handler = self.add_handler('1.0')
        site_library_handler = handler.add_handler('Stations')
        site_library_handler.add_function('findNearby',
                                          lambda name, inp: self.library.find_nearby(
                                              Position(int(inp['lat']), int(inp['long'])),
                                              int(inp['radius'])))
        site_library_handler \
            .add_handler('departures') \
            .add_function('*', lambda name, inp: self.library.station_from_id(int(name[0])).departures())
示例#6
0
class RESTHandler(Handler):
    def __init__(self, query_strategy: QueryStrategy):
        super().__init__(None)
        self.library = StationLibrary(query_strategy)
        self.setup_v1_0()

    def setup_v1_0(self):
        """
        Sets up v1.0 of the API
        :return:
        """
        handler = self.add_handler('1.0')
        site_library_handler = handler.add_handler('Stations')
        site_library_handler.add_function(
            'findNearby', lambda name, inp: self.library.find_nearby(
                Position(int(inp['lat']), int(inp['long'])), int(inp['radius'])
            ))
        site_library_handler \
            .add_handler('departures') \
            .add_function('*', lambda name, inp: self.library.station_from_id(int(name[0])).departures())
示例#7
0
class TestRESTHandler(unittest.TestCase):
    def setUp(self):
        self.query_strategy = StubQueryStrategy()
        self.lib = StationLibrary(self.query_strategy)
        self.station = self.lib.find_nearby(Position(0, 0))[0]
        self.handler = RESTHandler(self.query_strategy)

    def test_station_library_find_nearby(self):
        self.assertEqual(
            self.lib.find_nearby(Position(0, 0), 1000),
            self.handler.handle(['1.0', 'Stations', 'findNearby'], {
                'long': '0',
                'lat': 0,
                'radius': 1000
            }))

    def test_get_station_from_name(self):
        s1 = self.lib.station_from_id(603330500).departures()
        s2 = self.handler.handle(
            ['1.0', 'Stations', 'departures', '603330500'])
        self.assertEqual(s1, s2)
class TestStation(TestCase):
    def setUp(self):
        self.query_strategy = StubQueryStrategy()
        self.lib = StationLibrary(self.query_strategy)
        self.station = self.lib.find_nearby(Position(0, 0))[0]
        self.query_strategy.called = []

    def test_station_departure_times(self):
        departures = self.station.departures()
        other = [

            Departure(self.station, "ØR 2037", "TOG", datetime(2015, 7, 7, 10, 12)),
            Departure(self.station, "ØR 1036", "TOG", datetime(2015, 7, 7, 10, 12), direction='Hässleholm C og Kalmar C'),
            Departure(self.station, "Re 2221", "REG", datetime(2015, 7, 8, 10, 20), "Nykøbing F St.")
        ]
        self.assertEqual(other, departures)

    def test_strategy_called_right(self):
        self.station.departures()
        self.assertEqual([('departure_time', [8600626, True, True, True])], self.query_strategy.called)
示例#9
0
 def setUp(self):
     self.query_strategy = StubQueryStrategy()
     self.lib = StationLibrary(self.query_strategy)
     self.station = self.lib.find_nearby(Position(0, 0))[0]
     self.query_strategy.called = []
示例#10
0
 def setUp(self):
     self.query_strategy = StubQueryStrategy()
     self.lib = StationLibrary(self.query_strategy)
 def setUp(self):
     self.query_strategy = StubQueryStrategy()
     self.lib = StationLibrary(self.query_strategy)
     self.station = self.lib.find_nearby(Position(0, 0))[0]
     self.query_strategy.called = []
 def setUp(self):
     self.query_strategy = StubQueryStrategy()
     self.lib = StationLibrary(self.query_strategy)
示例#13
0
 def setUp(self):
     self.query_strategy = StubQueryStrategy()
     self.lib = StationLibrary(self.query_strategy)
     self.station = self.lib.find_nearby(Position(0, 0))[0]
     self.handler = RESTHandler(self.query_strategy)
示例#14
0
 def __init__(self, query_strategy: QueryStrategy):
     super().__init__(None)
     self.library = StationLibrary(query_strategy)
     self.setup_v1_0()
示例#15
0
 def setUp(self):
     self.query_strategy = StubQueryStrategy()
     self.lib = StationLibrary(self.query_strategy)
     self.station = self.lib.find_nearby(Position(0, 0))[0]
     self.handler = RESTHandler(self.query_strategy)
示例#16
0
 def __init__(self, query_strategy: QueryStrategy):
     super().__init__(None)
     self.library = StationLibrary(query_strategy)
     self.setup_v1_0()