Exemple #1
0
    def test_register(self):
        events.register("task:start", "inc_counter", self)
        events.emit("task:start")
        self.assertEqual(self.counter, 2)
        events.emit("task:stop")
        self.assertEqual(self.counter, 2)
        events.emit("task:start")
        self.assertEqual(self.counter, 3)

        event_models = events_service.get_last_events()
        self.assertEquals(len(event_models), 3)
        events.emit("task:start", persist=False)
        event_models = events_service.get_last_events()
        self.assertEquals(len(event_models), 3)
Exemple #2
0
 def get(self):
     args = self.get_args([
         ("after", None, False),
         ("before", None, False),
         ("only_files", False, False),
         ("page_size", 100, False),
         ("project_id", None, False),
     ])
     permissions.check_manager_permissions()
     before = self.parse_date_parameter(args["before"])
     after = self.parse_date_parameter(args["after"])
     page_size = args["page_size"]
     only_files = args["only_files"] == "true"
     project_id = args.get("project_id", None)
     if project_id is not None and not fields.is_valid_id(project_id):
         raise WrongParameterException(
             "The project_id parameter is not a valid id")
     else:
         return events_service.get_last_events(
             after=after,
             before=before,
             page_size=page_size,
             only_files=only_files,
             project_id=project_id,
         )
Exemple #3
0
    def get(self):
        args = self.get_args([("after", None, None), ("before", None, None),
                              ("only_files", False, False),
                              ("page_size", 100, False)])
        permissions.check_manager_permissions()
        before = None
        after = None

        try:
            if args["before"] is not None:
                before = fields.get_date_object(args["before"],
                                                "%Y-%m-%dT%H:%M:%S")
            if args["after"] is not None:
                after = fields.get_date_object(args["after"],
                                               "%Y-%m-%dT%H:%M:%S")
        except Exception:
            return {
                "error":
                True,
                "message":
                "Wrong date format for before or after argument."
                "Expected format: 2020-01-05T13:23:10"
            }, 400
        page_size = args["page_size"]
        only_files = args["only_files"] == "true"
        return events_service.get_last_events(after=after,
                                              before=before,
                                              page_size=page_size,
                                              only_files=only_files)
Exemple #4
0
 def get(self):
     args = self.get_args([("before", None, None),
                           ("page_size", 100, False)])
     permissions.check_manager_permissions()
     before = None
     if args["before"] is not None:
         before = fields.get_date_object(args["before"],
                                         "%Y-%m-%dT%H:%M:%S")
     page_size = args["page_size"]
     return events_service.get_last_events(before, page_size)
Exemple #5
0
    def get(self):
        args = self.get_args([
            ("after", None, False),
            ("before", None, False),
            ("only_files", False, False),
            ("page_size", 100, False),
            ("project_id", None, False),
        ])
        permissions.check_manager_permissions()
        before = None
        after = None

        if args["before"] is not None:
            try:
                before = fields.get_date_object(
                    args["before"], "%Y-%m-%dT%H:%M:%S"
                )
            except Exception:
                try:
                    before = fields.get_date_object(args["before"], "%Y-%m-%d")
                except Exception:
                    raise WrongParameterException(
                        "Wrong date format for before argument."
                        "Expected format: 2020-01-05T13:23:10 or 2020-01-05"
                    )

        if args["after"] is not None:
            try:
                after = fields.get_date_object(
                    args["after"], "%Y-%m-%dT%H:%M:%S"
                )
            except Exception:
                try:
                    after = fields.get_date_object(args["after"], "%Y-%m-%d")
                except Exception:
                    raise WrongParameterException(
                        "Wrong date format for after argument."
                        "Expected format: 2020-01-05T13:23:10 or 2020-01-05"
                    )

        page_size = args["page_size"]
        only_files = args["only_files"] == "true"
        project_id = args.get("project_id", None)
        if project_id is not None and not fields.is_valid_id(project_id):
            raise WrongParameterException(
                "The project_id parameter is not a valid id"
            )
        else:
            return events_service.get_last_events(
                after=after,
                before=before,
                page_size=page_size,
                only_files=only_files,
                project_id=project_id
            )
Exemple #6
0
 def test_get_last_events(self):
     asset = assets_service.create_asset(self.project.id,
                                         self.asset_type.id, "test 1", "",
                                         {})
     date = fields.get_date_object(asset["created_at"], "%Y-%m-%dT%H:%M:%S")
     time.sleep(1)
     asset = assets_service.create_asset(self.project.id,
                                         self.asset_type.id, "test 2", "",
                                         {})
     time.sleep(1)
     asset = assets_service.create_asset(self.project.id,
                                         self.asset_type.id, "test 3", "",
                                         {})
     events = events_service.get_last_events()
     self.assertEqual(len(events), 3)
     events = events_service.get_last_events(page_size=2)
     self.assertEqual(len(events), 2)
     date = fields.get_date_object(asset["created_at"], "%Y-%m-%dT%H:%M:%S")
     events = events_service.get_last_events(before=date)
     self.assertEqual(len(events), 2)
Exemple #7
0
    def test_register_all(self):
        event_map = {"task:start": self, "task:new": self}
        events.register_all(event_map)
        events.emit("task:start")
        self.assertEqual(self.counter, 2)
        events.emit("task:stop")
        self.assertEqual(self.counter, 2)
        events.emit("task:start")
        self.assertEqual(self.counter, 3)
        events.emit("task:new")
        self.assertEqual(self.counter, 4)

        event_models = events_service.get_last_events()
        self.assertEqual(len(event_models), 4)
        self.assertEqual(event_models[0]["name"], "task:new")