def test0020on_create(self): 'Test on_create' with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction: model, = self.model.search([ ('model', '=', 'test.triggered'), ]) action_model, = self.model.search([ ('model', '=', 'test.trigger_action'), ]) trigger, = self.trigger.create([{ 'name': 'Test', 'model': model.id, 'on_create': True, 'condition': 'true', 'action_model': action_model.id, 'action_function': 'trigger', }]) triggered, = self.triggered.create([{ 'name': 'Test', }]) self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # Trigger with condition condition = PYSONEncoder().encode( Eval('self', {}).get('name') == 'Bar') self.trigger.write([trigger], { 'condition': condition, }) # Matching condition triggered, = self.triggered.create([{ 'name': 'Bar', }]) self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # Non matching condition triggered, = self.triggered.create([{ 'name': 'Foo', }]) self.assertEqual(TRIGGER_LOGS, []) # With limit number self.trigger.write([trigger], { 'condition': 'true', 'limit_number': 1, }) triggered, = self.triggered.create([{ 'name': 'Test', }]) self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # With minimum delay self.trigger.write( [trigger], { 'limit_number': 0, 'minimum_time_delay': datetime.timedelta(hours=1), }) triggered, = self.triggered.create([{ 'name': 'Test', }]) self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # Restart the cache on the get_triggers method of ir.trigger self.trigger._get_triggers_cache.clear() transaction.cursor.rollback()
def test_on_create(self): 'Test on_create' pool = Pool() Model = pool.get('ir.model') Trigger = pool.get('ir.trigger') Triggered = pool.get('test.triggered') model, = Model.search([ ('model', '=', 'test.triggered'), ]) action_model, = Model.search([ ('model', '=', 'test.trigger_action'), ]) trigger, = Trigger.create([{ 'name': 'Test', 'model': model.id, 'on_create': True, 'condition': 'true', 'action_model': action_model.id, 'action_function': 'trigger', }]) triggered, = Triggered.create([{ 'name': 'Test', }]) self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # Trigger with condition condition = PYSONEncoder().encode( Eval('self', {}).get('name') == 'Bar') Trigger.write([trigger], { 'condition': condition, }) # Matching condition triggered, = Triggered.create([{ 'name': 'Bar', }]) self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # Non matching condition triggered, = Triggered.create([{ 'name': 'Foo', }]) self.assertEqual(TRIGGER_LOGS, []) # With limit number Trigger.write([trigger], { 'condition': 'true', 'limit_number': 1, }) triggered, = Triggered.create([{ 'name': 'Test', }]) self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # With minimum delay Trigger.write([trigger], { 'limit_number': 0, 'minimum_time_delay': datetime.timedelta(hours=1), }) triggered, = Triggered.create([{ 'name': 'Test', }]) self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # Restart the cache on the get_triggers method of ir.trigger Trigger._get_triggers_cache.clear()
def test0050on_time(self): 'Test on_time' with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction: model, = self.model.search([ ('model', '=', 'test.triggered'), ]) action_model, = self.model.search([ ('model', '=', 'test.trigger_action'), ]) trigger, = self.trigger.create([{ 'name': 'Test', 'model': model.id, 'on_time': True, 'condition': 'true', 'action_model': action_model.id, 'action_function': 'trigger', }]) triggered, = self.triggered.create([{ 'name': 'Test', }]) self.trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger)]) TRIGGER_LOGS.pop() # Trigger with condition condition = PYSONEncoder().encode( Eval('self', {}).get('name') == 'Bar') self.trigger.write([trigger], { 'condition': condition, }) # Matching condition self.triggered.write([triggered], { 'name': 'Bar', }) self.trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger)]) TRIGGER_LOGS.pop() # Non matching condition self.triggered.write([triggered], { 'name': 'Foo', }) self.trigger.trigger_time() self.assert_(TRIGGER_LOGS == []) # With limit number self.trigger.write([trigger], { 'condition': 'true', 'limit_number': 1, }) self.trigger.trigger_time() self.trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger)]) TRIGGER_LOGS.pop() # Delete trigger logs of limit number test self.trigger_log.delete( self.trigger_log.search([ ('trigger', '=', trigger.id), ])) # With minimum delay self.trigger.write([trigger], { 'limit_number': 0, 'minimum_time_delay': datetime.timedelta.max, }) self.trigger.trigger_time() self.trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger)]) TRIGGER_LOGS.pop() Transaction().delete = {} # Delete trigger logs of previous minimum delay test self.trigger_log.delete( self.trigger_log.search([ ('trigger', '=', trigger.id), ])) self.trigger.write( [trigger], { 'minimum_time_delay': datetime.timedelta(seconds=1), }) self.trigger.trigger_time() time.sleep(1.2) self.trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger), ([triggered], trigger)]) TRIGGER_LOGS.pop() TRIGGER_LOGS.pop() Transaction().delete = {} # Restart the cache on the get_triggers method of ir.trigger self.trigger._get_triggers_cache.clear() transaction.cursor.rollback()
def test_on_time(self): 'Test on_time' pool = Pool() Model = pool.get('ir.model') Trigger = pool.get('ir.trigger') Triggered = pool.get('test.triggered') TriggerLog = pool.get('ir.trigger.log') model, = Model.search([ ('model', '=', 'test.triggered'), ]) trigger, = Trigger.create([{ 'name': 'Test', 'model': model.id, 'on_time': True, 'condition': 'true', 'action': 'test.trigger_action|trigger', }]) triggered, = Triggered.create([{ 'name': 'Test', }]) Trigger.trigger_time() self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # Trigger with condition condition = PYSONEncoder().encode( Eval('self', {}).get('name') == 'Bar') Trigger.write([trigger], { 'condition': condition, }) # Matching condition Triggered.write([triggered], { 'name': 'Bar', }) Trigger.trigger_time() self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # Non matching condition Triggered.write([triggered], { 'name': 'Foo', }) Trigger.trigger_time() self.assertEqual(TRIGGER_LOGS, []) # With limit number Trigger.write([trigger], { 'condition': 'true', 'limit_number': 1, }) Trigger.trigger_time() Trigger.trigger_time() self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # Delete trigger logs of limit number test TriggerLog.delete(TriggerLog.search([ ('trigger', '=', trigger.id), ])) # With minimum delay Trigger.write([trigger], { 'limit_number': 0, 'minimum_time_delay': datetime.timedelta.max, }) Trigger.trigger_time() Trigger.trigger_time() self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() Transaction().delete = {} # Delete trigger logs of previous minimum delay test TriggerLog.delete(TriggerLog.search([ ('trigger', '=', trigger.id), ])) Trigger.write([trigger], { 'minimum_time_delay': datetime.timedelta(seconds=1), }) Trigger.trigger_time() # Make time pass by moving back in time the log creation trigger_log = TriggerLog.__table__() cursor = Transaction().connection.cursor() cursor.execute(*trigger_log.update( [trigger_log.create_date], [datetime.datetime.now() - datetime.timedelta(days=1)], where=trigger_log.record_id == triggered.id)) Trigger.trigger_time() self.assertEqual(TRIGGER_LOGS, [([triggered], trigger), ([triggered], trigger)]) TRIGGER_LOGS.pop() TRIGGER_LOGS.pop() Transaction().delete = {} # Restart the cache on the get_triggers method of ir.trigger Trigger._get_triggers_cache.clear()
def test_on_time(self): 'Test on_time' pool = Pool() Model = pool.get('ir.model') Trigger = pool.get('ir.trigger') Triggered = pool.get('test.triggered') TriggerLog = pool.get('ir.trigger.log') model, = Model.search([ ('model', '=', 'test.triggered'), ]) action_model, = Model.search([ ('model', '=', 'test.trigger_action'), ]) trigger, = Trigger.create([{ 'name': 'Test', 'model': model.id, 'on_time': True, 'condition': 'true', 'action_model': action_model.id, 'action_function': 'trigger', }]) triggered, = Triggered.create([{ 'name': 'Test', }]) Trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger)]) TRIGGER_LOGS.pop() # Trigger with condition condition = PYSONEncoder().encode( Eval('self', {}).get('name') == 'Bar') Trigger.write([trigger], { 'condition': condition, }) # Matching condition Triggered.write([triggered], { 'name': 'Bar', }) Trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger)]) TRIGGER_LOGS.pop() # Non matching condition Triggered.write([triggered], { 'name': 'Foo', }) Trigger.trigger_time() self.assert_(TRIGGER_LOGS == []) # With limit number Trigger.write([trigger], { 'condition': 'true', 'limit_number': 1, }) Trigger.trigger_time() Trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger)]) TRIGGER_LOGS.pop() # Delete trigger logs of limit number test TriggerLog.delete(TriggerLog.search([ ('trigger', '=', trigger.id), ])) # With minimum delay Trigger.write([trigger], { 'limit_number': 0, 'minimum_time_delay': datetime.timedelta.max, }) Trigger.trigger_time() Trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger)]) TRIGGER_LOGS.pop() Transaction().delete = {} # Delete trigger logs of previous minimum delay test TriggerLog.delete(TriggerLog.search([ ('trigger', '=', trigger.id), ])) Trigger.write([trigger], { 'minimum_time_delay': datetime.timedelta(seconds=1), }) Trigger.trigger_time() time.sleep(1.2) Trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger), ([triggered], trigger)]) TRIGGER_LOGS.pop() TRIGGER_LOGS.pop() Transaction().delete = {} # Restart the cache on the get_triggers method of ir.trigger Trigger._get_triggers_cache.clear()
def setUp(self): TRIGGER_LOGS.clear()
def test0020on_create(self): 'Test on_create' with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction: model, = self.model.search([ ('model', '=', 'test.triggered'), ]) action_model, = self.model.search([ ('model', '=', 'test.trigger_action'), ]) trigger, = self.trigger.create([{ 'name': 'Test', 'model': model.id, 'on_create': True, 'condition': 'true', 'action_model': action_model.id, 'action_function': 'trigger', }]) triggered, = self.triggered.create([{ 'name': 'Test', }]) self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # Trigger with condition condition = PYSONEncoder().encode( Eval('self', {}).get('name') == 'Bar') self.trigger.write([trigger], { 'condition': condition, }) # Matching condition triggered, = self.triggered.create([{ 'name': 'Bar', }]) self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # Non matching condition triggered, = self.triggered.create([{ 'name': 'Foo', }]) self.assertEqual(TRIGGER_LOGS, []) # With limit number self.trigger.write([trigger], { 'condition': 'true', 'limit_number': 1, }) triggered, = self.triggered.create([{ 'name': 'Test', }]) self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # With minimum delay self.trigger.write([trigger], { 'limit_number': 0, 'minimum_time_delay': datetime.timedelta(hours=1), }) triggered, = self.triggered.create([{ 'name': 'Test', }]) self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # Restart the cache on the get_triggers method of ir.trigger self.trigger._get_triggers_cache.clear() transaction.cursor.rollback()
def test0050on_time(self): 'Test on_time' with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction: model, = self.model.search([ ('model', '=', 'test.triggered'), ]) action_model, = self.model.search([ ('model', '=', 'test.trigger_action'), ]) trigger, = self.trigger.create([{ 'name': 'Test', 'model': model.id, 'on_time': True, 'condition': 'true', 'action_model': action_model.id, 'action_function': 'trigger', }]) triggered, = self.triggered.create([{ 'name': 'Test', }]) self.trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger)]) TRIGGER_LOGS.pop() # Trigger with condition condition = PYSONEncoder().encode( Eval('self', {}).get('name') == 'Bar') self.trigger.write([trigger], { 'condition': condition, }) # Matching condition self.triggered.write([triggered], { 'name': 'Bar', }) self.trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger)]) TRIGGER_LOGS.pop() # Non matching condition self.triggered.write([triggered], { 'name': 'Foo', }) self.trigger.trigger_time() self.assert_(TRIGGER_LOGS == []) # With limit number self.trigger.write([trigger], { 'condition': 'true', 'limit_number': 1, }) self.trigger.trigger_time() self.trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger)]) TRIGGER_LOGS.pop() # Delete trigger logs of limit number test self.trigger_log.delete(self.trigger_log.search([ ('trigger', '=', trigger.id), ])) # With minimum delay self.trigger.write([trigger], { 'limit_number': 0, 'minimum_time_delay': datetime.timedelta.max, }) self.trigger.trigger_time() self.trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger)]) TRIGGER_LOGS.pop() Transaction().delete = {} # Delete trigger logs of previous minimum delay test self.trigger_log.delete(self.trigger_log.search([ ('trigger', '=', trigger.id), ])) self.trigger.write([trigger], { 'minimum_time_delay': datetime.timedelta(seconds=1), }) self.trigger.trigger_time() time.sleep(1.2) self.trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger), ([triggered], trigger)]) TRIGGER_LOGS.pop() TRIGGER_LOGS.pop() Transaction().delete = {} # Restart the cache on the get_triggers method of ir.trigger self.trigger._get_triggers_cache.clear() transaction.cursor.rollback()
def test_on_create(self): 'Test on_create' pool = Pool() Model = pool.get('ir.model') Trigger = pool.get('ir.trigger') Triggered = pool.get('test.triggered') model, = Model.search([ ('model', '=', 'test.triggered'), ]) action_model, = Model.search([ ('model', '=', 'test.trigger_action'), ]) trigger, = Trigger.create([{ 'name': 'Test', 'model': model.id, 'on_create': True, 'condition': 'true', 'action_model': action_model.id, 'action_function': 'trigger', }]) triggered, = Triggered.create([{ 'name': 'Test', }]) self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # Trigger with condition condition = PYSONEncoder().encode( Eval('self', {}).get('name') == 'Bar') Trigger.write([trigger], { 'condition': condition, }) # Matching condition triggered, = Triggered.create([{ 'name': 'Bar', }]) self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # Non matching condition triggered, = Triggered.create([{ 'name': 'Foo', }]) self.assertEqual(TRIGGER_LOGS, []) # With limit number Trigger.write([trigger], { 'condition': 'true', 'limit_number': 1, }) triggered, = Triggered.create([{ 'name': 'Test', }]) self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # With minimum delay Trigger.write([trigger], { 'limit_number': 0, 'minimum_time_delay': datetime.timedelta(hours=1), }) triggered, = Triggered.create([{ 'name': 'Test', }]) self.assertEqual(TRIGGER_LOGS, [([triggered], trigger)]) TRIGGER_LOGS.pop() # Restart the cache on the get_triggers method of ir.trigger Trigger._get_triggers_cache.clear()
def test_on_time(self): 'Test on_time' pool = Pool() Model = pool.get('ir.model') Trigger = pool.get('ir.trigger') Triggered = pool.get('test.triggered') TriggerLog = pool.get('ir.trigger.log') model, = Model.search([ ('model', '=', 'test.triggered'), ]) action_model, = Model.search([ ('model', '=', 'test.trigger_action'), ]) trigger, = Trigger.create([{ 'name': 'Test', 'model': model.id, 'on_time': True, 'condition': 'true', 'action_model': action_model.id, 'action_function': 'trigger', }]) triggered, = Triggered.create([{ 'name': 'Test', }]) Trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger)]) TRIGGER_LOGS.pop() # Trigger with condition condition = PYSONEncoder().encode( Eval('self', {}).get('name') == 'Bar') Trigger.write([trigger], { 'condition': condition, }) # Matching condition Triggered.write([triggered], { 'name': 'Bar', }) Trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger)]) TRIGGER_LOGS.pop() # Non matching condition Triggered.write([triggered], { 'name': 'Foo', }) Trigger.trigger_time() self.assert_(TRIGGER_LOGS == []) # With limit number Trigger.write([trigger], { 'condition': 'true', 'limit_number': 1, }) Trigger.trigger_time() Trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger)]) TRIGGER_LOGS.pop() # Delete trigger logs of limit number test TriggerLog.delete(TriggerLog.search([ ('trigger', '=', trigger.id), ])) # With minimum delay Trigger.write([trigger], { 'limit_number': 0, 'minimum_time_delay': datetime.timedelta.max, }) Trigger.trigger_time() Trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger)]) TRIGGER_LOGS.pop() Transaction().delete = {} # Delete trigger logs of previous minimum delay test TriggerLog.delete(TriggerLog.search([ ('trigger', '=', trigger.id), ])) Trigger.write([trigger], { 'minimum_time_delay': datetime.timedelta(seconds=1), }) Trigger.trigger_time() time.sleep(1.2) Trigger.trigger_time() self.assert_(TRIGGER_LOGS == [([triggered], trigger), ([triggered], trigger)]) TRIGGER_LOGS.pop() TRIGGER_LOGS.pop() Transaction().delete = {} # Restart the cache on the get_triggers method of ir.trigger Trigger._get_triggers_cache.clear()