Example #1
0
def get_ridesharing_service_test():
    configs = [
        {
            "class": "jormungandr.scenarios.ridesharing.karos.Karos",
            "args": {
                "service_url": "toto",
                "api_key": "toto key",
                "network": "N",
                "timeout": 10,
                "timedelta": 7000,
                "departure_radius": 15,
                "arrival_radius": 15,
                "feed_publisher": DUMMY_KAROS_FEED_PUBLISHER,
            },
        },
        {
            "class": "jormungandr.scenarios.ridesharing.karos.Karos",
            "args": {
                "service_url": "tata",
                "api_key": "tata key",
                "network": "M"
            },
        },
    ]
    instance = DummyInstance()
    ridesharing_service_manager = RidesharingServiceManager(instance, configs)
    ridesharing_service_manager.init_ridesharing_services()
    services = ridesharing_service_manager.get_all_ridesharing_services()
    assert len(services) == 2

    assert services[0].service_url == 'toto'
    assert services[0].api_key == 'toto key'
    assert services[0].network == 'N'
    assert services[0].system_id == 'karos'
    assert services[0].timeout == 10
    assert services[0].timedelta == 7000
    assert services[0].departure_radius == 15
    assert services[0].arrival_radius == 15
    assert services[0]._get_feed_publisher() == RsFeedPublisher(
        **DUMMY_KAROS_FEED_PUBLISHER)

    assert services[1].service_url == 'tata'
    assert services[1].api_key == 'tata key'
    assert services[1].network == 'M'
    assert services[1].system_id == 'karos'
    # Default values
    assert services[1].timeout == 2
    assert services[1].timedelta == 3600
    assert services[1].departure_radius == 2
    assert services[1].arrival_radius == 2

    assert services[1]._get_feed_publisher() == RsFeedPublisher(
        **DEFAULT_KAROS_FEED_PUBLISHER)
Example #2
0
def get_ridesharing_service_test():
    configs = [
        {
            "class":
            "jormungandr.scenarios.ridesharing.instant_system.InstantSystem",
            "args": {
                "service_url": "toto",
                "api_key": "toto key",
                "network": "N",
                "rating_scale_min": 0,
                "rating_scale_max": 10,
                "crowfly_radius": 200,
                "timeframe_duration": 1800,
                "feed_publisher": DUMMY_INSTANT_SYSTEM_FEED_PUBLISHER,
            },
        },
        {
            "class":
            "jormungandr.scenarios.ridesharing.instant_system.InstantSystem",
            "args": {
                "service_url": "tata",
                "api_key": "tata key",
                "network": "M",
                "rating_scale_min": 1,
                "rating_scale_max": 5,
                "crowfly_radius": 200,
                "timeframe_duration": 1800,
            },
        },
    ]
    instance = DummyInstance()
    ridesharing_service_manager = RidesharingServiceManager(instance, configs)
    ridesharing_service_manager.init_ridesharing_services()
    services = ridesharing_service_manager.get_all_ridesharing_services()
    assert len(services) == 2

    assert services[0].service_url == 'toto'
    assert services[0].api_key == 'toto key'
    assert services[0].network == 'N'
    assert services[0].system_id == 'instant_system'
    assert services[0].rating_scale_min == 0
    assert services[0].rating_scale_max == 10
    assert services[0]._get_feed_publisher() == RsFeedPublisher(
        **DUMMY_INSTANT_SYSTEM_FEED_PUBLISHER)

    assert services[1].service_url == 'tata'
    assert services[1].api_key == 'tata key'
    assert services[1].network == 'M'
    assert services[1].system_id == 'instant_system'
    assert services[1].rating_scale_min == 1
    assert services[1].rating_scale_max == 5
    assert services[1]._get_feed_publisher() == RsFeedPublisher(
        **DEFAULT_INSTANT_SYSTEM_FEED_PUBLISHER)
Example #3
0
    def __init__(self,
                 instance,
                 service_url,
                 api_key,
                 network,
                 feed_publisher=DEFAULT_INSTANT_SYSTEM_FEED_PUBLISHER,
                 rating_scale_min=None,
                 rating_scale_max=None,
                 timeout=2):
        self.instance = instance
        self.service_url = service_url
        self.api_key = api_key
        self.network = network
        self.rating_scale_min = rating_scale_min
        self.rating_scale_max = rating_scale_max
        self.system_id = 'Instant System'
        self.timeout = timeout
        self.feed_publisher = None if feed_publisher is None else RsFeedPublisher(
            **feed_publisher)

        self.journey_metadata = rsj.MetaData(
            system_id=self.system_id,
            network=self.network,
            rating_scale_min=self.rating_scale_min,
            rating_scale_max=self.rating_scale_max)

        self.logger = logging.getLogger("{} {}".format(__name__,
                                                       self.system_id))

        self.breaker = pybreaker.CircuitBreaker(
            fail_max=app.config['CIRCUIT_BREAKER_MAX_INSTANT_SYSTEM_FAIL'],
            reset_timeout=app.
            config['CIRCUIT_BREAKER_INSTANT_SYSTEM_TIMEOUT_S'])
Example #4
0
    def __init__(
        self,
        service_url,
        api_key,
        network,
        feed_publisher=DEFAULT_BLABLALINES_FEED_PUBLISHER,
        timedelta=3600,
        timeout=2,
    ):
        self.service_url = service_url
        self.api_key = api_key
        self.network = network
        self.system_id = 'blablalines'
        self.timeout = timeout
        self.timedelta = timedelta
        self.feed_publisher = None if feed_publisher is None else RsFeedPublisher(
            **feed_publisher)

        self.logger = logging.getLogger("{} {}".format(__name__,
                                                       self.system_id))

        self.breaker = pybreaker.CircuitBreaker(
            fail_max=app.config.get(
                str('CIRCUIT_BREAKER_MAX_BLABLALINES_FAIL'), 4),
            reset_timeout=app.config.get(
                str('CIRCUIT_BREAKER_BLABLALINES_TIMEOUT_S'), 60),
        )
        self.call_params = ''

        self.journey_metadata = rsj.MetaData(system_id=self.system_id,
                                             network=self.network,
                                             rating_scale_min=None,
                                             rating_scale_max=None)
Example #5
0
def get_ridesharing_service_test():
    configs = [
        {
            "class":
            "jormungandr.scenarios.ridesharing.instant_system.InstantSystem",
            "args": {
                "service_url": "toto",
                "api_key": "toto key",
                "network": "N",
                "rating_scale_min": 0,
                "rating_scale_max": 10,
                "feed_publisher": DUMMY_INSTANT_SYSTEM_FEED_PUBLISHER,
            },
        },
        {
            "class":
            "jormungandr.scenarios.ridesharing.instant_system.InstantSystem",
            "args": {
                "service_url": "tata",
                "api_key": "tata key",
                "network": "M",
                "rating_scale_min": 1,
                "rating_scale_max": 5,
            },
        },
    ]

    services = Ridesharing.get_ridesharing_services(DummyInstance(), configs)
    assert len(services) == 2

    assert services[0].service_url == 'toto'
    assert services[0].api_key == 'toto key'
    assert services[0].network == 'N'
    assert services[0].system_id == 'Instant System'
    assert services[0].rating_scale_min == 0
    assert services[0].rating_scale_max == 10
    assert services[0]._get_feed_publisher() == RsFeedPublisher(
        **DUMMY_INSTANT_SYSTEM_FEED_PUBLISHER)

    assert services[1].service_url == 'tata'
    assert services[1].api_key == 'tata key'
    assert services[1].network == 'M'
    assert services[1].system_id == 'Instant System'
    assert services[1].rating_scale_min == 1
    assert services[1].rating_scale_max == 5
    assert services[1]._get_feed_publisher() == RsFeedPublisher(
        **DEFAULT_INSTANT_SYSTEM_FEED_PUBLISHER)
Example #6
0
def get_ridesharing_service_test():
    configs = [
        {
            "class":
            "jormungandr.scenarios.ridesharing.blablalines.Blablalines",
            "args": {
                "service_url": "toto",
                "api_key": "toto key",
                "network": "N",
                "feed_publisher": DUMMY_BLABLALINES_FEED_PUBLISHER,
            },
        },
        {
            "class":
            "jormungandr.scenarios.ridesharing.blablalines.Blablalines",
            "args": {
                "service_url": "tata",
                "api_key": "tata key",
                "network": "M"
            },
        },
    ]
    instance = DummyInstance()
    ridesharing_service_manager = RidesharingServiceManager(instance, configs)
    ridesharing_service_manager.init_ridesharing_services()
    services = ridesharing_service_manager.get_all_ridesharing_services()

    assert len(services) == 2

    assert services[0].service_url == 'toto'
    assert services[0].api_key == 'toto key'
    assert services[0].network == 'N'
    assert services[0].system_id == 'blablalines'
    assert services[0]._get_feed_publisher() == RsFeedPublisher(
        **DUMMY_BLABLALINES_FEED_PUBLISHER)

    assert services[1].service_url == 'tata'
    assert services[1].api_key == 'tata key'
    assert services[1].network == 'M'
    assert services[1].system_id == 'blablalines'
    assert services[1]._get_feed_publisher() == RsFeedPublisher(
        **DEFAULT_BLABLALINES_FEED_PUBLISHER)
Example #7
0
    def __init__(
        self,
        service_url,
        api_key,
        network,
        feed_publisher=DEFAULT_KLAXIT_FEED_PUBLISHER,
        timedelta=3600,
        timeout=2,
        departure_radius=2,
        arrival_radius=2,
        rating_scale_min=None,
        rating_scale_max=None,
    ):
        self.service_url = service_url
        self.api_key = api_key
        self.network = network
        self.system_id = 'klaxit'
        self.timeout = timeout
        self.timedelta = timedelta
        self.departure_radius = departure_radius
        self.arrival_radius = arrival_radius
        self.rating_scale_min = rating_scale_min
        self.rating_scale_max = rating_scale_max
        self.feed_publisher = None if feed_publisher is None else RsFeedPublisher(
            **feed_publisher)

        self.journey_metadata = rsj.MetaData(
            system_id=self.system_id,
            network=self.network,
            rating_scale_min=self.rating_scale_min,
            rating_scale_max=self.rating_scale_max,
        )

        self.logger = logging.getLogger("{} {}".format(__name__,
                                                       self.system_id))

        self.breaker = pybreaker.CircuitBreaker(
            fail_max=app.config.get(str('CIRCUIT_BREAKER_MAX_KLAXIT_FAIL'), 4),
            reset_timeout=app.config.get(
                str('CIRCUIT_BREAKER_KLAXIT_TIMEOUT_S'), 60),
        )
        self.call_params = ''
Example #8
0
    def __init__(
        self,
        service_url,
        api_key,
        network,
        feed_publisher=DEFAULT_INSTANT_SYSTEM_FEED_PUBLISHER,
        rating_scale_min=None,
        rating_scale_max=None,
        timeout=5,
        crowfly_radius=200,
        timeframe_duration=1800,
    ):
        self.service_url = service_url
        self.api_key = api_key
        self.network = network
        self.rating_scale_min = rating_scale_min
        self.rating_scale_max = rating_scale_max
        self.system_id = 'instant_system'
        self.timeout = timeout
        self.feed_publisher = None if feed_publisher is None else RsFeedPublisher(
            **feed_publisher)
        self.crowfly_radius = crowfly_radius
        self.timeframe_duration = timeframe_duration

        self.journey_metadata = rsj.MetaData(
            system_id=self.system_id,
            network=self.network,
            rating_scale_min=self.rating_scale_min,
            rating_scale_max=self.rating_scale_max,
        )

        self.logger = logging.getLogger("{} {}".format(__name__,
                                                       self.system_id))

        self.breaker = pybreaker.CircuitBreaker(
            fail_max=app.config.get(
                str('CIRCUIT_BREAKER_MAX_INSTANT_SYSTEM_FAIL'), 4),
            reset_timeout=app.config.get(
                str('CIRCUIT_BREAKER_INSTANT_SYSTEM_TIMEOUT_S'), 60),
        )
        self.call_params = ''
Example #9
0
def blablalines_test():
    with mock.patch('requests.get', mock_get):

        blablalines = Blablalines(
            service_url='dummyUrl',
            api_key='dummyApiKey',
            network='dummyNetwork',
            feed_publisher=DUMMY_BLABLALINES_FEED_PUBLISHER,
        )
        from_coord = '47.28696,0.78981'
        to_coord = '47.38642,0.69039'

        period_extremity = utils.PeriodExtremity(
            datetime=utils.str_to_time_stamp("20171225T060000"),
            represents_start=True)
        ridesharing_journeys, feed_publisher = blablalines.request_journeys_with_feed_publisher(
            from_coord=from_coord,
            to_coord=to_coord,
            period_extremity=period_extremity,
            instance_params=DummyInstance(),
        )

        assert len(ridesharing_journeys) == 2
        assert ridesharing_journeys[0].metadata.network == 'dummyNetwork'
        assert ridesharing_journeys[0].metadata.system_id == 'blablalines'
        assert ridesharing_journeys[
            0].ridesharing_ad == 'https://blablalines.com'

        assert ridesharing_journeys[
            0].pickup_place.addr == ""  # address is not provided in mock
        assert ridesharing_journeys[0].pickup_place.lat == 47.28696
        assert ridesharing_journeys[0].pickup_place.lon == 0.78981

        assert ridesharing_journeys[
            0].dropoff_place.addr == ""  # address is not provided in mock
        assert ridesharing_journeys[0].dropoff_place.lat == 47.38642
        assert ridesharing_journeys[0].dropoff_place.lon == 0.69039

        assert ridesharing_journeys[0].shape
        assert ridesharing_journeys[0].shape[0].lat == ridesharing_journeys[
            0].pickup_place.lat
        assert ridesharing_journeys[0].shape[0].lon == ridesharing_journeys[
            0].pickup_place.lon
        assert ridesharing_journeys[0].shape[
            1].lat == 47.28698  # test that we really load a shape
        assert ridesharing_journeys[0].shape[1].lon == 0.78975
        assert ridesharing_journeys[0].shape[-1].lat == ridesharing_journeys[
            0].dropoff_place.lat
        assert ridesharing_journeys[0].shape[-1].lon == ridesharing_journeys[
            0].dropoff_place.lon

        assert ridesharing_journeys[0].price == 100.0
        assert ridesharing_journeys[0].currency == 'centime'

        assert ridesharing_journeys[0].total_seats is None
        assert ridesharing_journeys[0].available_seats == 3

        assert ridesharing_journeys[1].metadata.network == 'dummyNetwork'
        assert ridesharing_journeys[1].metadata.system_id == 'blablalines'
        assert ridesharing_journeys[1].shape
        assert ridesharing_journeys[
            1].ridesharing_ad == 'https://blablalines.com'

        assert ridesharing_journeys[1].pickup_place.addr == ""
        assert ridesharing_journeys[1].pickup_place.lat == 47.28696
        assert ridesharing_journeys[1].pickup_place.lon == 0.78981

        assert ridesharing_journeys[1].dropoff_place.addr == ""
        assert ridesharing_journeys[1].dropoff_place.lat == 47.38399
        assert ridesharing_journeys[1].dropoff_place.lon == 0.69192

        assert ridesharing_journeys[1].price == 300.0
        assert ridesharing_journeys[1].currency == 'centime'

        assert ridesharing_journeys[1].total_seats is None
        assert ridesharing_journeys[1].available_seats == 2

        assert feed_publisher == RsFeedPublisher(
            **DUMMY_BLABLALINES_FEED_PUBLISHER)
Example #10
0
def instant_system_test():
    with mock.patch('requests.get', mock_get):

        instant_system = InstantSystem(
            service_url='dummyUrl',
            api_key='dummyApiKey',
            network='dummyNetwork',
            feed_publisher=DUMMY_INSTANT_SYSTEM_FEED_PUBLISHER,
            rating_scale_min=0,
            rating_scale_max=10,
        )
        from_coord = '48.109377,-1.682103'
        to_coord = '48.020335,-1.743929'

        period_extremity = utils.PeriodExtremity(
            datetime=utils.str_to_time_stamp("20171225T060000"),
            represents_start=True)

        params = RidesharingServiceManager.InstanceParams.make_params(
            DummyInstance())
        ridesharing_journeys, feed_publisher = instant_system.request_journeys_with_feed_publisher(
            from_coord=from_coord,
            to_coord=to_coord,
            period_extremity=period_extremity,
            instance_params=params)

        assert len(ridesharing_journeys) == 2
        assert ridesharing_journeys[0].metadata.network == 'dummyNetwork'
        assert ridesharing_journeys[0].metadata.system_id == 'instant_system'
        assert ridesharing_journeys[0].metadata.rating_scale_min == 0
        assert ridesharing_journeys[0].metadata.rating_scale_max == 10
        assert (
            ridesharing_journeys[0].ridesharing_ad ==
            'https://jky8k.app.goo.gl/?efr=1&apn=com.is.android.rennes&ibi=&isi=&utm_campaign=KISIO&link=https%3A%2F%2Fwww.star.fr%2Fsearch%2F%3FfeatureName%3DsearchResultDetail%26networkId%3D33%26journeyId%3D4bcd0b9d-2c9d-42a2-8ffb-4508c952f4fb'
        )

        assert ridesharing_journeys[
            0].pickup_place.addr == ""  # address is not provided in mock
        assert ridesharing_journeys[0].pickup_place.lat == 48.1102
        assert ridesharing_journeys[0].pickup_place.lon == -1.68623

        assert ridesharing_journeys[
            0].dropoff_place.addr == ""  # address is not provided in mock
        assert ridesharing_journeys[0].dropoff_place.lat == 48.02479
        assert ridesharing_journeys[0].dropoff_place.lon == -1.74673

        assert len(ridesharing_journeys[0].shape) > 3
        assert ridesharing_journeys[0].shape[0].lat == ridesharing_journeys[
            0].pickup_place.lat
        assert ridesharing_journeys[0].shape[0].lon == ridesharing_journeys[
            0].pickup_place.lon
        assert ridesharing_journeys[0].shape[
            1].lat == 48.1101  # test that we really load a shape
        assert ridesharing_journeys[0].shape[1].lon == -1.68635
        assert ridesharing_journeys[0].shape[-1].lat == ridesharing_journeys[
            0].dropoff_place.lat
        assert ridesharing_journeys[0].shape[-1].lon == ridesharing_journeys[
            0].dropoff_place.lon

        assert ridesharing_journeys[
            0].pickup_date_time == utils.str_to_time_stamp("20171225T070759")
        assert ridesharing_journeys[
            0].dropoff_date_time == utils.str_to_time_stamp("20171225T072536")

        assert ridesharing_journeys[0].driver.alias == 'Jean P.'
        assert ridesharing_journeys[0].driver.gender == Gender.MALE
        assert ridesharing_journeys[
            0].driver.image == 'https://dummyimage.com/128x128/C8E6C9/000.png&text=JP'
        assert ridesharing_journeys[0].driver.rate == 0
        assert ridesharing_journeys[0].driver.rate_count == 0

        assert ridesharing_journeys[0].price == 170
        assert ridesharing_journeys[0].currency == 'centime'

        assert ridesharing_journeys[0].total_seats is None
        assert ridesharing_journeys[0].available_seats == 4

        assert ridesharing_journeys[1].metadata.network == 'dummyNetwork'
        assert ridesharing_journeys[1].metadata.system_id == 'instant_system'
        assert ridesharing_journeys[1].metadata.rating_scale_min == 0
        assert ridesharing_journeys[1].metadata.rating_scale_max == 10
        # the shape should not be none, but we don't test the whole string
        assert ridesharing_journeys[1].shape
        assert (
            ridesharing_journeys[1].ridesharing_ad ==
            "https://jky8k.app.goo.gl/?efr=1&apn=com.is.android.rennes&ibi=&isi=&utm_campaign=KISIO&link=https%3A%2F%2Fwww.star.fr%2Fsearch%2F%3FfeatureName%3DsearchResultDetail%26networkId%3D33%26journeyId%3D05223c04-834d-4710-905f-aa3796da5837"
        )

        assert ridesharing_journeys[1].pickup_place.addr == ""
        assert ridesharing_journeys[1].pickup_place.lat == 48.1102
        assert ridesharing_journeys[1].pickup_place.lon == -1.68623

        assert ridesharing_journeys[1].dropoff_place.addr == ""
        assert ridesharing_journeys[1].dropoff_place.lat == 48.03193
        assert ridesharing_journeys[1].dropoff_place.lon == -1.74635

        assert ridesharing_journeys[
            1].pickup_date_time == utils.str_to_time_stamp("20171225T073542")
        assert ridesharing_journeys[
            1].dropoff_date_time == utils.str_to_time_stamp("20171225T075309")

        assert ridesharing_journeys[1].driver.alias == 'Alice M.'
        assert ridesharing_journeys[1].driver.gender == Gender.FEMALE
        assert ridesharing_journeys[
            1].driver.image == 'https://dummyimage.com/128x128/B2EBF2/000.png&text=AM'
        assert ridesharing_journeys[1].driver.rate == 0
        assert ridesharing_journeys[1].driver.rate_count == 0

        assert ridesharing_journeys[1].price == 0
        assert ridesharing_journeys[1].currency == 'centime'

        assert ridesharing_journeys[1].total_seats is None
        assert ridesharing_journeys[1].available_seats == 4

        assert feed_publisher == RsFeedPublisher(
            **DUMMY_INSTANT_SYSTEM_FEED_PUBLISHER)
Example #11
0
def klaxit_service_test():
    with mock.patch('requests.get', mock_get):

        klaxit = Klaxit(
            service_url='dummyUrl',
            api_key='dummyApiKey',
            network='dummyNetwork',
            feed_publisher=DUMMY_KLAXIT_FEED_PUBLISHER,
        )
        from_coord = '47.28696,0.78981'
        to_coord = '47.38642,0.69039'

        period_extremity = utils.PeriodExtremity(
            datetime=utils.str_to_time_stamp("20171225T060000"),
            represents_start=True)
        params = RidesharingServiceManager.InstanceParams.make_params(
            DummyInstance())
        ridesharing_journeys, feed_publisher = klaxit.request_journeys_with_feed_publisher(
            from_coord=from_coord,
            to_coord=to_coord,
            period_extremity=period_extremity,
            instance_params=params)

        assert len(ridesharing_journeys) == 2
        assert ridesharing_journeys[0].metadata.network == 'dummyNetwork'
        assert ridesharing_journeys[0].metadata.system_id == 'klaxit'
        assert ridesharing_journeys[
            0].ridesharing_ad == 'https://klaxit.app.link'

        assert ridesharing_journeys[
            0].pickup_place.addr == ""  # address is not provided in mock
        assert ridesharing_journeys[0].pickup_place.lat == 48.8898252102323
        assert ridesharing_journeys[0].pickup_place.lon == 2.37550085289956

        assert ridesharing_journeys[
            0].dropoff_place.addr == ""  # address is not provided in mock
        assert ridesharing_journeys[0].dropoff_place.lat == 48.85658
        assert ridesharing_journeys[0].dropoff_place.lon == 2.37729

        assert ridesharing_journeys[0].shape
        assert ridesharing_journeys[0].shape[0].lat == ridesharing_journeys[
            0].pickup_place.lat
        assert ridesharing_journeys[0].shape[0].lon == ridesharing_journeys[
            0].pickup_place.lon
        assert ridesharing_journeys[0].shape[
            1].lat == 48.88981  # test that we really load a shape
        assert ridesharing_journeys[0].shape[1].lon == 2.37553
        assert ridesharing_journeys[0].shape[-1].lat == ridesharing_journeys[
            0].dropoff_place.lat
        assert ridesharing_journeys[0].shape[-1].lon == ridesharing_journeys[
            0].dropoff_place.lon

        assert ridesharing_journeys[0].price == 51.0
        assert ridesharing_journeys[0].currency == 'centime'

        # Klaxit doesn't have any information on seats
        assert ridesharing_journeys[0].total_seats is None
        assert ridesharing_journeys[0].available_seats is None

        assert ridesharing_journeys[1].metadata.network == 'dummyNetwork'
        assert ridesharing_journeys[1].metadata.system_id == 'klaxit'
        assert ridesharing_journeys[1].shape
        assert ridesharing_journeys[
            1].ridesharing_ad == 'https://klaxit.app.link'

        assert ridesharing_journeys[1].pickup_place.addr == ""
        assert ridesharing_journeys[1].pickup_place.lat == 48.8943912703919
        assert ridesharing_journeys[1].pickup_place.lon == 2.3724889755249

        assert ridesharing_journeys[1].dropoff_place.addr == ""
        assert ridesharing_journeys[1].dropoff_place.lat == 48.8559454289402
        assert ridesharing_journeys[1].dropoff_place.lon == 2.37563525508835

        assert ridesharing_journeys[1].price == pytest.approx(56.0, abs=0.01)
        assert ridesharing_journeys[1].currency == 'centime'

        # Klaxit doesn't have any information on seats
        assert ridesharing_journeys[1].total_seats is None
        assert ridesharing_journeys[1].available_seats is None

        assert feed_publisher == RsFeedPublisher(**DUMMY_KLAXIT_FEED_PUBLISHER)
Example #12
0
def karos_service_test():
    with mock.patch('requests.get', mock_get):

        karos = Karos(
            service_url='dummyUrl',
            api_key='dummyApiKey',
            network='dummyNetwork',
            feed_publisher=DUMMY_KAROS_FEED_PUBLISHER,
        )

        # Check status information
        status = karos.status()
        assert status['id'] == 'karos'
        assert status['class'] == 'Karos'
        assert status['network'] == 'dummyNetwork'
        assert status['circuit_breaker']['fail_counter'] == 0
        assert status['circuit_breaker']['current_state'] == 'closed'
        assert status['circuit_breaker']['reset_timeout'] == 60

        from_coord = '47.28696,0.78981'
        to_coord = '47.38642,0.69039'

        period_extremity = utils.PeriodExtremity(
            datetime=utils.str_to_time_stamp("20171225T060000"), represents_start=True
        )
        params = RidesharingServiceManager.InstanceParams.make_params(DummyInstance)
        ridesharing_journeys, feed_publisher = karos.request_journeys_with_feed_publisher(
            from_coord=from_coord, to_coord=to_coord, period_extremity=period_extremity, instance_params=params
        )

        assert len(ridesharing_journeys) == 2
        assert ridesharing_journeys[0].metadata.network == 'dummyNetwork'
        assert ridesharing_journeys[0].metadata.system_id == 'karos'
        assert (
            ridesharing_journeys[0].ridesharing_ad
            == 'https://www.karos.fr/vianavigo?data=eyJmaXJzdE5hbWUiOiAiQW50b25lbGxvIiwgImlkIjogImY3MmZlNWNkLWQyODctNDViMy1iMzViLTdkMmFmNTZmOWE2NiIsICJncmFkZSI6IDUsICJhZ2UiOiAyMCwgImxhc3ROYW1lIjogIk0iLCAiZHVyYXRpb25fc2luY2VfbGFzdF9sb2dpbiI6IDk0LCAiZGVwYXJ0dXJlVG9QaWNrdXBXYWxraW5nUG9seWxpbmUiOiAiaWp6aEhpZ19NYVl0YEAiLCAicGljdHVyZSI6ICJodHRwczovL3N0b3JhZ2UtZG93bmxvYWQuZ29vZ2xlYXBpcy5jb20va2Fyb3MtZGUuYXBwc3BvdC5jb20vcC8yMDYwOTg3Ny0yOWRiLTRjZTUtYmIwMy03Njg0MGM0ODY4ZmEuanBnIiwgImRyb3BvZmZUb0Fycml2YWxXYWxraW5nVGltZSI6IDU3NTIsICJwaG9uZV92ZXJpZmllZCI6IHRydWUsICJkdXJhdGlvbiI6IDY5NiwgInByaWNlIjogeyJhbW91bnQiOiAyLjAsICJkaXNjb3VudCI6IDAuMH0sICJnZW5kZXIiOiAiTSIsICJyZXNwb25zZV9yYXRlIjogMC44NDg0ODQ4NDg0ODQ4NDg1LCAiZHJvcG9mZlRvQXJyaXZhbFdhbGtpbmdQb2x5bGluZSI6ICJjd3ZoSGdxZ0x+ZkJieFIiLCAiZGVwYXJ0dXJlX3RpbWUiOiAxNjAyMDY4NTM5LCAibmJfY2FycG9vbCI6IDQzLCAiZGVwYXJ0dXJlVG9QaWNrdXBXYWxraW5nVGltZSI6IDQ1NywgImpvdXJuZXlQb2x5bGluZSI6ICJrZHtoSHNlfkxSZkBSZkBiQn5DakhqTWpDbkZ6QG5BYkJyRD9SUmZAUj9SU3pFekpSZkB6QG5BakNiR3pAYkJSUnpAYkJ+SHpPfkNqSFJSbkF2QmZAYkJ2QmJCekBuQT9mQFJ2QnJEckk/ZkB+Q2ZKUlJuQWJHbkFyRFJmQG5BckRmQHZCekBqQz9SUmZAZkBiQmZAdkJiQnpFfkNmSlJ6QD9SfkNuS1JmQHpAdkJmQGpDekBqQ1JmQFJmQFJmQFJuQVJmQG5BfkNmQGJCP2ZAUmZAdkJ2Rz9SekB2QmZAdkJ6QGpDUm5BekBqQ1JSUnpAYkJuRj9SYkJuRmJCekU/ZkByRGJMbkFyRFJmQD9mQD9SbkFyRFJuQW5BckR2QmpIPz8/ZkBmQFI/Um5GalJ6QHZCUm5BP1I/ZkBSYkJmQD9Se0BTe0BnQHtAP1NnQHtAa0hjVj8/UmdAU1NTU1NSP2ZAZkBSP1JuRmpSekB2QlJuQT9SP2ZAUmJCP3pAUz8/YkdTZkpvQXJdZ0B+V29Bel53THZgRWdAZkpvQWpXZ0BiR3NEckQifQ=='
        )

        assert ridesharing_journeys[0].pickup_place.addr == ""  # address is not provided in mock
        assert ridesharing_journeys[0].pickup_place.lat == 48.8047
        assert ridesharing_journeys[0].pickup_place.lon == 2.2897

        assert ridesharing_journeys[0].dropoff_place.addr == ""  # address is not provided in mock
        assert ridesharing_journeys[0].dropoff_place.lat == 48.7821
        assert ridesharing_journeys[0].dropoff_place.lon == 2.1738

        assert ridesharing_journeys[0].shape
        assert ridesharing_journeys[0].shape[0].lat == ridesharing_journeys[0].pickup_place.lat
        assert ridesharing_journeys[0].shape[0].lon == ridesharing_journeys[0].pickup_place.lon
        assert ridesharing_journeys[0].shape[1].lat == 48.8046  # test that we really load a shape
        assert ridesharing_journeys[0].shape[1].lon == 2.2895
        assert ridesharing_journeys[0].shape[-1].lat == ridesharing_journeys[0].dropoff_place.lat
        assert ridesharing_journeys[0].shape[-1].lon == ridesharing_journeys[0].dropoff_place.lon

        assert ridesharing_journeys[0].driver.alias == 'Antonello'
        assert ridesharing_journeys[0].driver.gender == Gender.MALE
        assert ridesharing_journeys[0].driver.image == 'https://dummyimage.com/128x128/C8E6C9/000.png&text=JP'
        assert ridesharing_journeys[0].driver.rate == 5
        assert ridesharing_journeys[0].driver.rate_count is None

        assert ridesharing_journeys[0].price == 200.0
        assert ridesharing_journeys[0].currency == 'centime'
        assert ridesharing_journeys[0].total_seats is None
        assert ridesharing_journeys[0].available_seats == 3
        assert ridesharing_journeys[1].metadata.network == 'dummyNetwork'
        assert ridesharing_journeys[1].metadata.system_id == 'karos'
        assert ridesharing_journeys[1].shape
        assert (
            ridesharing_journeys[1].ridesharing_ad
            == 'https://www.karos.fr/vianavigo?data=eyJmaXJzdE5hbWUiOiAiY2Fyb2xpbmUiLCAiaWQiOiAiMTkwNzFlZTUtZjc2YS00MTMwLTkwZmYtMzM1NTFmOTFlZDBmIiwgImdyYWRlIjogNSwgImFnZSI6IDIwLCAibGFzdE5hbWUiOiAidCIsICJkdXJhdGlvbl9zaW5jZV9sYXN0X2xvZ2luIjogNjIzNCwgImRlcGFydHVyZVRvUGlja3VwV2Fsa2luZ1BvbHlsaW5lIjogImlqemhIaWdfTXxWeXRAIiwgInBpY3R1cmUiOiBudWxsLCAiZHJvcG9mZlRvQXJyaXZhbFdhbGtpbmdUaW1lIjogNTUwMCwgInBob25lX3ZlcmlmaWVkIjogdHJ1ZSwgImR1cmF0aW9uIjogMTE4MSwgInByaWNlIjogeyJhbW91bnQiOiAyLjAsICJkaXNjb3VudCI6IDAuMH0sICJnZW5kZXIiOiAiRiIsICJyZXNwb25zZV9yYXRlIjogMC45NjI5NjI5NjI5NjI5NjI5LCAiZHJvcG9mZlRvQXJyaXZhbFdhbGtpbmdQb2x5bGluZSI6ICJvZ2doSGN2eUtzZkt+fEQiLCAiZGVwYXJ0dXJlX3RpbWUiOiAxNjAyMDc0MTI3LCAibmJfY2FycG9vbCI6IDE0NiwgImRlcGFydHVyZVRvUGlja3VwV2Fsa2luZ1RpbWUiOiA1NzIsICJqb3VybmV5UG9seWxpbmUiOiAia3J5aEhjfWBNemlRfmVmQCJ9'
        )

        assert ridesharing_journeys[1].pickup_place.addr == ""
        assert ridesharing_journeys[1].pickup_place.lat == 48.7967
        assert ridesharing_journeys[1].pickup_place.lon == 2.3037

        assert ridesharing_journeys[1].dropoff_place.addr == ""
        assert ridesharing_journeys[1].dropoff_place.lat == 48.7028
        assert ridesharing_journeys[1].dropoff_place.lon == 2.1029

        assert ridesharing_journeys[1].price == 200.0
        assert ridesharing_journeys[1].currency == 'centime'
        assert ridesharing_journeys[1].total_seats is None
        assert ridesharing_journeys[1].available_seats == 3
        assert feed_publisher == RsFeedPublisher(**DUMMY_KAROS_FEED_PUBLISHER)