Exemplo n.º 1
0
    def test_get_last_events(self):
        asset = assets_service.create_asset(self.project.id,
                                            self.asset_type.id, "test 1", "",
                                            {})
        after = asset["created_at"]
        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", "",
                                            {})
        before = asset["created_at"]
        time.sleep(1)
        asset = assets_service.create_asset(self.project.id,
                                            self.asset_type.id, "test 4", "",
                                            {})

        events = self.get("/data/events/last")
        self.assertEqual(len(events), 4)
        events = self.get("/data/events/last?page_size=2")
        self.assertEqual(len(events), 2)
        events = self.get("/data/events/last?before=%s" % before)
        self.assertEqual(len(events), 2)
        events = self.get("/data/events/last?before=%s&after=%s" %
                          (before, after))
        self.assertEqual(len(events), 2)

        ApiEvent.create(name="preview-file:add-file")
        ApiEvent.create(name="person:set-thumbnail")
        events = self.get("/data/events/last")
        self.assertEqual(len(events), 6)
        events = self.get("/data/events/last?only_files=true")
        self.assertEqual(len(events), 2)
Exemplo n.º 2
0
def save_event(event, data):
    """
    Store event information in the database.
    """
    try:
        from zou.app.services.persons_service import get_current_user_raw

        person = get_current_user_raw()
        person_id = person.id
    except:
        person_id = None

    return ApiEvent.create(name=event, data=data, user_id=person_id)