Commit 325b6e0d authored by KarenKawaii's avatar KarenKawaii
Browse files

[ADD] set_group_by_department: Add test to verify that the new group was...

[ADD] set_group_by_department: Add test to verify that the new group was correctly set to the employee's user and if is necessary write the related user id into the employee when the employee's mail is like the user's login. For this purpose the data demo with the users and employees is added.
parent 57957194
......@@ -20,6 +20,7 @@
'wizard/wizard_department_group_view.xml',
],
'demo': [
'demo/employees.xml',
],
'test': [],
'qweb': [],
......
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<!--Users-->
<record model="res.users" id="user_employee_1" context="{'no_reset_password': True}">
<field name="name">Peter Partner Manager User</field>
<field name="login">peter@company.com</field>
<field name="email">peter@company.com</field>
<field name="company_id"
eval="ref('base.main_company')"/>
<field name="company_ids"
eval="[(4, ref('base.main_company'))]"/>
<field name="groups_id"
eval="[(4, ref('base.group_hr_manager'))]"/>
</record>
<record model="res.users" id="user_employee_2" context="{'no_reset_password': True}">
<field name="name">Maria White User</field>
<field name="login">maria@company.com</field>
<field name="company_id"
eval="ref('base.main_company')"/>
<field name="company_ids"
eval="[(4, ref('base.main_company'))]"/>
<field name="groups_id"
eval="[(4, ref('base.group_hr_user'))]"/>
</record>
<record model="res.users" id="user_employee_3" context="{'no_reset_password': True}">
<field name="name">Nina Anders User</field>
<field name="login">nina@company.com</field>
<field name="company_id"
eval="ref('base.main_company')"/>
<field name="company_ids"
eval="[(4, ref('base.main_company'))]"/>
<field name="groups_id"
eval="[(4, ref('base.group_user'))]"/>
</record>
<!--Employees-->
<record id="employee_1" model="hr.employee">
<field name="name">Peter Parker</field>
<field name="user_id" ref="user_employee_1"/>
<field name="department_id" ref="hr.dep_management"/>
<field name="job_id" ref="hr.job_ceo"/>
<field name="category_ids" eval="[(6, 0, [ref('hr.employee_category_2')])]"/>
<field name="work_location">Grand-Road</field>
<field name="work_phone">+3289810000</field>
<field name="work_email">peter@company.com</field>
</record>
<record id="employee_2" model="hr.employee">
<field name="name">Maria White</field>
<field name="user_id" ref="user_employee_2"/>
<field name="department_id" ref="hr.dep_management"/>
<field name="job_id" ref="hr.job_ceo"/>
<field name="category_ids" eval="[(6, 0, [ref('hr.employee_category_2')])]"/>
<field name="work_location">Grand-Road</field>
<field name="work_phone">+320021111</field>
</record>
<record id="employee_3" model="hr.employee">
<field name="name">Nina Anders</field>
<field name="department_id" ref="hr.dep_management"/>
<field name="job_id" ref="hr.job_ceo"/>
<field name="category_ids" eval="[(6, 0, [ref('hr.employee_category_2')])]"/>
<field name="work_location">Grand-Road</field>
<field name="work_phone">+323350000</field>
<field name="work_email">nina@company.com</field>
</record>
<record id="employee_4" model="hr.employee">
<field name="name">Julia Roberts</field>
<field name="department_id" ref="hr.dep_management"/>
<field name="job_id" ref="hr.job_ceo"/>
<field name="category_ids" eval="[(6, 0, [ref('hr.employee_category_2')])]"/>
<field name="work_location">Grand-Road</field>
<field name="work_phone">+323205555</field>
<field name="work_email">julia@company.com</field>
</record>
<record id="employee_5" model="hr.employee">
<field name="name">Joseph Smith</field>
<field name="department_id" ref="hr.dep_management"/>
<field name="job_id" ref="hr.job_ceo"/>
<field name="category_ids" eval="[(6, 0, [ref('hr.employee_category_2')])]"/>
<field name="work_location">Grand-Road</field>
<field name="work_phone">+323205555</field>
</record>
</data>
</openerp>
# coding: utf-8
# © 2016 Vauxoo - http://www.vauxoo.com
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# info Vauxoo (info@vauxoo.com)
# coded by: karen@vauxoo.com
# planned by: nhomar@vauxoo.com
from . import test_set_group_by_department
# coding: utf-8
# © 2016 Vauxoo - http://www.vauxoo.com
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# info Vauxoo (info@vauxoo.com)
# coded by: karen@vauxoo.com
# planned by: nhomar@vauxoo.com
from openerp.tests.common import TransactionCase
class TestSetGroupByDepartment(TransactionCase):
"""In order to test the wizard that removes all created groups and
according to the department assign the group in question to the employee.
So, this test does the following:
1. Takes the employees who will be assigned a new group.
2. Calls the wizard to set only the new group for the employees.
3. Do an assertTrue to verify that the new group has been set correctly.
"""
def setUp(self):
"""Define global variables to test method."""
super(TestSetGroupByDepartment, self).setUp()
self.hr_employee_obj = self.env['hr.employee']
self.users_obj = self.env['res.users']
self.employee_1 = self.env.ref('set_group_by_department.employee_1')
self.employee_2 = self.env.ref('set_group_by_department.employee_2')
self.employee_3 = self.env.ref('set_group_by_department.employee_3')
self.employee_4 = self.env.ref('set_group_by_department.employee_4')
self.employee_5 = self.env.ref('set_group_by_department.employee_5')
self.user_1 = self.env.ref('set_group_by_department.user_employee_1')
self.user_2 = self.env.ref('set_group_by_department.user_employee_2')
self.user_3 = self.env.ref('set_group_by_department.user_employee_3')
self.group_id = self.env.ref('set_group_by_department.'
'res_group_vx_administrative_team')
self.wiz_obj = self.env['wizard.department.group'].with_context({
'active_model': 'hr.employee',
'active_ids': [self.employee_1.id, self.employee_2.id,
self.employee_3.id, self.employee_4.id,
self.employee_5.id],
})
def test_10_set_new_group_and_user_id(self):
"""Set the new group and the user_id if necessary on the employees.
"""
wiz_id = self.wiz_obj.create({
'dept_group_id': self.group_id.id,
})
wiz_id.set_group()
# Verify that the new group was set to the employee's user.
self.assertEqual(self.user_1.groups_id.id, self.group_id.id,
'A different group was established.')
self.assertEqual(self.user_2.groups_id.id, self.group_id.id,
'A different group was established.')
self.assertEqual(self.user_3.groups_id.id, self.group_id.id,
'A different group was established.')
# Verify that the related user_id was set in the employee_3 too.
self.assertEqual(self.employee_3.user_id.id, self.user_3.id,
'A different user_id was established.')
# For employees 4 and 5 the new group was not established because they
# don't have their corresponding user.
# So, I verify that the employees 4 and 5 don't have a related user_id.
self.assertTrue(self.employee_4.user_id.id is False,
'This employee should not have a user_id.')
self.assertTrue(self.employee_5.user_id.id is False,
'This employee should not have a user_id.')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment