def send(self, obj, operation, actorobj, comment=None, details=None): obj = object_to_enterpriseid(obj) actorobj = object_to_enterpriseid(actorobj) action = self.__get_timeline_action("send", obj, operation, actorobj) try: return super(AuditorClient, self).send( obj, operation, actorobj, comment, details) finally: action.finish()
def send(self, obj, operation, actorobj, comment=None, details=None): obj = object_to_enterpriseid(obj) actorobj = object_to_enterpriseid(actorobj) action = self.__get_timeline_action("send", obj, operation, actorobj) try: return super(AuditorClient, self).send(obj, operation, actorobj, comment, details) finally: action.finish()
def test_send_and_receive(self): # We can use .send() and .receive() on AuditorClient to log. actor = self.factory.makePerson() pu = self.factory.makePackageUpload() client = AuditorClient() result = client.send(pu, 'packageupload-accepted', actor) self.assertEqual('Operation recorded.', result) data = "Object: %s; Operation: packageupload-accepted, Actor: %s" % ( object_to_enterpriseid(pu), object_to_enterpriseid(actor)) self.assertAction('auditor-send', data) result = client.receive(obj=pu) del result[0]['date'] # Ignore the date. expected = [{ u'comment': u'', u'details': u'', u'actor': actor, u'operation': u'packageupload-accepted', u'object': pu}] self.assertContentEqual(expected, result) self.assertAction( 'auditor-receive', "Object: %s; Operation: None, Actor: None" % ( object_to_enterpriseid(pu)))
def test_send_and_receive(self): # We can use .send() and .receive() on AuditorClient to log. actor = self.factory.makePerson() pu = self.factory.makePackageUpload() client = AuditorClient() result = client.send(pu, 'packageupload-accepted', actor) self.assertEqual('Operation recorded.', result) data = "Object: %s; Operation: packageupload-accepted, Actor: %s" % ( object_to_enterpriseid(pu), object_to_enterpriseid(actor)) self.assertAction('auditor-send', data) result = client.receive(obj=pu) del result[0]['date'] # Ignore the date. expected = [{ u'comment': u'', u'details': u'', u'actor': actor, u'operation': u'packageupload-accepted', u'object': pu }] self.assertContentEqual(expected, result) self.assertAction( 'auditor-receive', "Object: %s; Operation: None, Actor: None" % (object_to_enterpriseid(pu)))
def test_object_to_enterpriseid(self): person = self.factory.makePerson() eid = object_to_enterpriseid(person) expected = 'lp-development:Person:%d' % person.id self.assertEqual(expected, eid)
def _convert_to_enterpriseid(self, obj): if isinstance(obj, (list, tuple)): return [object_to_enterpriseid(o) for o in obj] else: return object_to_enterpriseid(obj)
def test_object_to_enterpriseid(self): person = self.factory.makePerson() eid = object_to_enterpriseid(person) expected = "lp-development:Person:%d" % person.id self.assertEqual(expected, eid)