def on_delete(self): ServiceRemoveEvent.emit(self)
def test_events(self): store_list = [] p_data = _ServiceEventData() ServiceCreateEvent.connect(p_data.on_create) ServiceEditEvent.connect(p_data.on_edit) ServiceRemoveEvent.connect(p_data.on_delete) try: # Test service being created store = new_store() store_list.append(store) sellable = Sellable( store=store, description=u'Test 1234', price=decimal.Decimal(2), ) service = Service( store=store, sellable=sellable, ) store.commit() self.assertTrue(p_data.was_created) self.assertFalse(p_data.was_edited) self.assertFalse(p_data.was_deleted) self.assertEqual(p_data.service, service) p_data.reset() # Test service being edited and emmiting the event just once store = new_store() store_list.append(store) sellable = store.fetch(sellable) service = store.fetch(service) sellable.notes = u'Notes' sellable.description = u'Test 666' service.weight = decimal.Decimal(10) store.commit() self.assertTrue(p_data.was_edited) self.assertFalse(p_data.was_created) self.assertFalse(p_data.was_deleted) self.assertEqual(p_data.service, service) self.assertEqual(p_data.emit_count, 1) p_data.reset() # Test service being edited, editing Sellable store = new_store() store_list.append(store) sellable = store.fetch(sellable) service = store.fetch(service) sellable.notes = u'Notes for test' store.commit() self.assertTrue(p_data.was_edited) self.assertFalse(p_data.was_created) self.assertFalse(p_data.was_deleted) self.assertEqual(p_data.service, service) self.assertEqual(p_data.emit_count, 1) p_data.reset() finally: # Test service being removed store = new_store() store_list.append(store) sellable = store.fetch(sellable) service = store.fetch(service) sellable.remove() store.commit() self.assertTrue(p_data.was_deleted) self.assertFalse(p_data.was_created) self.assertFalse(p_data.was_edited) self.assertEqual(p_data.service, service) self.assertEqual(p_data.emit_count, 1) p_data.reset() for store in store_list: store.close()