def test_equipment_reports_with_wrong_id(self): """ wrong id test """ # Bad id inside received data mock_equipment_providers( equipment_provider_manager=self.equipment_provider_manager( "main_routing_test"), data=wrong_mock_with_bad_id_data, code_types_list=["TCL_ASCENSEUR", "TCL_ESCALIER"], ) response = self.query_region('equipment_reports?' + default_date_filter) warnings = get_not_null(response, 'warnings') assert len(warnings) == 1 assert warnings[0]['id'] == 'beta_endpoint' # Expected response stopA_equipment_details = [ ("5", "elevator", "unknown"), ("1", "escalator", "unknown"), ("2", "escalator", "unknown"), ("3", "escalator", "unknown"), ("4", "escalator", "unknown"), ] stopb_equipment_details = [ ("6", "elevator", "unknown"), ("7", "elevator", "unknown"), ("8", "elevator", "unknown"), ("9", "elevator", "unknown"), ] expected_result = { "A": { "stopA": stopA_equipment_details, "stopB": stopb_equipment_details }, "B": { "stopA": stopA_equipment_details, "stopB": stopb_equipment_details }, "C": { "stopA": stopA_equipment_details, "stopB": stopb_equipment_details }, "D": { "stopA": stopA_equipment_details }, "M": { "stopA": stopA_equipment_details, "stopB": stopb_equipment_details }, } equipment_reports = get_not_null(response, 'equipment_reports') assert len(equipment_reports) == 5 for equipment_report in equipment_reports: is_valid_equipment_report(equipment_report) self._check_equipment_report(equipment_reports, expected_result)
def test_equipment_reports_with_forbidden_uris(self): """ with forbidden_uris parameters """ mock_equipment_providers( equipment_provider_manager=self.equipment_provider_manager("main_routing_test"), data=standard_mock_elevator_data, code_types_list=["TCL_ASCENSEUR", "TCL_ESCALIER"], ) response = self.query_region('equipment_reports?' + default_date_filter + default_forbidden_uris_filter) warnings = get_not_null(response, 'warnings') assert len(warnings) == 1 assert warnings[0]['id'] == 'beta_endpoint' # Expected response stopA_equipment_details = [ ("5", "elevator", "unknown"), ("1", "escalator", "unknown"), ("2", "escalator", "unknown"), ("3", "escalator", "unknown"), ("4", "escalator", "unknown"), ] # stop B is forbidden and there is only the D line which doesn't have stop point B. expected_result = {"D": {"stopA": stopA_equipment_details}} equipment_reports = get_not_null(response, 'equipment_reports') assert len(equipment_reports) == 1 for equipment_report in equipment_reports: is_valid_equipment_report(equipment_report) self._check_equipment_report(equipment_reports, expected_result)
def _check_train_delay_disruption(dis): is_valid_disruption(dis, chaos_disrup=False) eq_(dis['disruption_id'], 'vjA_delayed') eq_(dis['severity']['effect'], 'SIGNIFICANT_DELAYS') eq_(len(dis['impacted_objects']), 1) ptobj = dis['impacted_objects'][0]['pt_object'] eq_(ptobj['embedded_type'], 'trip') eq_(ptobj['id'], 'vjA') eq_(ptobj['name'], 'vjA') # for delay we should have detail on the impacted stops impacted_objs = get_not_null(dis['impacted_objects'][0], 'impacted_stops') assert len(impacted_objs) == 2 imp_obj1 = impacted_objs[0] eq_(get_valid_time(get_not_null(imp_obj1, 'amended_arrival_time')), _dt(h=8, m=2, s=24)) eq_(get_valid_time(get_not_null(imp_obj1, 'amended_departure_time')), _dt(h=8, m=2, s=25)) eq_(get_not_null(imp_obj1, 'cause'), 'cow on tracks') # for the moment we output 00000, but we should output the right base departure/arrival eq_(get_valid_time(get_not_null(imp_obj1, 'base_arrival_time')), _dt(8, 1, 0)) eq_(get_valid_time(get_not_null(imp_obj1, 'base_departure_time')), _dt(8, 1, 0)) imp_obj2 = impacted_objs[1] eq_(get_valid_time(get_not_null(imp_obj2, 'amended_arrival_time')), _dt(h=8, m=4, s=0)) eq_(get_valid_time(get_not_null(imp_obj2, 'amended_departure_time')), _dt(h=8, m=4, s=0)) eq_(imp_obj2['cause'], '') eq_(get_valid_time(get_not_null(imp_obj2, 'base_departure_time')), _dt(8, 1, 2)) eq_(get_valid_time(get_not_null(imp_obj2, 'base_arrival_time')), _dt(8, 1, 2))
def test_stop_schedule_with_realtime_only(self): mock_requests = MockRequests({ 'http://XXXX?stop_id=syn_stoppoint1': ( { "departures": [ { "line": "Kisio数字 A", "stop": "syn_stoppoint1", "direction_id": "3341", "direction_name": "Piscine Chambéry", "datetime": "2016-01-02T10:17:17+02:00", "type": "E", }, { "line": "Kisio数字 A", "stop": "syn_stoppoint1", "direction_id": "3341", "direction_name": "Piscine Chambéry", "type": "E", "datetime": "2016-01-02T11:17:17+02:00", }, ] }, 200, ) }) with mock.patch('requests.get', mock_requests.get): query = self.query_template_scs.format(sp='SP_1') response = self.query_region(query) scs = get_not_null(response, 'stop_schedules') assert len(scs) == 1 # 2016-01-02 08:17:00 assert get_schedule(scs, 'SP_1', 'code A') == [ { 'rt': True, 'dt': '20160102T081717' }, { 'rt': True, 'dt': '20160102T091717' }, ] query = self.query_template_dep.format(sp='SP_1') response = self.query_region(query) dep = get_not_null(response, 'departures') assert len(dep) == 2 assert get_departure(dep, 'SP_1', 'code A') == [ { 'rt': True, 'dt': '20160102T081717' }, { 'rt': True, 'dt': '20160102T091717' }, ]
def test_equipment_reports_with_uri(self): """ with uri filter """ mock_equipment_providers( equipment_provider_manager=self.equipment_provider_manager("main_routing_test"), data=standard_mock_elevator_data, code_types_list=["TCL_ASCENSEUR", "TCL_ESCALIER"], ) response = self.query_region(default_line_uri_filter + 'equipment_reports?' + default_date_filter) # Expected response stopA_equipment_details = [ ("5", "elevator", "unknown"), ("1", "escalator", "unknown"), ("2", "escalator", "unknown"), ("3", "escalator", "unknown"), ("4", "escalator", "unknown"), ] stopb_equipment_details = [ ("6", "elevator", "available"), ("7", "elevator", "unavailable"), ("8", "elevator", "unknown"), ("9", "elevator", "unknown"), ] # filtered with the A line that serve stopA and stopB expected_result = {"A": {"stopA": stopA_equipment_details, "stopB": stopb_equipment_details}} equipment_reports = get_not_null(response, 'equipment_reports') assert len(equipment_reports) == 1 for equipment_report in equipment_reports: is_valid_equipment_report(equipment_report) self._check_equipment_report(equipment_reports, expected_result) response = self.query_region(default_stop_areas_uri_filter + 'equipment_reports?' + default_date_filter) # Filtered with the stopA stop_area. # The A, B, C, D, M Line serve stopA expected_result = { "A": {"stopA": stopA_equipment_details}, "B": {"stopA": stopA_equipment_details}, "C": {"stopA": stopA_equipment_details}, "D": {"stopA": stopA_equipment_details}, "K": {"stopA": stopA_equipment_details}, "M": {"stopA": stopA_equipment_details}, "PM": {"stopA": stopA_equipment_details}, } equipment_reports = get_not_null(response, 'equipment_reports') assert len(equipment_reports) == 7 for equipment_report in equipment_reports: is_valid_equipment_report(equipment_report) self._check_equipment_report(equipment_reports, expected_result)
def test_feed_publishers(self): # With direct path q = ( "journeys?from={from_coord}&to={to_coord}&datetime={datetime}&first_section_mode[]=car_no_park" "&last_section_mode[]=car_no_park&debug=true&min_nb_journeys=0". format(from_coord=s_coord, to_coord=r_coord, datetime=QUERY_DATETIME_STR)) response = self.query_region(q) feeds = get_not_null(response, 'feed_publishers') assert len(feeds) == 2 feeds.sort(key=sortFeeds) assert feeds[0].get('id') == 'builder' assert feeds[0].get('name') == 'routing api data' assert feeds[0].get('license') == 'ODBL' assert feeds[0].get('url') == 'www.canaltp.fr' assert feeds[1].get('id') == 'here' assert feeds[1].get('name') == 'here' assert feeds[1].get('license') == 'Private' assert feeds[1].get( 'url') == 'https://developer.here.com/terms-and-conditions' # Without direct path q = ( "journeys?from={from_coord}&to={to_coord}&datetime={datetime}&first_section_mode[]=car_no_park" "&last_section_mode[]=car_no_park&debug=true&min_nb_journeys=0&direct_path=none" .format(from_coord=s_coord, to_coord=r_coord, datetime=QUERY_DATETIME_STR)) response = self.query_region(q) feeds = get_not_null(response, 'feed_publishers') assert len(feeds) == 2 feeds.sort(key=sortFeeds) assert feeds[0].get('id') == 'builder' assert feeds[0].get('name') == 'routing api data' assert feeds[0].get('license') == 'ODBL' assert feeds[0].get('url') == 'www.canaltp.fr' assert feeds[1].get('id') == 'here' assert feeds[1].get('name') == 'here' assert feeds[1].get('license') == 'Private' assert feeds[1].get( 'url') == 'https://developer.here.com/terms-and-conditions'
def test_pois_without_stands_on_places_nearby(self): with mock_bss_providers(pois_supported=['station_unknown']): r = self.query_region("places/admin:74435/places_nearby?count=20", display=False) places_nearby = get_not_null(r, 'places_nearby') assert {p[p['embedded_type']]['id'] for p in places_nearby} == { 'poi:parking_1', 'poi:station_1', 'stop_point:stopB', 'stopB', 'poi:station_2', 'poi:parking_2', 'stopC', 'stop_point:stopC', 'stopA', 'stop_point:stopA', 'stop_point:uselessA', } for p in places_nearby: embedded_type = p['embedded_type'] if embedded_type == 'poi': is_valid_poi(p[embedded_type]) assert not 'stands' in p[embedded_type]
def test_stop_schedule_bad_id_multiple_routes(self): """ test for a route point when the route code is not in synthese since there are multiple routes in navitia, we can't sort them out, and we don't get some realtime """ mock_requests = MockRequests({ 'http://bob.com?SERVICE=tdg&roid=syn_stoppoint21&rn=10000&date=2016-01-02 08:00': ("""<?xml version="1.0" encoding="UTF-8"?> <timeTable> <journey routeId="unknown_route" dateTime="2016-Jan-02 09:17:17" blink="0" realTime="yes" waiting_time="00:07:10"> <stop id="syn_stoppoint21"/> <line id="syn_lineC"> <network id="syn_network" name="nice_network" image=""/> </line> </journey> </timeTable> """, 200) }) with mock.patch('requests.get', mock_requests.get): query = self.query_template.format(sp='SP_21') response = self.query_region(query) scs = get_not_null(response, 'stop_schedules') assert len(scs) == 3 assert _get_schedule(response, 'SP_21', 'C1') == [{ 'rt': False, 'dt': '20160102T090000' }] assert _get_schedule(response, 'SP_21', 'C2') == [{ 'rt': False, 'dt': '20160102T100000' }]
def test_pois_places_nearby_depth_zero(self): """ with depth=0 we don't have to poi_type, so it's not possible to use bss availability we don't want jormungandr to crash in this case """ with mock_bss_providers(pois_supported=['station_1']): r = self.query_region( 'places/admin:74435/places_nearby?depth=0&count=20', display=False) places_nearby = get_not_null(r, 'places_nearby') assert {p[p['embedded_type']]['id'] for p in places_nearby} == { 'poi:parking_1', 'poi:station_1', 'stop_point:stopB', 'stopB', 'poi:station_2', 'poi:parking_2', 'stopC', 'stop_point:stopC', 'stopA', 'stop_point:stopA', 'stop_point:uselessA', }
def test_pois_with_stands_on_all_pois(self): with mock_bss_providers(pois_supported=[]): r = self.query_region('pois', display=False) pois = get_not_null(r, 'pois') assert {p['id'] for p in pois} == { 'poi:station_1', 'poi:station_2', 'poi:parking_1', 'poi:parking_2', } for p in pois: is_valid_poi(p) if p['id'] == 'poi:station_1' or p['id'] == 'poi:station_2': assert 'stands' in p stands = p['stands'] if p['id'] == 'poi:station_1': assert stands['available_places'] == 13 assert stands['available_bikes'] == 3 assert stands['total_stands'] == 16 assert stands['status'] == 'open' elif p['id'] == 'poi:station_2': assert stands['available_places'] == 99 assert stands['available_bikes'] == 98 assert stands['total_stands'] == 197 assert stands['status'] == 'open' else: assert not 'stands' in p
def test_pois_with_stands_on_second_places_nearby(self): with mock_bss_providers(pois_supported=['poi:station_1']): r = self.query_region('places/admin:74435/places_nearby?count=20', display=False) places_nearby = get_not_null(r, 'places_nearby') assert {p[p['embedded_type']]['id'] for p in places_nearby} == { 'poi:parking_1', 'poi:station_1', 'stop_point:stopB', 'stopB', 'poi:station_2', 'poi:parking_2', 'stopC', 'stop_point:stopC', 'stopA', 'stop_point:stopA', 'stop_point:uselessA', } for p in places_nearby: embedded_type = p['embedded_type'] if embedded_type == 'poi': is_valid_poi(p[embedded_type]) if p[embedded_type]['id'] == 'poi:station_1': assert 'stands' in p[embedded_type] stands = p[embedded_type]['stands'] assert stands['available_places'] == 13 assert stands['available_bikes'] == 3 assert stands['total_stands'] == 16 assert stands['status'] == 'open' else: assert not 'stands' in p[embedded_type] else: assert not 'stands' in p[embedded_type]
def send_mock(self, *args, **kwargs): status = self.query_region('status') last_loaded_data = get_not_null(status['status'], 'last_rt_data_loaded') item = self._make_mock_item(*args, **kwargs) self._publish(item) #we sleep a bit to let kraken reload the data self._poll_until_reload(last_loaded_data)
def pois_with_stands_on_all_places_nearby_test(self): with mock_bss_providers(pois_supported=[]): r = self.query_region('places/admin:74435/places_nearby', display=False) places_nearby = get_not_null(r, 'places_nearby') assert {p[p['embedded_type']]['id'] for p in places_nearby} == {'parking_1', 'station_1', 'stop_point:stopB', 'stopB', 'station_2', 'parking_2', 'stopC', 'stop_point:stopC', 'stopA', 'stop_point:stopA'} for p in places_nearby: embedded_type = p['embedded_type'] if embedded_type == 'poi': is_valid_poi(p[embedded_type]) if p[embedded_type]['id'] == 'station_1' or p[embedded_type]['id'] == 'station_2': assert 'stands' in p[embedded_type] stands = p[embedded_type]['stands'] if p[embedded_type]['id'] == 'station_1': assert stands['available_places'] == 13 assert stands['available_bikes'] == 3 assert stands['total_stands'] == 16 elif p[embedded_type]['id'] == 'station_2': assert stands['available_places'] == 99 assert stands['available_bikes'] == 98 assert stands['total_stands'] == 197 else: assert not 'stands' in p[embedded_type] else: assert not 'stands' in p[embedded_type]
def test_stop_schedule_bad_id_one_route_bad_line(self): """ test for a route point when the route code is not in synthese since there is only one route in navitia and 1 response in synthese but not on the same line we don't get some realtime """ mock_requests = MockRequests({ 'http://bob.com?SERVICE=tdg&roid=syn_stoppoint11&rn=10000&date=2016-01-02 08:00': ("""<?xml version="1.0" encoding="UTF-8"?> <timeTable> <journey routeId="unknown_route_code" dateTime="2016-Jan-02 09:17:17" realTime="yes" waiting_time="00:07:10"> <stop id="syn_stoppoint11"/> <line id="another_line_code_but_not_B"> <network id="syn_network" name="nice_network" image=""/> </line> </journey> </timeTable> """, 200), }) with mock.patch('requests.get', mock_requests.get): query = self.query_template.format(sp='SP_11') response = self.query_region(query) scs = get_not_null(response, 'stop_schedules') assert len(scs) == 1 assert _get_schedule(response, 'SP_11', 'B1') == [{ 'rt': False, 'dt': '20160102T090000' }]
def test_bss_stands_on_journeys_disabled_by_default(self): supported_pois = ['poi:station_1', 'poi:station_2'] with mock_bss_providers(pois_supported=supported_pois): query = journey_basic_query + "&first_section_mode=bss&last_section_mode=bss" response = self.query_region(query) self.is_valid_journey_response(response, query) journeys = get_not_null(response, 'journeys') for poi in get_from_to_pois_of_journeys(journeys): is_valid_poi(poi) assert 'stands' not in poi # since no stands have been added, we have not added the bss provider as a feed publisher # thus we only have the 'static' data feed publisher feeds = get_not_null(response, 'feed_publishers') assert len(feeds) == 1 assert next(f for f in feeds if f['name'] == 'routing api data')
def test_equipment_reports_with_filter(self): """ added an extra filter """ mock_equipment_providers( equipment_provider_manager=self.equipment_provider_manager( "main_routing_test"), data=standard_mock_elevator_data, code_types_list=["TCL_ASCENSEUR", "TCL_ESCALIER"], ) response = self.query_region('equipment_reports?' + default_date_filter + default_line_filter) warnings = get_not_null(response, 'warnings') assert len(warnings) == 1 assert warnings[0]['id'] == 'beta_endpoint' # Expected response stopA_equipment_details = [ ("5", "elevator", "unknown"), ("1", "escalator", "unknown"), ("2", "escalator", "unknown"), ("3", "escalator", "unknown"), ("4", "escalator", "unknown"), ] stopb_equipment_details = [ ("6", "elevator", "available"), ("7", "elevator", "unavailable"), ("8", "elevator", "unknown"), ("9", "elevator", "unknown"), ] # filtered with the A line expected_result = { "A": { "stopA": stopA_equipment_details, "stopB": stopb_equipment_details } } equipment_reports = get_not_null(response, 'equipment_reports') assert len(equipment_reports) == 1 for equipment_report in equipment_reports: is_valid_equipment_report(equipment_report) self._check_equipment_report(equipment_reports, expected_result)
def _wait_for_rabbitmq_cnx(self): """ poll until the kraken is connected to rabbitmq small timeout because it must not be long (otherwise it way be a server configuration problem) """ Retrying(stop_max_delay=1 * 1000, wait_fixed=50, retry_on_result=lambda status: get_not_null(status['status'], 'is_connected_to_rabbitmq') is False) \ .call(lambda: self.query_region('status'))
def test_pois_without_stands_on_pois(self): with mock_bss_providers(pois_supported=['station_unknown']): r = self.query_region('pois', display=False) pois = get_not_null(r, 'pois') assert {p['id'] for p in pois} == {'poi:station_1', 'poi:station_2', 'poi:parking_1', 'poi:parking_2'} for p in pois: is_valid_poi(p) assert not 'stands' in p
def test_stop_schedule_good_id(self): """ test for a route point with good codes (but with multiple codes on the route) we should be able to find all the synthese passages and aggregate them """ mock_requests = MockRequests( { 'http://bob.com?SERVICE=tdg&roid=syn_stoppoint1&rn=10000&date=2016-01-02 08:00': ( """<?xml version="1.0" encoding="UTF-8"?> <timeTable> <journey routeId="syn_cute_routeA1" dateTime="2016-Jan-02 09:17:17" blink="0" realTime="yes" waiting_time="00:07:10"> <stop id="syn_stoppoint1"/> <line id="syn_lineA"> <network id="syn_network" name="nice_network" image=""/> </line> </journey> <journey routeId="syn_cute_routeA1" dateTime="2016-Jan-02 10:17:17" blink="0" realTime="yes" waiting_time="00:07:10"> <stop id="syn_stoppoint1"/> <line id="syn_lineA"> <network id="syn_network" name="nice_network" image=""/> </line> </journey> <!-- another of the route's code--> <journey routeId="syn_routeA1" dateTime="2016-Jan-02 11:17:17" blink="0" realTime="yes" waiting_time="00:07:10"> <stop id="syn_stoppoint1"/> <line id="syn_lineA"> <network id="syn_network" name="nice_network" image=""/> </line> </journey> <!-- an unkown route's code, should not be considered--> <journey routeId="unknown_route" dateTime="2016-Jan-02 12:17:17" blink="0" realTime="yes" waiting_time="00:07:10"> <stop id="syn_stoppoint1"/> <line id="syn_lineA"> <network id="syn_network" name="nice_network" image=""/> </line> </journey> </timeTable> """, 200, ) } ) with mock.patch('requests.get', mock_requests.get): query = self.query_template.format(sp='SP_1') response = self.query_region(query) scs = get_not_null(response, 'stop_schedules') assert len(scs) == 1 print(_get_schedule(response, 'SP_1', 'A1')) assert _get_schedule(response, 'SP_1', 'A1') == [ {'rt': True, 'dt': '20160102T091717'}, {'rt': True, 'dt': '20160102T101717'}, {'rt': True, 'dt': '20160102T111717'}, ]
def _poll_until_reload(self, previous_val): """ poll until the kraken have reloaded its data check that the last_rt_data_loaded field is different from the first call """ Retrying(stop_max_delay=10 * 1000, wait_fixed=100, retry_on_result=lambda status: get_not_null(status['status'], 'last_rt_data_loaded') == previous_val) \ .call(lambda: self.query_region('status'))
def test_pois_without_stands_on_places_autocompletion(self): with mock_bss_providers(pois_supported=[]): r = self.query_region("places/?q=first station&count=1", display=False) places = get_not_null(r, 'places') assert {p[p['embedded_type']]['id'] for p in places} == {'poi:station_1'} poi = places[0]['poi'] is_valid_poi(poi) assert not 'stands' in poi
def test_pois_with_stands_on_first_parking_place(self): with mock_bss_providers(pois_supported=[]): r = self.query_region("places/poi:parking_1", display=False) places = get_not_null(r, 'places') assert {p[p['embedded_type']]['id'] for p in places} == {'poi:parking_1'} poi = places[0]['poi'] is_valid_poi(poi) assert not 'stands' in poi
def test_pois_with_stands_on_first_parking_poi(self): with mock_bss_providers(pois_supported=[]): r = self.query_region("pois/poi:parking_1", display=False) pois = get_not_null(r, 'pois') assert {p['id'] for p in pois} == {'poi:parking_1'} poi = pois[0] is_valid_poi(poi) assert not 'stands' in poi
def test_pois_without_stands_on_poi(self): with mock_bss_providers(pois_supported=['station_unknown']): r = self.query_region("pois/station_1", display=False) pois = get_not_null(r, 'pois') assert {p['id'] for p in pois} == {'station_1'} poi = pois[0] is_valid_poi(poi) assert not 'stands' in poi
def test_bss_stands_on_journeys_disabled_by_default(self): supported_pois = ['station_1', 'station_2'] with mock_bss_providers(pois_supported=supported_pois): query = journey_basic_query + "&first_section_mode=bss&last_section_mode=bss" response = self.query_region(query) self.is_valid_journey_response(response, query) journeys = get_not_null(response, 'journeys') for poi in get_from_to_pois_of_journeys(journeys): is_valid_poi(poi) assert 'stands' not in poi
def pois_without_stands_on_place_test(self): with mock_bss_providers(pois_supported=['station_unknown']): r = self.query_region("places/station_1", display=False) places = get_not_null(r, 'places') assert {p[p['embedded_type']]['id'] for p in places} == {'station_1'} poi = places[0]['poi'] is_valid_poi(poi) assert not 'stands' in poi
def test_freefloatings_nearby(self): """ simple freefloatings_nearby call """ response, status = self.query_no_assert( 'v1/coverage/main_routing_test/coord/2.37715%3B48.846781/freefloatings_nearby?count=5&start_page=1' ) warnings = get_not_null(response, 'warnings') assert len(warnings) == 1 assert warnings[0]['id'] == 'beta_endpoint' free_floatings = get_not_null(response, 'free_floatings') assert len(free_floatings) == 3 # First free_floating doesn't contain all attributes assert free_floatings[0]['public_id'] == '12009' assert free_floatings[0]['provider_name'] == 'Velib' assert free_floatings[0]['type'] == 'STATION' assert free_floatings[0]['id'] == 'dmVsaWI6U1RBVElPTjoxMjAwOQ==' assert free_floatings[0]['coord']['lat'] == '48.84617146118711' assert free_floatings[0]['coord']['lon'] == '2.379306815564632' # Second free_floating contains more attributes assert free_floatings[1]['public_id'] == 'FB-435-HD' assert free_floatings[1]['distance'] == 100.55 assert free_floatings[1]['provider_name'] == 'Cityscoot' assert free_floatings[1]['type'] == 'MOTORSCOOTER' assert free_floatings[1][ 'id'] == 'Y2l0eXNjb290Ok1PVE9SU0NPT1RFUjpGQi00MzUtSEQ=' assert free_floatings[1]['coord']['lat'] == '48.848715' assert free_floatings[1]['coord']['lon'] == '2.37618' assert ( free_floatings[1]['deeplink'] == 'https://cityscoot.onelink.me/8GT9?pid=FLUCTUO&c=CS-API-FLUCTUO&af_dp=cityscoot%3A%2F%2Fcities%2F4%2Fscooters%2F18055&af_web_dp=https%3A%2F%2Fwww.cityscoot.eu%2F&af_force_deeplink=true' ) assert free_floatings[1]['battery'] == 91 assert free_floatings[1]['propulsion'] == 'ELECTRIC' assert free_floatings[1]['attributes'] == ['ELECTRIC'] assert 'pagination' in response assert response['pagination']['start_page'] == 1 assert response['pagination']['items_on_page'] == 3 assert response['pagination']['items_per_page'] == 5 assert response['pagination']['total_result'] == 8
def test_journey_sections_from_to_poi_with_stands(self): supported_pois = ['poi:station_1'] with mock_bss_providers(pois_supported=supported_pois): query = ( journey_basic_query + "&first_section_mode=bss&last_section_mode=bss&add_poi_infos[]=bss_stands" ) response = self.query_region(query) self.is_valid_journey_response(response, query) journeys = get_not_null(response, 'journeys') for poi in get_from_to_pois_of_journeys(journeys): is_valid_poi(poi) if poi['id'] in supported_pois: assert 'stands' in poi assert poi['stands']['available_places'] == 13 assert poi['stands']['available_bikes'] == 3 assert poi['stands']['total_stands'] == 16 assert poi['stands']['status'] == 'open' else: assert 'stands' not in poi # check the feed publishers # we have the feed publisher of the 'static' data feeds = get_not_null(response, 'feed_publishers') tc_data = next(f for f in feeds if f['name'] == 'routing api data') assert tc_data == { 'id': 'builder', 'name': 'routing api data', 'license': 'ODBL', 'url': 'www.canaltp.fr', } # we check that the feedpublisher of the bss provider has been added bss_provider = next(f for f in feeds if f['name'] == 'mock bss provider') assert bss_provider == { 'id': 'mock_bss', 'name': 'mock bss provider', 'license': 'the death license', 'url': 'bob.com', }
def test_stop_schedule_bad_id_multiple_response(self): """ test for a route point when the route code is not in synthese since there is only one route in navitia but multiple routes in synthese, we get all the synthese passage on this route """ mock_requests = MockRequests({ 'http://bob.com?SERVICE=tdg&roid=syn_stoppoint11&rn=10000&date=2016-01-02 08:00': ("""<?xml version="1.0" encoding="UTF-8"?> <timeTable> <journey routeId="unknown_route_code1" dateTime="2016-Jan-02 09:17:17" realTime="yes" waiting_time="00:07:10"> <stop id="syn_stoppoint11"/> <line id="syn_lineB"> <network id="syn_network" name="nice_network" image=""/> </line> </journey> <journey routeId="unknown_route_code2" dateTime="2016-Jan-02 10:17:17" realTime="yes" waiting_time="00:07:10"> <stop id="syn_stoppoint11"/> <line id="syn_lineB"> <network id="syn_network" name="nice_network" image=""/> </line> </journey> <journey routeId="unknown_route_code3" dateTime="2016-Jan-02 11:17:17" realTime="yes" waiting_time="00:07:10"> <stop id="syn_stoppoint11"/> <line id="another_line_this_will_not_be_taken"> <network id="syn_network" name="nice_network" image=""/> </line> </journey> </timeTable> """, 200), }) with mock.patch('requests.get', mock_requests.get): query = self.query_template.format(sp='SP_11') response = self.query_region(query) scs = get_not_null(response, 'stop_schedules') assert len(scs) == 1 sched = _get_schedule(response, 'SP_11', 'B1') assert sched == [ { 'rt': True, 'dt': '20160102T091717' }, { 'rt': True, 'dt': '20160102T101717' }, ]
def test_pois_with_stands_on_second_poi(self): with mock_bss_providers(pois_supported=[]): r = self.query_region("pois/station_2", display=False) pois = get_not_null(r, 'pois') assert {p['id'] for p in pois} == {'station_2'} poi = pois[0] is_valid_poi(poi) assert 'stands' in poi stands = poi['stands'] assert stands['available_places'] == 99 assert stands['available_bikes'] == 98 assert stands['total_stands'] == 197