Exemplo n.º 1
0
    def post(self, request, *args, **kwargs):

        serializer = CourseOfActionGeneration(data=request.data)
        serializer.is_valid(raise_exception=True)

        data = request.data
        print data["type"]
        if not data["type"]=="depth" and not data["type"]=="breadth":
            context = {
                "message": '"type" field must be "depth" or "breadth"'
            }
            return Response(status=400, data=context)

        tasks = None
        if "tasks" in data:
            tasks = data["tasks"]

        if tasks is None:
            tasks = list(self.tasks_collection.find({}, {"_id":False}))


        dep_fun = getattr(COAG, "generate_course_action_" + data["type"])

        result = dep_fun(data["target_task"], tasks)

        task_list = COAG.extract_tasks(result, tasks)

        return Response(status=201, data=task_list)
Exemplo n.º 2
0
    def test_extract_tasks_1(self):

        task_list = ["D1", "D2"]
        tasks = json.load(
            open("tests/data/course_of_action_generation_data_2.json"))

        expected_result = [{
            "taskId": "D1",
            "effect": "DISRUPT",
            "objective": "POWER-STATION-PROCESSING-NODE-C2",
            "actor": "JV3",
            "timeFrame": 2,
            "dependencies": ["S1", "A1"]
        }, {
            "taskId": "D2",
            "effect": "DISRUPT",
            "objective": "POWER-STATION-FIREWALL-C1",
            "actor": "JV3",
            "timeFrame": 2,
            "dependencies": ["A2"]
        }]

        result = COAG.extract_tasks(task_list, tasks)

        self.assertEqual(result, expected_result)