Esempio n. 1
0
def one_best_test():
    def check(profile, type):
        scenario = keolis.Scenario()
        response = response_pb2.Response()
        journey_direct = response.journeys.add()

        journey_direct.type = "best"
        #we set the destination else the filter will not be applicated
        req = {'debug': False, 'destination': 'foo'}
        scenario._qualification(req, response, travelers_profile[profile])
        eq_(type, journey_direct.type)

    for profile in travelers_profile.keys():
        yield (check, profile, 'rapid')
Esempio n. 2
0
def best_and_fallback_test():
    def check(profile, type_direct, type_fallback_walking, type_fallback_bike,
              nb):
        scenario = keolis.Scenario()

        response = response_pb2.Response()
        journey_direct = response.journeys.add()
        journey_fallback_walking = response.journeys.add()
        journey_fallback_bike = response.journeys.add()

        journey_direct.type = "best"
        journey_fallback_walking.type = "less_fallback_walk"
        journey_fallback_bike.type = "less_fallback_bss"
        #we set the destination else the filter will not be applicated
        req = {'debug': False, 'destination': 'foo'}
        scenario._qualification(req, response, travelers_profile[profile])
        eq_(type_direct, journey_direct.type)
        eq_(type_fallback_walking, journey_fallback_walking.type)
        eq_(type_fallback_bike, journey_fallback_bike.type)
        eq_(len(response.journeys), nb)

    for profile in travelers_profile.keys():
        yield (check, profile, 'rapid', 'comfort', '', 2)
Esempio n. 3
0
    def __init__(self):
        # journeys must have a custom authentication process
        ResourceUri.__init__(self, authentication=False)
        ResourceUtc.__init__(self)
        modes = ["walking", "car", "bike", "bss"]
        types = {
            "all": "All types",
            "best": "The best journey",
            "rapid": "A good trade off between duration, changes and constraint respect",
            'no_train': "Journey without train",
            'comfort': "A journey with less changes and walking",
            'car': "A journey with car to get to the public transport",
            'less_fallback_walk': "A journey with less walking",
            'less_fallback_bike': "A journey with less biking",
            'less_fallback_bss': "A journey with less bss",
            'fastest': "A journey with minimum duration",
            'non_pt_walk': "A journey without public transport, only walking",
            'non_pt_bike': "A journey without public transport, only biking",
            'non_pt_bss': "A journey without public transport, only bike sharing",
        }

        self.parsers = {}
        self.parsers["get"] = reqparse.RequestParser(
            argument_class=ArgumentDoc)
        parser_get = self.parsers["get"]
        parser_get.add_argument("from", type=str, dest="origin")
        parser_get.add_argument("to", type=str, dest="destination")
        parser_get.add_argument("datetime", type=date_time_format)
        parser_get.add_argument("datetime_represents", dest="clockwise",
                                type=dt_represents, default=True)
        parser_get.add_argument("max_nb_transfers", type=int, dest="max_transfers")
        parser_get.add_argument("first_section_mode[]",
                                type=option_value(modes),
                                default=["walking"],
                                dest="origin_mode", action="append")
        parser_get.add_argument("last_section_mode[]",
                                type=option_value(modes),
                                default=["walking"],
                                dest="destination_mode", action="append")
        parser_get.add_argument("max_duration_to_pt", type=int,
                                description="maximal duration of non public transport in second")

        parser_get.add_argument("max_walking_duration_to_pt", type=int,
                                description="maximal duration of walking on public transport in second")
        parser_get.add_argument("max_bike_duration_to_pt", type=int,
                                description="maximal duration of bike on public transport in second")
        parser_get.add_argument("max_bss_duration_to_pt", type=int,
                                description="maximal duration of bss on public transport in second")
        parser_get.add_argument("max_car_duration_to_pt", type=int,
                                description="maximal duration of car on public transport in second")

        parser_get.add_argument("walking_speed", type=float)
        parser_get.add_argument("bike_speed", type=float)
        parser_get.add_argument("bss_speed", type=float)
        parser_get.add_argument("car_speed", type=float)
        parser_get.add_argument("forbidden_uris[]", type=str, action="append")
        parser_get.add_argument("count", type=int)
        parser_get.add_argument("min_nb_journeys", type=int)
        parser_get.add_argument("max_nb_journeys", type=int)
        parser_get.add_argument("type", type=option_value(types),
                                default="all")
        parser_get.add_argument("disruption_active",
                                type=boolean, default=False)
# a supprimer
        parser_get.add_argument("max_duration", type=int, default=3600*24)
        parser_get.add_argument("wheelchair", type=boolean, default=False)
        parser_get.add_argument("debug", type=boolean, default=False,
                                hidden=True)
        # for retrocompatibility purpose, we duplicate (without []):
        parser_get.add_argument("first_section_mode",
                                type=option_value(modes), action="append")
        parser_get.add_argument("last_section_mode",
                                type=option_value(modes), action="append")
        parser_get.add_argument("show_codes", type=boolean, default=False,
                            description="show more identification codes")
        parser_get.add_argument("traveler_type", type=option_value(travelers_profile.keys()))
        parser_get.add_argument("_override_scenario", type=str, description="debug param to specify a custom scenario")

        self.method_decorators.append(complete_links(self))

        # manage post protocol (n-m calculation)
        self.parsers["post"] = deepcopy(parser_get)
        parser_post = self.parsers["post"]
        parser_post.add_argument("details", type=boolean, default=False, location="json")
        for index, elem in enumerate(parser_post.args):
            if elem.name in ["from", "to"]:
                parser_post.args[index].type = list
                parser_post.args[index].dest = elem.name
            parser_post.args[index].location = "json"