Skip to content

Commit

Permalink
[IMP] hr_employee_id: Improve tests coverage
Browse files Browse the repository at this point in the history
- Add test : test_generate_identification_id_exception
  • Loading branch information
maisim committed Aug 16, 2024
1 parent 85bd660 commit fceb15b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions hr_employee_id/tests/test_employee_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Copyright 2018 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from unittest.mock import patch

from odoo.exceptions import UserError
from odoo.tests import common


Expand Down Expand Up @@ -145,3 +148,23 @@ def test_multi_company_res_config(self):
self.assertEqual(res2["employee_id_random_digits"], DIGITS2)
self.assertEqual(res2["employee_id_gen_method"], METHOD2)
self.assertEqual(res2["employee_id_sequence"], sequence2.id)

def test_generate_identification_id_exception(self):
sequence = self.sequence
company = self.company
company.employee_id_gen_method = "sequence"
company.employee_id_sequence = sequence.id

# Create an user with 00001 identification_id
self.employee_model.create(
{"name": "First Employee", "identification_id": "00001"}
)

# Override the company employee_id_sequence sequence next_by_id
# method to always return 00001
with patch(
"odoo.addons.base.models.ir_sequence.IrSequence.next_by_id",
return_value="00001",
):
with self.assertRaises(UserError):
self.employee_model.create({"name": "Second Employee"})

0 comments on commit fceb15b

Please sign in to comment.