示例#1
0
    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
            self.trigger.write([trigger], {"condition": 'self.name == "Bar"'})

            # 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_delay": 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()
示例#2
0
    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
            self.trigger.write([trigger], {"condition": 'self.name == "Bar"'})

            # 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_delay": MAXINT})
            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_delay": 0.02})
            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 test0020on_create(self):
        '''
        Test on_create
        '''
        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            model_id = self.model.search([
                ('model', '=', 'test.triggered'),
                ])[0]

            trigger_id = self.trigger.create({
                'name': 'Test',
                'model': model_id,
                'on_create': True,
                'condition': 'True',
                'action_model': model_id,
                'action_function': 'trigger',
                })

            triggered_id = self.triggered.create({
                'name': 'Test',
                })

            self.assert_(TRIGGER_LOGS == [([triggered_id], trigger_id)])
            TRIGGER_LOGS.pop()

            # Trigger with condition
            self.trigger.write(trigger_id, {
                'condition': 'self.name == "Bar"',
                })

            # Matching condition
            triggered_id = self.triggered.create({
                'name': 'Bar',
                })
            self.assert_(TRIGGER_LOGS == [([triggered_id], trigger_id)])
            TRIGGER_LOGS.pop()

            # Non matching condition
            triggered_id = self.triggered.create({
                'name': 'Foo',
                })
            self.assert_(TRIGGER_LOGS == [])

            # With limit number
            self.trigger.write(trigger_id, {
                'condition': 'True',
                'limit_number': 1,
                })
            triggered_id = self.triggered.create({
                'name': 'Test',
                })
            self.assert_(TRIGGER_LOGS == [([triggered_id], trigger_id)])
            TRIGGER_LOGS.pop()

            # With minimum delay
            self.trigger.write(trigger_id, {
                'limit_number': 0,
                'minimum_delay': 1,
                })
            triggered_id = self.triggered.create({
                'name': 'Test',
                })
            self.assert_(TRIGGER_LOGS == [([triggered_id], trigger_id)])
            TRIGGER_LOGS.pop()

            # Restart the cache on the get_triggers method of ir.trigger
            self.trigger.get_triggers.reset()
            transaction.cursor.rollback()