def equipments_get_informations_for_reports_not_duplicated(): """ When 2 stop points (from the same stop areas) refer to the same equipment (type and value), we only want 1 equipment_details object that refers to it as we report information per stop area. """ CODE_TYPE = "TCL_ESCALIER" provider = SytralProvider(url="sytral.url", timeout=3, code_types=[CODE_TYPE]) provider._call_webservice = MagicMock(return_value=mock_data) sae = StopAreaEquipment() sae.stop_area.name = "StopArea1_name" sae.stop_area.uri = "StopArea1_uri" sp1 = sae.stop_area.stop_points.add() codes1 = sp1.codes.add() codes1.type = CODE_TYPE codes1.value = "val" sp2 = sae.stop_area.stop_points.add() codes2 = sp2.codes.add() codes2.type = CODE_TYPE codes2.value = "val" provider.get_informations_for_equipment_reports([sae]) assert len(sae.equipment_details) == 1
def equipments_get_information_test(): """ Test that 'equipment_details' structure is added to StopPoint proto when conditions are met """ provider = SytralProvider(url="sytral.url", timeout=3, code_types=["TCL_ASCENSEUR", "TCL_ESCALIER"]) provider._call_webservice = MagicMock(return_value=mock_data) # stop point has code with correct type and value present in webservice response # equipment_details is added st = create_stop_point("TCL_ASCENSEUR", "261") provider.get_informations_for_journeys([st]) assert st.equipment_details # stop point has code with correct type but value not present in webservice response # equipment_details is not added st = create_stop_point("TCL_ASCENSEUR", "262") provider.get_informations_for_journeys([st]) assert not st.equipment_details # stop point has code with incorrect type but value present in webservice response # equipment_details is not added st = create_stop_point("TCL_ASCENCEUR", "261") provider.get_informations_for_journeys([st]) assert not st.equipment_details
def mock_equipment_providers(equipment_provider_manager, data, code_types_list): equipment_provider_manager._equipment_providers = { "sytral": SytralProvider(url="fake.url", timeout=3, code_types=code_types_list) } equipment_provider_manager._equipment_providers["sytral"]._call_webservice = mock.MagicMock( return_value=data )