From 1e910f987400828b258d6bad6384be7a9ccc8b51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Taymans?= Date: Wed, 10 Jan 2024 16:15:05 +0100 Subject: [PATCH] [OU-ADD] hr: tests for work_contact_id --- .../scripts/hr/16.0.1.1/tests/__init__.py | 1 + .../scripts/hr/16.0.1.1/tests/data.py | 173 ++++++++++++++++++ .../hr/16.0.1.1/tests/test_hr_migration.py | 23 +++ 3 files changed, 197 insertions(+) create mode 100644 openupgrade_scripts/scripts/hr/16.0.1.1/tests/__init__.py create mode 100644 openupgrade_scripts/scripts/hr/16.0.1.1/tests/data.py create mode 100644 openupgrade_scripts/scripts/hr/16.0.1.1/tests/test_hr_migration.py diff --git a/openupgrade_scripts/scripts/hr/16.0.1.1/tests/__init__.py b/openupgrade_scripts/scripts/hr/16.0.1.1/tests/__init__.py new file mode 100644 index 000000000000..ac0ab7e61e91 --- /dev/null +++ b/openupgrade_scripts/scripts/hr/16.0.1.1/tests/__init__.py @@ -0,0 +1 @@ +from . import test_hr_migration diff --git a/openupgrade_scripts/scripts/hr/16.0.1.1/tests/data.py b/openupgrade_scripts/scripts/hr/16.0.1.1/tests/data.py new file mode 100644 index 000000000000..19d04a23cf11 --- /dev/null +++ b/openupgrade_scripts/scripts/hr/16.0.1.1/tests/data.py @@ -0,0 +1,173 @@ +env = locals().get("env") + +# Image of an employee +# hr/static/img/employee_al-image.jpg +image_base64 = """ +/9j/4AAQSkZJRgABAQEASABIAAD/4gKgSUNDX1BST0ZJTEUAAQEAAAKQbGNtcwQwAABtbnRyUkdC +IFhZWiAH3QAMABkAAAADACZhY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9tYAAQAA +AADTLWxjbXMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAtk +ZXNjAAABCAAAADhjcHJ0AAABQAAAAE53dHB0AAABkAAAABRjaGFkAAABpAAAACxyW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o2mO33xbY3JC25Pp8vXEgmCTLD4d1RjzCSKXfungLBj1YqQQODbp2A +HyxZaim2TPGqCxCE2633Y5hpmo+z57RzbobeMFsnoRb+vXnHTdRTRivdkYsXhWwt0Ixl6+FZU/tG +p+nyvHX0QMBkspABUDZu9Dhe8k1NqWlmp03sqcD1wXQ+Iad7tYiQ3F++FtSxGeUgBt5bDn2wqC5Z +05HwgYwVM8zyiDaXdibNybnnsR3HX1xd/ALPcu03rhJswirmkqYTRwNSgExu7D/CBdwbDp0J7459 +FKzBohvjjVrBRbzHpcjv1P0xk1RLFVxSZdUPTPEwYTqbOrix4t057/8AONiUVPHRjYsjx5FKuj7O +gyLKEq5s6WniglnBWWopl8JZR0KzxDyse1yL+4x8w/HzQ8OjtSLV5XCY8nzF2kp1AO2B+rxA+n+J +fa47Yoh8bdUrDB4UGXiaOPZUTyA/vBtYFlvYHi9x8sI9cfEjMtY6ZfI81p8uSIyLJG0UbbomBuCr +FiPUWt0JxxYdPlhKzQ1OpwZY7f8ABz6KZZXhjHReW598CVEniSlgOS2Dly4xJujmJD+XxLceth+n +0x+jy+NZ4/EkO1OSGVl3e1wOMdm2Rmbka5Y9pVgfMyXIPHPQf74EMwWwuCSPXoMNmWEICYrPa6sz +EgjpYDvYj/62Ni1MA2q1NAG6XCdMW2fuDd+wrWqX7FJGCCd9/wAvL/tjCnqwg2lSwJ5Udx3wbmZR +VMn2eJ93Ie1mPHqD05H64o9a/DefIdK5VqyjzFarL62CGZo3TbLCZFBtxwwBNr8YTkmoNJvsdjg5 +ptLomogyxhy5VV5WxBv7dO1/pgx2/ePEJXw5f8QO0Wv09jwMAUVSskkQZHEe3bvLWv1tYfPBUkY8 +UsjKqkHzqOhPfk39sPi7XAh9hMMwNVE8TBkEgdnIsWN/T04789cdUzZy9QtuPuOOODjkEMeydSzt +J5gBuNucdWrpnIge6/3HW/tjP1/cTR/T+pH/2Q== +""" + +# Create res.partner +partners = [ + { + "name": "Ronnie Hart", + "email": "ronnie.hart@home.me", + "phone": "+32 2 420 42 42", + "mobile": "+32 420 42 42 42", + }, + { + "name": "Alanis Dubois", + "phone": "+32 2 421 42 42", + "mobile": "+32 421 42 42 42", + "email": "alanis.dubois@example.com", + "image_1920": image_base64, + }, +] +partner_ids = [env["res.partner"].create(partner) for partner in partners] + +# Create res.users +users = [ + { + "login": "ronniehart", + "partner_id": partner_ids[0].id, + }, + { + "login": "alanisdubois", + "partner_id": partner_ids[1].id, + }, +] +user_ids = [env["res.users"].create(user) for user in users] + +# Create hr.employee +employees = [ + { + "name": "Ronnie Hart", + "job_title": "Chief Technical Officer", + "work_phone": "(376)-310-7863", + "mobile_phone": "(538)-672-3185", + "work_email": "ronnie.hart87@example.com", + "image_1920": image_base64, + "user_id": user_ids[0].id, + }, + { + "name": "Alanis Dubois", + "job_title": "Experienced Developer", + "work_phone": "+32 2 421 42 42", + "mobile_phone": "+32 421 42 42 42", + "work_email": "alanis.dubois@example.com", + "image_1920": image_base64, + "user_id": user_ids[1].id, + }, + { + "name": "Anita Oliver", + "job_title": "Experienced Developer", + "work_phone": "(538)-497-4804", + "mobile_phone": "(538)-672-3185", + "work_email": "anita.oliver32@example.com", + "image_1920": image_base64, + }, +] + +for employee in employees: + env["hr.employee"].create(employee) + +env.cr.commit() diff --git a/openupgrade_scripts/scripts/hr/16.0.1.1/tests/test_hr_migration.py b/openupgrade_scripts/scripts/hr/16.0.1.1/tests/test_hr_migration.py new file mode 100644 index 000000000000..29eaa2f17887 --- /dev/null +++ b/openupgrade_scripts/scripts/hr/16.0.1.1/tests/test_hr_migration.py @@ -0,0 +1,23 @@ +from odoo.tests import TransactionCase + + +class TestHrMigration(TransactionCase): + def test_work_contact_creation(self): + """Make sure work_contact_id has been created""" + anita_oliver = self.env["hr.employee"].search([("name", "=", "Anita Oliver")]) + self.assertEqual(anita_oliver.mobile_phone, anita_oliver.work_contact_id.mobile) + self.assertEqual(anita_oliver.work_email, anita_oliver.work_contact_id.email) + self.assertEqual( + anita_oliver.image_1920, anita_oliver.work_contact_id.image_1920 + ) + + def test_work_contact_link(self): + """Make sure work_contact_id has been linked to an existing + partner + """ + alanis_bubois = self.env["res.partner"].search([("name", "=", "Alanis Dubois")]) + employee = self.env["hr.employee"].search([("name", "=", "Alanis Dubois")]) + self.assertEqual(alanis_bubois.id, employee.work_contact_id.id) + ronnie_hart = self.env["res.partner"].search([("name", "=", "Ronnie Hart")]) + employee = self.env["hr.employee"].search([("name", "=", "Ronnie Hart")]) + self.assertEqual(ronnie_hart.id, employee.work_contact_id.id)