Ejemplo n.º 1
0
 def test_job_delay(self):
     self.cr.execute("delete from queue_job")
     job(task_a)
     job_uuid = task_a.delay(self.session, "res.users")
     stored = self.queue_job.search([])
     self.assertEqual(len(stored), 1)
     self.assertEqual(stored.uuid, job_uuid, "Incorrect returned Job UUID")
Ejemplo n.º 2
0
 def _create_job(self):
     self.cr.execute('delete from queue_job')
     job(task_a)
     task_a.delay(self.session, 'res.users')
     stored = self.queue_job.search([])
     self.assertEqual(len(stored), 1)
     return stored
Ejemplo n.º 3
0
 def test_retry_pattern(self):
     """ When we specify a retry pattern, the eta must follow it"""
     datetime_path = 'openerp.addons.connector.queue.job.datetime'
     test_pattern = {
         1:  60,
         2: 180,
         3:  10,
         5: 300,
     }
     job(retryable_error_task, retry_pattern=test_pattern)
     with mock.patch(datetime_path, autospec=True) as mock_datetime:
         mock_datetime.now.return_value = datetime(2015, 6, 1, 15, 10, 0)
         test_job = Job(func=retryable_error_task,
                        max_retries=0)
         test_job.retry += 1
         test_job.postpone(self.session)
         self.assertEqual(test_job.retry, 1)
         self.assertEqual(test_job.eta, datetime(2015, 6, 1, 15, 11, 0))
         test_job.retry += 1
         test_job.postpone(self.session)
         self.assertEqual(test_job.retry, 2)
         self.assertEqual(test_job.eta, datetime(2015, 6, 1, 15, 13, 0))
         test_job.retry += 1
         test_job.postpone(self.session)
         self.assertEqual(test_job.retry, 3)
         self.assertEqual(test_job.eta, datetime(2015, 6, 1, 15, 10, 10))
         test_job.retry += 1
         test_job.postpone(self.session)
         self.assertEqual(test_job.retry, 4)
         self.assertEqual(test_job.eta, datetime(2015, 6, 1, 15, 10, 10))
         test_job.retry += 1
         test_job.postpone(self.session)
         self.assertEqual(test_job.retry, 5)
         self.assertEqual(test_job.eta, datetime(2015, 6, 1, 15, 15, 00))
Ejemplo n.º 4
0
 def test_retry_pattern(self):
     """ When we specify a retry pattern, the eta must follow it"""
     datetime_path = 'openerp.addons.connector.queue.job.datetime'
     test_pattern = {
         1:  60,
         2: 180,
         3:  10,
         5: 300,
     }
     job(retryable_error_task, retry_pattern=test_pattern)
     with mock.patch(datetime_path, autospec=True) as mock_datetime:
         mock_datetime.now.return_value = datetime(2015, 6, 1, 15, 10, 0)
         test_job = Job(func=retryable_error_task,
                        max_retries=0)
         test_job.retry += 1
         test_job.postpone(self.session)
         self.assertEqual(test_job.retry, 1)
         self.assertEqual(test_job.eta, datetime(2015, 6, 1, 15, 11, 0))
         test_job.retry += 1
         test_job.postpone(self.session)
         self.assertEqual(test_job.retry, 2)
         self.assertEqual(test_job.eta, datetime(2015, 6, 1, 15, 13, 0))
         test_job.retry += 1
         test_job.postpone(self.session)
         self.assertEqual(test_job.retry, 3)
         self.assertEqual(test_job.eta, datetime(2015, 6, 1, 15, 10, 10))
         test_job.retry += 1
         test_job.postpone(self.session)
         self.assertEqual(test_job.retry, 4)
         self.assertEqual(test_job.eta, datetime(2015, 6, 1, 15, 10, 10))
         test_job.retry += 1
         test_job.postpone(self.session)
         self.assertEqual(test_job.retry, 5)
         self.assertEqual(test_job.eta, datetime(2015, 6, 1, 15, 15, 00))
Ejemplo n.º 5
0
    def test_channel_on_job(self):
        job(task_a)
        self.function_model._register_jobs()
        path_a = '%s.%s' % (task_a.__module__, task_a.__name__)
        job_func = self.function_model.search([('name', '=', path_a)])
        self.assertEquals(job_func.channel, 'root')

        test_job = Job(func=task_a)
        storage = OpenERPJobStorage(self.session)
        storage.store(test_job)
        stored = self.job_model.search([('uuid', '=', test_job.uuid)])
        self.assertEquals(stored.channel, 'root')

        channel = self.channel_model.create({'name': 'sub',
                                             'parent_id': self.root_channel.id,
                                             })
        job_func.channel_id = channel

        test_job = Job(func=task_a)
        storage = OpenERPJobStorage(self.session)
        storage.store(test_job)
        stored = self.job_model.search([('uuid', '=', test_job.uuid)])
        self.assertEquals(stored.channel, 'root.sub')

        # it's also possible to override the channel
        test_job = Job(func=task_a, channel='root.sub.sub.sub')
        storage = OpenERPJobStorage(self.session)
        storage.store(test_job)
        stored = self.job_model.search([('uuid', '=', test_job.uuid)])
        self.assertEquals(stored.channel, test_job.channel)
Ejemplo n.º 6
0
 def test_job_delay(self):
     self.cr.execute('delete from queue_job')
     job(task_a)
     job_uuid = task_a.delay(self.session, 'res.users')
     stored = self.queue_job.search([])
     self.assertEqual(len(stored), 1)
     self.assertEqual(stored.uuid, job_uuid, 'Incorrect returned Job UUID')
Ejemplo n.º 7
0
    def test_channel_on_job(self):
        job(task_a)
        self.function_model._register_jobs(self.cr)
        path_a = 'openerp.addons.connector.tests.test_job.task_a'
        func_ids = self.function_model.search(self.cr, self.uid,
                                              [('name', '=', path_a)])
        self.assertEqual(len(func_ids), 1)
        job_func = self.function_model.browse(self.cr, self.uid, func_ids[0])
        self.assertEquals(job_func.channel, 'root')

        test_job = Job(func=task_a)
        storage = OpenERPJobStorage(self.session)
        storage.store(test_job)
        stored_ids = self.job_model.search(self.cr, self.uid,
                                           [('uuid', '=', test_job.uuid)])
        self.assertEqual(len(stored_ids), 1)
        stored = self.job_model.browse(self.cr, self.uid, stored_ids[0])
        self.assertEquals(stored.channel, 'root')

        channel = self.channel_model.create(self.cr, self.uid, {
            'name': 'sub',
            'parent_id': self.root_channel,
        })
        job_func.refresh()
        self.function_model.write(self.cr, self.uid, job_func.id,
                                  {'channel_id': channel})

        test_job = Job(func=task_a)
        storage = OpenERPJobStorage(self.session)
        storage.store(test_job)
        stored_ids = self.job_model.search(self.cr, self.uid,
                                           [('uuid', '=', test_job.uuid)])
        self.assertEqual(len(stored_ids), 1)
        stored = self.job_model.browse(self.cr, self.uid, stored_ids[0])
        self.assertEquals(stored.channel, 'root.sub')
Ejemplo n.º 8
0
 def test_job_delay_override_channel(self):
     self.cr.execute('delete from queue_job')
     job(dummy_task_args)
     task_a.delay(self.session, 'res.users', 'o', channel='root.sub.sub')
     stored = self.queue_job.search([])
     self.assertEqual(len(stored), 1)
     self.assertEqual('root.sub.sub', stored.channel)
Ejemplo n.º 9
0
 def _create_job(self):
     self.cr.execute('delete from queue_job')
     job(task_a)
     task_a.delay(self.session, 'res.users')
     stored = self.queue_job.search([])
     self.assertEqual(len(stored), 1)
     return stored
Ejemplo n.º 10
0
 def test_register_jobs(self):
     job(task_a)
     job(task_b)
     self.function_model._register_jobs()
     path_a = 'openerp.addons.connector.tests.test_job.task_a'
     path_b = 'openerp.addons.connector.tests.test_job.task_b'
     self.assertTrue(self.function_model.search([('name', '=', path_a)]))
     self.assertTrue(self.function_model.search([('name', '=', path_b)]))
Ejemplo n.º 11
0
 def test_register_jobs(self):
     job(task_a)
     job(task_b)
     self.function_model._register_jobs()
     path_a = "openerp.addons.connector.tests.test_job.task_a"
     path_b = "openerp.addons.connector.tests.test_job.task_b"
     self.assertTrue(self.function_model.search([("name", "=", path_a)]))
     self.assertTrue(self.function_model.search([("name", "=", path_b)]))
Ejemplo n.º 12
0
 def test_register_jobs(self):
     job(task_a)
     job(task_b)
     self.function_model._register_jobs()
     path_a = 'openerp.addons.connector.tests.test_job.task_a'
     path_b = 'openerp.addons.connector.tests.test_job.task_b'
     self.assertTrue(self.function_model.search([('name', '=', path_a)]))
     self.assertTrue(self.function_model.search([('name', '=', path_b)]))
Ejemplo n.º 13
0
 def test_job_delay(self):
     self.cr.execute('delete from queue_job')
     job(task_a)
     job_uuid = task_a.delay(self.session, 'res.users')
     stored = self.queue_job.search(self.cr, self.uid, [])
     self.assertEqual(len(stored), 1)
     stored_brw = self.queue_job.browse(self.cr, self.uid, stored)
     self.assertEqual(
         stored_brw[0].uuid,
         job_uuid,
         'Incorrect returned Job UUID')
Ejemplo n.º 14
0
    def test_default_channel(self):
        self.function_model.search([]).unlink()
        job(task_a, default_channel='root.sub.subsub')
        self.assertEquals(task_a.default_channel, 'root.sub.subsub')

        self.function_model._register_jobs()

        path_a = '%s.%s' % (task_a.__module__, task_a.__name__)
        job_func = self.function_model.search([('name', '=', path_a)])

        self.assertEquals(job_func.channel, 'root.sub.subsub')
        channel = job_func.channel_id
        self.assertEquals(channel.name, 'subsub')
        self.assertEquals(channel.parent_id.name, 'sub')
        self.assertEquals(channel.parent_id.parent_id.name, 'root')
Ejemplo n.º 15
0
    def test_default_channel(self):
        self.function_model.search([]).unlink()
        job(task_a, default_channel='root.sub.subsub')
        self.assertEquals(task_a.default_channel, 'root.sub.subsub')

        self.function_model._register_jobs()

        path_a = '%s.%s' % (task_a.__module__, task_a.__name__)
        job_func = self.function_model.search([('name', '=', path_a)])

        self.assertEquals(job_func.channel, 'root.sub.subsub')
        channel = job_func.channel_id
        self.assertEquals(channel.name, 'subsub')
        self.assertEquals(channel.parent_id.name, 'sub')
        self.assertEquals(channel.parent_id.parent_id.name, 'root')
Ejemplo n.º 16
0
 def test_register_jobs(self):
     job(task_a)
     job(task_b)
     self.function_model._register_jobs()
     path_a = 'connector.tests.test_job.task_a'
     path_b = 'connector.tests.test_job.task_b'
     # if you run tests with standard ``--test-enable`
     # the path is exactly 'openerp.addons.connector.tests.test_job.task_a'
     # BUT if you run them using nose test from anybox recipe
     # you get different path, like '..connector.tests.test_job.task_a'
     # So, let's use `like` to match them in both cases.
     self.assertTrue(
         self.function_model.search([('name', 'like', '%' + path_a)]))
     self.assertTrue(
         self.function_model.search([('name', 'like', '%' + path_b)]))
Ejemplo n.º 17
0
    def test_default_channel(self):
        self.function_model.search([]).unlink()
        job(task_a, default_channel="root.sub.subsub")
        self.assertEquals(task_a.default_channel, "root.sub.subsub")

        self.function_model._register_jobs()

        path_a = "%s.%s" % (task_a.__module__, task_a.__name__)
        job_func = self.function_model.search([("name", "=", path_a)])

        self.assertEquals(job_func.channel, "root.sub.subsub")
        channel = job_func.channel_id
        self.assertEquals(channel.name, "subsub")
        self.assertEquals(channel.parent_id.name, "sub")
        self.assertEquals(channel.parent_id.parent_id.name, "root")
Ejemplo n.º 18
0
 def test_job_decorator(self):
     """ Test the job decorator """
     default_channel = "channel"
     retry_pattern = {1: 5}
     partial = job(None, default_channel=default_channel, retry_pattern=retry_pattern)
     self.assertEquals(partial.keywords.get("default_channel"), default_channel)
     self.assertEquals(partial.keywords.get("retry_pattern"), retry_pattern)
Ejemplo n.º 19
0
 def test_retry_pattern_no_zero(self):
     """ When we specify a retry pattern without 0, uses RETRY_INTERVAL"""
     test_pattern = {3: 180}
     job(retryable_error_task, retry_pattern=test_pattern)
     test_job = Job(func=retryable_error_task, max_retries=0)
     test_job.retry += 1
     self.assertEqual(test_job.retry, 1)
     self.assertEqual(test_job._get_retry_seconds(), RETRY_INTERVAL)
     test_job.retry += 1
     self.assertEqual(test_job.retry, 2)
     self.assertEqual(test_job._get_retry_seconds(), RETRY_INTERVAL)
     test_job.retry += 1
     self.assertEqual(test_job.retry, 3)
     self.assertEqual(test_job._get_retry_seconds(), 180)
     test_job.retry += 1
     self.assertEqual(test_job.retry, 4)
     self.assertEqual(test_job._get_retry_seconds(), 180)
Ejemplo n.º 20
0
 def test_register_jobs(self):
     job(task_a)
     job(task_b)
     self.function_model._register_jobs()
     path_a = 'connector.tests.test_job.task_a'
     path_b = 'connector.tests.test_job.task_b'
     # if you run tests with standard ``--test-enable`
     # the path is exactly 'openerp.addons.connector.tests.test_job.task_a'
     # BUT if you run them using nose test from anybox recipe
     # you get different path, like '..connector.tests.test_job.task_a'
     # So, let's use `like` to match them in both cases.
     self.assertTrue(
         self.function_model.search([('name', 'like', '%' + path_a)])
     )
     self.assertTrue(
         self.function_model.search([('name', 'like', '%' + path_b)])
     )
Ejemplo n.º 21
0
 def test_job_decorator(self):
     """ Test the job decorator """
     default_channel = 'channel'
     retry_pattern = {1: 5}
     partial = job(None, default_channel=default_channel,
                   retry_pattern=retry_pattern)
     self.assertEquals(partial.keywords.get('default_channel'),
                       default_channel)
     self.assertEquals(partial.keywords.get('retry_pattern'), retry_pattern)
Ejemplo n.º 22
0
 def test_retry_pattern_no_zero(self):
     """ When we specify a retry pattern without 0, uses RETRY_INTERVAL"""
     test_pattern = {
         3: 180,
     }
     job(retryable_error_task, retry_pattern=test_pattern)
     test_job = Job(func=retryable_error_task, max_retries=0)
     test_job.retry += 1
     self.assertEqual(test_job.retry, 1)
     self.assertEqual(test_job._get_retry_seconds(), RETRY_INTERVAL)
     test_job.retry += 1
     self.assertEqual(test_job.retry, 2)
     self.assertEqual(test_job._get_retry_seconds(), RETRY_INTERVAL)
     test_job.retry += 1
     self.assertEqual(test_job.retry, 3)
     self.assertEqual(test_job._get_retry_seconds(), 180)
     test_job.retry += 1
     self.assertEqual(test_job.retry, 4)
     self.assertEqual(test_job._get_retry_seconds(), 180)
Ejemplo n.º 23
0
    def test_default_channel(self):
        func_ids = self.function_model.search(self.cr, self.uid, [])
        self.function_model.unlink(self.cr, self.uid, func_ids)
        job(task_a, default_channel='root.sub.subsub')
        self.assertEquals(task_a.default_channel, 'root.sub.subsub')

        self.function_model._register_jobs(self.cr)

        path_a = 'openerp.addons.connector.tests.test_job.task_a'
        func_ids = self.function_model.search(self.cr, self.uid,
                                              [('name', '=', path_a)])
        self.assertEqual(len(func_ids), 1)
        job_func = self.function_model.browse(self.cr, self.uid, func_ids[0])

        self.assertEquals(job_func.channel, 'root.sub.subsub')
        channel = job_func.channel_id
        self.assertEquals(channel.name, 'subsub')
        self.assertEquals(channel.parent_id.name, 'sub')
        self.assertEquals(channel.parent_id.parent_id.name, 'root')
Ejemplo n.º 24
0
 def test_job_delay(self):
     self.cr.execute('delete from queue_job')
     deco_task = job(task_a)
     job_uuid = task_a.delay(self.session, 'res.users')
     stored = self.queue_job.search(self.cr, self.uid, [])
     self.assertEqual(len(stored), 1)
     stored_brw = self.queue_job.browse(self.cr, self.uid, stored)
     self.assertEqual(
         stored_brw[0].uuid,
         job_uuid,
         'Incorrect returned Job UUID')
Ejemplo n.º 25
0
    def test_channel_on_job(self):
        job(task_a)
        self.function_model._register_jobs()
        path_a = "%s.%s" % (task_a.__module__, task_a.__name__)
        job_func = self.function_model.search([("name", "=", path_a)])
        self.assertEquals(job_func.channel, "root")

        test_job = Job(func=task_a)
        storage = OpenERPJobStorage(self.session)
        storage.store(test_job)
        stored = self.job_model.search([("uuid", "=", test_job.uuid)])
        self.assertEquals(stored.channel, "root")

        channel = self.channel_model.create({"name": "sub", "parent_id": self.root_channel.id})
        job_func.channel_id = channel

        test_job = Job(func=task_a)
        storage = OpenERPJobStorage(self.session)
        storage.store(test_job)
        stored = self.job_model.search([("uuid", "=", test_job.uuid)])
        self.assertEquals(stored.channel, "root.sub")
Ejemplo n.º 26
0
    def test_channel_on_job(self):
        job(task_a)
        self.function_model._register_jobs()
        path_a = '%s.%s' % (task_a.__module__, task_a.__name__)
        job_func = self.function_model.search([('name', '=', path_a)])
        self.assertEquals(job_func.channel, 'root')

        test_job = Job(func=task_a)
        storage = OpenERPJobStorage(self.session)
        storage.store(test_job)
        stored = self.job_model.search([('uuid', '=', test_job.uuid)])
        self.assertEquals(stored.channel, 'root')

        channel = self.channel_model.create({'name': 'sub',
                                             'parent_id': self.root_channel.id,
                                             })
        job_func.channel_id = channel

        test_job = Job(func=task_a)
        storage = OpenERPJobStorage(self.session)
        storage.store(test_job)
        stored = self.job_model.search([('uuid', '=', test_job.uuid)])
        self.assertEquals(stored.channel, 'root.sub')
Ejemplo n.º 27
0
 def test_job_delay(self):
     self.cr.execute('delete from queue_job')
     deco_task = job(task_a)
     task_a.delay(self.session, 'res.users')
     stored = self.queue_job.search(self.cr, self.uid, [])
     self.assertEqual(len(stored), 1)
Ejemplo n.º 28
0
 def test_job_delay_args(self):
     self.cr.execute("delete from queue_job")
     job(dummy_task_args)
     task_a.delay(self.session, "res.users", "o", "k", c="!")
     stored = self.queue_job.search([])
     self.assertEqual(len(stored), 1)
Ejemplo n.º 29
0
 def test_job_delay_args(self):
     self.cr.execute('delete from queue_job')
     job(dummy_task_args)
     task_a.delay(self.session, 'res.users', 'o', 'k', c='!')
     stored = self.queue_job.search([])
     self.assertEqual(len(stored), 1)
Ejemplo n.º 30
0
 def test_job_delay_args(self):
     self.cr.execute('delete from queue_job')
     job(dummy_task_args)
     task_a.delay(self.session, 'res.users', 'o', 'k', c='!')
     stored = self.queue_job.search([])
     self.assertEqual(len(stored), 1)