def test_update_scenario_name_resolver(self):
     scenario = self.scenarios[0]
     name = self.scenarios[1].name
     update_scenario_name(scenario, name, True)
     scenario.save()
     updated_scenario = get_scenario_with_id(scenario.id)
     self.assertTrue(updated_scenario.name.startswith(name))
示例#2
0
def delete_scenario(scenario_id: int):
    """
    Deletes the scenario, and the connected road_segments
    :param scenario: The scenario to be deleted
    :return:
    """
    scenario = get_scenario_with_id(scenario_id)

    ScenarioToLabel.objects.filter(scenario_id=scenario.id).delete()
    road_segments = RoadSegment.objects.filter(scenario=scenario).all()
    for rs in road_segments:
        delete_road_segment(rs.id)
    scenario.delete()
def create_road_segment_with_route_id(name: str, scenario_id: int,
                                      road_segment_type_id: int,
                                      route_id: int,
                                      alternative_route_id: int) -> RoadSegment:
    scenario = get_scenario_with_id(scenario_id)
    road_segment_type = get_road_segment_type_with_id(road_segment_type_id)
    road_segment = RoadSegment(name=name, scenario=scenario,
                               road_segment_type=road_segment_type,
                               route_id=route_id,
                               alternative_route_id=alternative_route_id)
    road_segment.save()
    update_location(scenario)
    return road_segment
 def test_delete(self):
     self.assertEqual(len(get_all_folders()), 6)
     folder = self.folders[0]
     scenario = Scenario(name="boomerang",
                         description="tori",
                         start_lat=0,
                         start_lng=0,
                         end_lat=0,
                         end_lng=0,
                         folder=folder)
     scenario.save()
     delete_folder(folder.id)
     updated_scenario = get_scenario_with_id(scenario.id)
     self.assertEqual(len(get_all_folders()), 5)
     self.assertEqual(updated_scenario.folder, None)
示例#5
0
def update_scenario(scenario_id: int, name: str, folder_id: int,
                    description: str,
                    labels: graphene.List(LabelInputObject)) -> Scenario:
    scenario = get_scenario_with_id(scenario_id)
    if name:
        update_scenario_name(scenario, name)
    scenario.description = description if description else scenario.description
    if has_folder_with_id(folder_id):
        update_scenario_folder(scenario, folder_id)
    update_location(scenario)

    if labels:
        ScenarioToLabel.objects.filter(scenario_id=scenario.id).delete()
        for l in labels:
            label = create_label(l)
            ScenarioToLabel(scenario=scenario, label=label).save()
    return scenario
def create_response_plan(road_segment_id: int, operator: str,
                         road_condition_id: int, scenario_id: int,
                         parent_id: int) -> ResponsePlan:
    if operator:
        response_plan = ResponsePlan(operator=operator)

        if road_segment_id:
            response_plan.road_segment = get_road_segment_with_id(
                road_segment_id)
        if road_condition_id:
            response_plan.road_condition = get_road_condition_with_id(
                road_condition_id)
        if scenario_id:
            response_plan.scenario = get_scenario_with_id(scenario_id)
        if parent_id:
            response_plan.parent = get_response_plan_with_id(parent_id)

        response_plan.save()
        return response_plan
    else:
        raise InvalidInputException()
示例#7
0
def update_road_segment(road_segment_id: int, name: str, scenario_id: int,
                        road_segment_type_id: int, route: RouteInputObject,
                        alternative_route: RouteInputObject) -> RoadSegment:
    road_segment = get_road_segment_with_id(road_segment_id)
    road_segment.name = name if name else road_segment.name
    if scenario_id:
        road_segment.scenario = get_scenario_with_id(scenario_id)

    if road_segment_type_id:
        road_segment.road_segment_type = get_road_segment_type_with_id(
            road_segment_type_id)

    if route:
        r = create_route(route)
        road_segment.route = r

    if alternative_route:
        r = create_route(alternative_route)
        road_segment.alternative_route = r

    road_segment.save()
    update_location(road_segment.scenario)

    return road_segment
示例#8
0
def to_json_scenario_by_id(scenario_id: int):
    try:
        scenario = get_scenario_with_id(scenario_id)
        return to_json_scenario(scenario)
    except ApiException as exc:
        return {"msg": str(exc)}
def update_response_plan_scenario(response_plan: ResponsePlan,
                                  scenario_id: int):
    scenario = get_scenario_with_id(scenario_id)
    response_plan.scenario = scenario
 def test_get_scenario_exception(self):
     with self.assertRaises(ObjectNotFoundException):
         get_scenario_with_id(-1)
 def test_has_and_get_scenario(self):
     scenario = self.scenarios[0]
     getter_scenario = get_scenario_with_id(scenario.id)
     self.assertEqual(scenario, getter_scenario)
     self.assertTrue(has_scenario_with_id(scenario.id))