def drop_audit(init_date=None, end_date=None): """Delete all Documents in Audit database. """ if not init_date and not end_date: ModelAction.drop_collection() Access.drop_collection() Process.drop_collection() else: ModelAction.objects.filter(timestamp__gte=init_date, timestamp__lte=end_date).delete() Access.objects.filter(time__request__gte=init_date, time__request__lte=end_date).delete() Process.objects.filter(creation_time__gte=init_date, creation_time__lte=end_date).delete()
def test_verbose_str(self): process = Process( interlink_id=None, name=self.name, args=None, machine=self.machine, user=self.user, pid=self.pid, creation_time=self.creation_time, ) expected = 'Process {} with pid {:d} run by {} on {} ({})'.format( self.name, self.pid, self.user, self.machine, self.creation_time) self.assertEqual(expected, process.verbose_str())
def test_verbose_str(self): process = Process( interlink_id=None, name=self.name, args=None, machine=self.machine, user=self.user, pid=self.pid, creation_time=self.creation_time, ) expected = "Process {} with pid {:d} run by {} on {} ({})".format( self.name, self.pid, self.user, self.machine, self.creation_time ) self.assertEqual(expected, process.verbose_str())
def test_items(self): items = [('name', self.name), ('machine', self.machine), ('user', self.user), ('pid', self.pid), ('creation_time', self.creation_time)] process = Process( interlink_id=None, name=self.name, args=None, machine=self.machine, user=self.user, pid=self.pid, creation_time=self.creation_time, ) result = process.items() self.assertEqual(items, result)
def test_items(self): items = [ ("name", self.name), ("machine", self.machine), ("user", self.user), ("pid", self.pid), ("creation_time", self.creation_time), ] process = Process( interlink_id=None, name=self.name, args=None, machine=self.machine, user=self.user, pid=self.pid, creation_time=self.creation_time, ) result = process.items() self.assertEqual(items, result)
def get_process(self, process): """ Get current process. If not exists, create it. :param process: Process data. :type process: dict. :return: Process :rtype: :class:`audit_tools.audit.Process` """ from audit_tools.audit.models import Process p = getattr(self.namespace, "audit_current_process", None) if p is None: try: p = Process.objects.get(pid=process['pid'], machine=process['machine'], creation_time=process['creation_time']) except DoesNotExist: p = Process(**process) p.save() self.set_process(p) return p
def test_str(self): process = Process( interlink_id=None, name=self.name, args=None, machine=self.machine, user=self.user, pid=self.pid, creation_time=self.creation_time, ) expected = 'Process{{{}, pid:{:d}, user:{}, machine:{}, creation_time:{}}}'.format( self.name, self.pid, self.user, self.machine, self.creation_time) self.assertEqual(expected, str(process))
def setUpClass(cls): cls.cache = cache cls.process = Process() cls.access = Access()