diff --git a/cron_run_manually/__openerp__.py b/cron_run_manually/__openerp__.py index d20812cb1..4e92e72ed 100644 --- a/cron_run_manually/__openerp__.py +++ b/cron_run_manually/__openerp__.py @@ -30,5 +30,8 @@ of the scheduler. """, 'depends': ['base'], 'data': ['view/ir_cron.xml'], + "test": [ + "tests/correct_uid.yml", + ], 'installable': True, } diff --git a/cron_run_manually/ir_cron.py b/cron_run_manually/ir_cron.py index 31ad714e3..7b5ba8133 100644 --- a/cron_run_manually/ir_cron.py +++ b/cron_run_manually/ir_cron.py @@ -65,3 +65,9 @@ class Cron(models.Model): self.function) args = safe_eval('tuple(%s)' % (self.args or '')) return method(*args) + + @api.model + def _current_uid(self): + """This function returns the current UID, for testing purposes.""" + + return self.env.uid diff --git a/cron_run_manually/tests/correct_uid.yml b/cron_run_manually/tests/correct_uid.yml new file mode 100644 index 000000000..34af0c227 --- /dev/null +++ b/cron_run_manually/tests/correct_uid.yml @@ -0,0 +1,23 @@ +- I create a user that will run the job. +- !record {model: res.users, id: worker_user, view: False}: + company_id: base.main_company + name: worker + login: worker + password: worker + email: worker@example.com + +- Create a cron job to check the UID +- !record {model: ir.cron, id: check_uid_job}: + name: Check UID + active: True + user_id: worker_user + interval_number: 1 + interval_type: days + numbercall: -1 + doall: False + model: ir.cron + function: _current_uid + +- I execute the cron job manually to check its running UID +- !assert {model: ir.cron, id: check_uid_job}: | + self.run_manually()[0] == self.user_id