Exemplo n.º 1
0
def test_build_stop_pk_to_service_maps_response(monkeypatch):
    system = models.System(id=SYSTEM_ID)
    route_1 = models.Route(id=ROUTE_1_ID, system=system)
    route_2 = models.Route(id=ROUTE_2_ID, system=system)

    monkeypatch.setattr(
        servicemapmanager,
        "build_stop_pk_to_group_id_to_inherited_routes_map",
        lambda *args: {STOP_1_PK: {GROUP_ID: [route_1, route_2]}},
    )

    expected = {
        STOP_1_PK: [
            views.ServiceMapWithRoutes(
                GROUP_ID,
                [
                    views.Route(ROUTE_1_ID, None, SYSTEM_ID),
                    views.Route(ROUTE_2_ID, None, SYSTEM_ID),
                ],
            )
        ]
    }

    actual = servicemapmanager.build_stop_pk_to_service_maps_response([STOP_1_PK])

    assert expected == actual
Exemplo n.º 2
0
def test_build_stop_pk_to_group_id_to_inherited_routes_map(monkeypatch):
    monkeypatch.setattr(
        stopqueries,
        "build_stop_pk_to_descendant_pks_map",
        lambda *args, **kwargs: {1: [1, 2, 3]},
    )
    monkeypatch.setattr(
        servicemapqueries,
        "get_stop_pk_to_group_id_to_routes_map",
        lambda *args: {
            2: {"group": [models.Route(id="2"), models.Route(id="3")]},
            3: {"group": [models.Route(id="4"), models.Route(id="1")]},
        },
    )

    expected_result = {
        1: {
            "group": [
                models.Route(id="1"),
                models.Route(id="2"),
                models.Route(id="3"),
                models.Route(id="4"),
            ]
        }
    }

    actual_result = servicemapmanager.build_stop_pk_to_group_id_to_inherited_routes_map(
        [1]
    )

    assert expected_result == actual_result
Exemplo n.º 3
0
def test_get_in_system_by_id(monkeypatch):
    system = models.System(id=SYSTEM_ID)
    route = models.Route(id=ROUTE_ID, color=ROUTE_COLOR, system=system)
    agency_1 = models.Agency(system=system,
                             id=AGENCY_ONE_ID,
                             name=AGENCY_ONE_NAME,
                             routes=[route],
                             alerts=[])

    monkeypatch.setattr(genericqueries, "get_in_system_by_id",
                        lambda *args: agency_1)
    monkeypatch.setattr(alertqueries, "get_agency_pk_to_active_alerts",
                        lambda *args, **kwargs: {})

    expected = views.AgencyLarge(
        id=AGENCY_ONE_ID,
        name=AGENCY_ONE_NAME,
        timezone=None,
        url=None,
        routes=[
            views.Route(id=ROUTE_ID, color=ROUTE_COLOR, _system_id=SYSTEM_ID)
        ],
        alerts=[],
    )

    actual = agencyservice.get_in_system_by_id(SYSTEM_ID, AGENCY_ONE_ID)

    assert expected == actual
Exemplo n.º 4
0
def test_build_trip_stop_time_response():
    system = models.System(id=SYSTEM_ID)
    stop = models.Stop(system=system)
    stop.id = STOP_ONE_ID
    trip = models.Trip(current_stop_sequence=1)
    trip.pk = TRIP_PK
    trip.id = TRIP_ID
    trip_stop_time = models.TripStopTime(arrival_time=TIME_1,
                                         departure_time=TIME_2,
                                         stop_sequence=1)
    trip_stop_time.trip = trip
    trip_stop_time.stop = stop
    route = models.Route(system=system)
    route.id = ROUTE_ID
    trip.route = route
    last_stop = models.Stop(system=system, id=STOP_TWO_ID, name=STOP_TWO_NAME)
    last_stop.id = STOP_TWO_ID

    expected = views.TripStopTime(
        arrival=views._TripStopTimeEvent(time=TIME_1,
                                         delay=None,
                                         uncertainty=None),
        departure=views._TripStopTimeEvent(time=TIME_2,
                                           delay=None,
                                           uncertainty=None),
        track=None,
        future=True,
        stop_sequence=1,
        direction=DIRECTION_NAME,
        trip=views.Trip(
            id=TRIP_ID,
            direction_id=None,
            started_at=None,
            updated_at=None,
            vehicle=None,
            _route_id=ROUTE_ID,
            _system_id=SYSTEM_ID,
            route=views.Route(id=ROUTE_ID, color=None, _system_id=SYSTEM_ID),
            last_stop=views.Stop(id=STOP_TWO_ID,
                                 name=STOP_TWO_NAME,
                                 _system_id=SYSTEM_ID),
        ),
    )

    actual = stopservice._build_trip_stop_time_response(
        trip_stop_time, DIRECTION_NAME, {trip.pk: last_stop})

    assert expected == actual
Exemplo n.º 5
0
def test_flush(db_session, add_model, system_1, previous_update,
               current_update):
    current_update.update_type = models.FeedUpdate.Type.FLUSH

    add_model(
        models.Stop(
            system=system_1,
            source_pk=previous_update.pk,
            type=models.Stop.Type.STATION,
        ))
    add_model(models.Route(
        system=system_1,
        source_pk=previous_update.pk,
    ))

    importdriver.run_import(current_update.pk, ParserForTesting([]))

    assert [] == db_session.query(models.Route).all()
Exemplo n.º 6
0
def test_calculate_realtime_service_map_for_route(inline_unit_of_work, monkeypatch):
    monkeypatch.setattr(dbconnection, "get_session", mock.MagicMock())
    service_map_group = models.ServiceMapGroup(
        source=models.ServiceMapGroup.ServiceMapSource.REALTIME
    )
    route_1 = models.Route(
        pk=ROUTE_1_PK,
        id=ROUTE_1_ID,
        system=models.System(service_map_groups=[service_map_group]),
        trips=[
            models.Trip(pk=TRIP_1_PK, direction_id=True),
            models.Trip(pk=TRIP_2_PK, direction_id=False),
        ],
    )

    monkeypatch.setattr(
        tripqueries,
        "get_trip_pk_to_path_map",
        lambda *args, **kwargs: {TRIP_1_PK: [1, 2, 3, 4], TRIP_2_PK: [3, 1, 0]},
    )
    monkeypatch.setattr(
        stopqueries,
        "get_stop_pk_to_station_pk_map_in_system",
        lambda *args, **kwargs: {0: 0, 1: 11, 2: 2, 3: 3, 4: 14},
    )

    new_service_map = models.ServiceMap()
    _build_service_map_from_paths = mock.MagicMock()
    monkeypatch.setattr(
        servicemapmanager,
        "_build_service_map_from_paths",
        _build_service_map_from_paths,
    )
    _build_service_map_from_paths.return_value = new_service_map

    expected_paths = {(11, 2, 3, 14), (0, 11, 3)}

    servicemapmanager.calculate_realtime_service_map_for_route(route_1)

    _build_service_map_from_paths.assert_called_once_with(expected_paths)
    assert route_1.pk == new_service_map.route_pk
    assert service_map_group.pk == new_service_map.group_pk
Exemplo n.º 7
0
 ],
 [
     models.Alert,
     [
         models.Alert(
             id="alert",
             cause=models.Alert.Cause.DEMONSTRATION,
             effect=models.Alert.Effect.DETOUR,
         )
     ],
     [],
     (0, 0, 1),
 ],
 [
     models.Route,
     [models.Route(id="route", description="old route")],
     [new_route],
     (0, 1, 0),
 ],
 [models.Route, [], [new_route], (1, 0, 0)],
 [
     models.Route,
     [models.Route(id="route", description="old route")],
     [new_route],
     (0, 1, 0),
 ],
 [
     models.Agency,
     [models.Agency(id="agency", name="old agency", timezone="")],
     [new_agency],
     (0, 1, 0),
Exemplo n.º 8
0
def route_1_1(add_model, system_1, feed_1_1_update_1):
    return add_model(
        models.Route(pk=201,
                     id=ROUTE_1_1_ID,
                     system=system_1,
                     source=feed_1_1_update_1))
Exemplo n.º 9
0
def route_2_1(add_model, system_2, feed_2_1_update_1):
    return add_model(
        models.Route(pk=207,
                     id="208",
                     system=system_2,
                     source=feed_2_1_update_1))
Exemplo n.º 10
0
def route_1_3(add_model, system_1, feed_1_1_update_1):
    return add_model(
        models.Route(pk=205,
                     id="206",
                     system=system_1,
                     source=feed_1_1_update_1))