Exemplo n.º 1
0
 def test_direction_code_backward_returnedCorrectDirectionCode(self):
     # Given
     l = Line(66, "PLACE1 - PLACE2", LINE_RETURN_DIRECTION)
     # When
     code = l.get_agency_direction_code()
     # Then
     self.assertEqual(code, LINE_RETURN_DIRECTION_CODE)
Exemplo n.º 2
0
 def test_origin_regularLineName(self):
     # Given
     l = Line(66, "PLACE1 - PLACE2", LINE_FORWARD_DIRECTION)
     # When
     origin = l.get_origin_name()
     # Then
     self.assertEqual(origin, "PLACE1", "Origin is not correct")
Exemplo n.º 3
0
 def test_destination_regularLineName(self):
     # Given
     l = Line(66, "PLACE1 - PLACE2", LINE_FORWARD_DIRECTION)
     # When
     dest = l.get_destination_name()
     # Then
     self.assertEqual(dest, "PLACE2", "Destination is not correct")
Exemplo n.º 4
0
 def test_add_stops_connections_from_cache_validDict_returnedConnectionsOk(
         self):
     # Given
     connections_cache = {
         "1234": ["I01", "I02", "V03"],
         "5678": ["I01", "I33"],
         "9012": ["V01"]
     }
     l = Line("01", "PLACE1 - PLACE2", LINE_FORWARD_DIRECTION)
     dummy_location = Location("10", "10")
     l.set_stops([
         Stop("1234", "Stop1", dummy_location),
         Stop("5678", "Stop2", dummy_location),
         Stop("9012", "Stop3", dummy_location)
     ])
     # When
     core.add_stops_connections_from_cache(l, connections_cache)
     # Then
     expected_connections = {
         "1234": ["I02", "V03"],
         "5678": ["I33"],
         "9012": []
     }
     for s in l.stops:
         self.assertListEqual(s.connections, expected_connections[s.id])
Exemplo n.º 5
0
    def test_is_night_line_nightLines_returnTrue(self):
        # Given
        lines = [
            Line("g1", "PLACE1 - PLACE2", LINE_FORWARD_DIRECTION),
            Line("G12", "PLACE1 - PLACE2", LINE_RETURN_DIRECTION),
            Line("G9", "PLACE1 - PLACE2", LINE_RETURN_DIRECTION)
        ]

        # When - Then
        for l in lines:
            self.assertEqual(l.is_night_line(), True)
Exemplo n.º 6
0
    def test_is_night_line_dayLines_returnFalse(self):
        # Given
        lines = [
            Line(66, "PLACE1 - PLACE2", LINE_RETURN_DIRECTION),
            Line("H1", "PLACE1 - PLACE2", LINE_FORWARD_DIRECTION),
            Line("3", "PLACE1 - PLACE2", LINE_RETURN_DIRECTION),
            Line("GG", "PLACE1 - PLACE2", LINE_RETURN_DIRECTION)
        ]

        # When - Then
        for l in lines:
            self.assertEqual(l.is_night_line(), False)
Exemplo n.º 7
0
def parse_lines(xml_response):
    """ Parse the response of all lines query """
    xmldoc = minidom.parseString(xml_response)
    lines_nodes = xmldoc.getElementsByTagName("ept:Line")
    result = []
    for l in lines_nodes:
        line = Line(parse_line_id(l), parse_line_name(l),
                    LINE_FORWARD_DIRECTION)
        result.append(line)
        if has_return_route(l):
            result.append(
                Line(line.id, line.get_reverse_name(), LINE_RETURN_DIRECTION))
    return result
Exemplo n.º 8
0
 def test_parse_lines_validXML_linesReturnedExpected(self):
     # Given
     input_xml = TEST_XML_RESPONSE
     # When
     lines = parse_lines(input_xml)
     # Then
     expected_lines = [
         Line('1001', "Origin1 - Destination1", LINE_FORWARD_DIRECTION),
         Line('1001', "Destination1 - Origin1", LINE_RETURN_DIRECTION),
         Line('1002', "Origin2 - Middle2 - Destination2/Alt2",
              LINE_FORWARD_DIRECTION),
         Line('1002', "Destination2/Alt2 - Middle2 - Origin2",
              LINE_RETURN_DIRECTION),
         Line('1003', "No Return Line", LINE_FORWARD_DIRECTION)
     ]
     self.assertListEqual(lines, expected_lines)
Exemplo n.º 9
0
 def test_get_stops_points_returnedStopsLocations(self):
     # Given
     l = Line("01", "PLACE1 - PLACE2", LINE_FORWARD_DIRECTION)
     l.set_stops([
         Stop("1234", "Stop1", Location(22.1, 3.1)),
         Stop("5678", "Stop2", Location(22.4, 3.2)),
         Stop("9012", "Stop3", Location(22.7, 3.3))
     ])
     # When
     locations = core.get_stops_points(l)
     # Then
     expected_locations = [
         Location(22.1, 3.1),
         Location(22.4, 3.2),
         Location(22.7, 3.3)
     ]
     self.assertListEqual(locations, expected_locations)
Exemplo n.º 10
0
 def test_parse_routes_validJSON_returnedExpectedRoute(self):
     # Given
     input_json = TEST_JSON_RESPONSE
     expected_route = [
         Location.from_coordinates(506233.065172259, 4790795.30995913),
         Location.from_coordinates(505959.0574198989, 4790065.031728711)
     ]
     line = Line(66, "PLACE1 - Place2", LINE_FORWARD_DIRECTION)
     location1001 = Location.from_coordinates(506233.065172259,
                                              4790795.30995913)
     location1001.set_raw_coordinates_simplified(506233, 4790795)
     location1002 = Location.from_coordinates(505959.0574198989,
                                              4790065.031728711)
     location1002.set_raw_coordinates_simplified(505959, 4790065)
     line.stops = [
         Stop("1001", "Stop name 1", location1001),
         Stop("1002", "Stop name 2", location1002)
     ]
     # When
     route = parse_route(line, input_json)
     # Then
     self.assertListEqual(route, expected_route)
Exemplo n.º 11
0
 def test_parse_stops_validXML_stopsReturnedExpected(self):
     # Given
     input_xml = TEST_XML_RESPONSE
     line = Line(66, "Origin - DestinationX", LINE_FORWARD_DIRECTION)
     # When
     stops = parse_stops(input_xml, line)
     # Then
     expected_stops = [
         Stop("1001", "Stop name 1",
              Location(43.26805613861105, -2.924456101471126)),
         Stop("1002", "Stop name 2",
              Location(43.26148247545685, -2.9278402600777014))
     ]
     self.assertListEqual(stops, expected_stops)
Exemplo n.º 12
0
 def test_reverse_name_returnedNameReversed(self):
     # Given
     cases = [(Line(66, "PLACE1 - Place2",
                    LINE_FORWARD_DIRECTION), "Place2 - PLACE1"),
              (Line(66, "PLACE1 - PLACE2/PLACE3",
                    LINE_FORWARD_DIRECTION), "PLACE2/PLACE3 - PLACE1"),
              (Line(66, "PLACE1 - Place2 - PLACE3",
                    LINE_FORWARD_DIRECTION), "PLACE3 - Place2 - PLACE1"),
              (Line(66, "PLACE1 VERY LONG",
                    LINE_FORWARD_DIRECTION), "PLACE1 VERY LONG"),
              (Line(66, "PLACE1 - Place 2 long",
                    LINE_FORWARD_DIRECTION), "Place 2 long - PLACE1"),
              (Line(66, "Place 1 long - Place2",
                    LINE_FORWARD_DIRECTION), "Place2 - Place 1 long")]
     for c in cases:
         # When
         reverse = c[0].get_reverse_name()
         # Then
         self.assertEqual(reverse, c[1])