| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
from odoo.addons.mail.tests.common import mail_new_test_user |
| 5 |
from odoo.exceptions import AccessError |
| 6 |
from odoo.tests import common, Form, tagged |
| 7 |
from odoo.tools import mute_logger |
| 8 |
|
| 9 |
|
| 10 |
@tagged('security') |
| 11 |
class TestRecruitmentSurvey(common.TransactionCase): |
| 12 |
|
| 13 |
@classmethod |
| 14 |
def setUpClass(cls): |
| 15 |
super(TestRecruitmentSurvey, cls).setUpClass() |
| 16 |
|
| 17 |
|
| 18 |
cls.hr_recruitment_manager = mail_new_test_user( |
| 19 |
cls.env, name='Gustave Doré', login='hr_recruitment_manager', email='[email protected]', |
| 20 |
groups='hr_recruitment.group_hr_recruitment_manager' |
| 21 |
) |
| 22 |
cls.hr_recruitment_user = mail_new_test_user( |
| 23 |
cls.env, name='Lukas Peeters', login='hr_recruitment_user', email='[email protected]', |
| 24 |
groups='hr_recruitment.group_hr_recruitment_user' |
| 25 |
) |
| 26 |
cls.hr_recruitment_interviewer = mail_new_test_user( |
| 27 |
cls.env, name='Eglantine Ask', login='hr_recruitment_interviewer', email='[email protected]', |
| 28 |
groups='hr_recruitment.group_hr_recruitment_interviewer' |
| 29 |
) |
| 30 |
|
| 31 |
|
| 32 |
cls.department_admins = cls.env['hr.department'].create({'name': 'Admins'}) |
| 33 |
cls.survey_sysadmin, cls.survey_custom = cls.env['survey.survey'].create([ |
| 34 |
{'title': 'Questions for Sysadmin job offer', 'survey_type': 'recruitment'}, |
| 35 |
{'title': 'Survey of type custom for security tests purpose', 'survey_type': 'custom'} |
| 36 |
]) |
| 37 |
cls.question_ft = cls.env['survey.question'].create({ |
| 38 |
'title': 'Test Free Text', |
| 39 |
'survey_id': cls.survey_sysadmin.id, |
| 40 |
'sequence': 2, |
| 41 |
'question_type': 'text_box', |
| 42 |
}) |
| 43 |
cls.job = cls.env['hr.job'].create({ |
| 44 |
'name': 'Technical worker', |
| 45 |
'survey_id': cls.survey_sysadmin.id, |
| 46 |
'description': None, |
| 47 |
}) |
| 48 |
cls.job_applicant = cls.env['hr.applicant'].create({ |
| 49 |
'partner_name': 'Jane Doe', |
| 50 |
'email_from': '[email protected]', |
| 51 |
'department_id': cls.department_admins.id, |
| 52 |
'job_id': cls.job.id, |
| 53 |
}) |
| 54 |
|
| 55 |
@mute_logger('odoo.addons.base.models.ir_rule') |
| 56 |
def test_send_survey(self): |
| 57 |
Answer = self.env['survey.user_input'] |
| 58 |
invite_recruitment = self._prepare_invite(self.survey_sysadmin, self.job_applicant) |
| 59 |
invite_recruitment.action_invite() |
| 60 |
|
| 61 |
self.assertEqual(invite_recruitment.applicant_id, self.job_applicant) |
| 62 |
self.assertNotEqual(self.job_applicant.response_ids.ids, False) |
| 63 |
answers = Answer.search([('survey_id', '=', self.survey_sysadmin.id)]) |
| 64 |
self.assertEqual(len(answers), 1) |
| 65 |
self.assertEqual(self.job_applicant.response_ids, answers) |
| 66 |
self.assertSetEqual( |
| 67 |
set(answers.mapped('email')), |
| 68 |
{self.job_applicant.email_from}) |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
invite_recruitment.with_user(self.hr_recruitment_manager).action_invite() |
| 73 |
with self.assertRaises(AccessError): |
| 74 |
self.survey_custom.with_user(self.hr_recruitment_manager).read(['title']) |
| 75 |
|
| 76 |
for user in (self.hr_recruitment_interviewer, self.hr_recruitment_user): |
| 77 |
with self.subTest(user=user): |
| 78 |
with self.assertRaises(AccessError): |
| 79 |
invite_recruitment.with_user(user).action_invite() |
| 80 |
self.job.interviewer_ids = user |
| 81 |
invite_recruitment.with_user(user).action_invite() |
| 82 |
self.job.interviewer_ids = False |
| 83 |
with self.assertRaises(AccessError): |
| 84 |
invite_recruitment.with_user(user).action_invite() |
| 85 |
self.job_applicant.interviewer_ids = user |
| 86 |
invite_recruitment.with_user(user).action_invite() |
| 87 |
|
| 88 |
@mute_logger('odoo.addons.base.models.ir_rule') |
| 89 |
def test_print_survey(self): |
| 90 |
action_print = self.job_applicant.action_print_survey() |
| 91 |
self.assertEqual(action_print['type'], 'ir.actions.act_url') |
| 92 |
self.job_applicant.response_ids = self.env['survey.user_input'].create({'survey_id': self.survey_sysadmin.id}) |
| 93 |
action_print_with_response = self.job_applicant.action_print_survey() |
| 94 |
self.assertIn(self.job_applicant.response_ids.access_token, action_print_with_response['url']) |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
with self.assertRaises(AccessError): |
| 99 |
self.job_applicant.with_user(self.hr_recruitment_interviewer).action_print_survey() |
| 100 |
|
| 101 |
self.job_applicant.with_user(self.hr_recruitment_manager).action_print_survey() |
| 102 |
with self.assertRaises(AccessError): |
| 103 |
self.survey_custom.with_user(self.hr_recruitment_manager).action_print_survey() |
| 104 |
|
| 105 |
with self.assertRaises(AccessError): |
| 106 |
self.job_applicant.with_user(self.hr_recruitment_user).action_print_survey() |
| 107 |
self.job_applicant.interviewer_ids = self.hr_recruitment_user |
| 108 |
self.job_applicant.with_user(self.hr_recruitment_user).action_print_survey() |
| 109 |
|
| 110 |
def _prepare_invite(self, survey, applicant): |
| 111 |
survey.write({'access_mode': 'public', 'users_login_required': False}) |
| 112 |
return Form.from_action(self.env, applicant.action_send_survey()).save() |