def test_field_event(self): # fieldproperties are everywhere including in field themselfs # so event are triggered from guillotina.schema import Text from guillotina.component.event import sync_subscribers from guillotina.schema.fieldproperty import FieldUpdatedEvent log = [] sync_subscribers.append(log.append) self.assertEqual(log, []) field = Text( __name__='testing', description='DESCRIPTION', default='DEFAULT', readonly=True, required=True, ) self.assertEqual(len(log), 6) # these are fieldproperties in the field self.assertEqual( [ev.field.__name__ for ev in log], ['min_length', 'max_length', 'title', 'description', 'required', 'readonly']) event = log[0] self.assertTrue(isinstance(event, FieldUpdatedEvent)) self.assertEqual(event.inst, field) self.assertEqual(event.old_value, 0) self.assertEqual(event.new_value, 0)
def test_field_event_update(self): from guillotina.schema import Text from guillotina.component.event import sync_subscribers from guillotina.schema.fieldproperty import FieldUpdatedEvent field = Text( __name__='testing', description='DESCRIPTION', default='DEFAULT', required=True, ) prop = self._makeOne(field=field) class Foo(object): testing = prop foo = Foo() log = [] sync_subscribers.append(log.append) foo.testing = 'Bar' foo.testing = 'Foo' self.assertEqual(len(log), 2) event = log[1] self.assertTrue(isinstance(event, FieldUpdatedEvent)) self.assertEqual(event.inst, foo) self.assertEqual(event.field, field) self.assertEqual(event.old_value, 'Bar') self.assertEqual(event.new_value, 'Foo')
def test_field_event(self): from guillotina.schema import Text from guillotina.component.event import sync_subscribers from guillotina.schema.fieldproperty import FieldUpdatedEvent log = [] sync_subscribers.append(log.append) self.assertEqual(log, []) field = Text( __name__="testing", description="DESCRIPTION", default="DEFAULT", readonly=True, required=True ) self.assertEqual(len(log), 6) event = log[0] self.assertTrue(isinstance(event, FieldUpdatedEvent)) self.assertEqual(event.inst, field) self.assertEqual(event.old_value, 0) self.assertEqual(event.new_value, 0) self.assertEqual( [ev.field.__name__ for ev in log], ["min_length", "max_length", "title", "description", "required", "readonly"], )