Ankush Menat | 9b3f5d5 | 2021-03-03 12:38:52 +0530 | [diff] [blame] | 1 | import unittest |
Ankush Menat | 9b3f5d5 | 2021-03-03 12:38:52 +0530 | [diff] [blame] | 2 | from unittest.mock import patch |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 3 | |
| 4 | import frappe |
| 5 | |
Ankush Menat | 9b3f5d5 | 2021-03-03 12:38:52 +0530 | [diff] [blame] | 6 | from erpnext.regional.india.utils import validate_document_name |
| 7 | |
| 8 | |
| 9 | class TestIndiaUtils(unittest.TestCase): |
| 10 | @patch("frappe.get_cached_value") |
| 11 | def test_validate_document_name(self, mock_get_cached): |
| 12 | mock_get_cached.return_value = "India" # mock country |
| 13 | posting_date = "2021-05-01" |
| 14 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 15 | invalid_names = ["SI$1231", "012345678901234567", "SI 2020 05", "SI.2020.0001", "PI2021 - 001"] |
Ankush Menat | 9b3f5d5 | 2021-03-03 12:38:52 +0530 | [diff] [blame] | 16 | for name in invalid_names: |
| 17 | doc = frappe._dict(name=name, posting_date=posting_date) |
| 18 | self.assertRaises(frappe.ValidationError, validate_document_name, doc) |
| 19 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 20 | valid_names = ["012345678901236", "SI/2020/0001", "SI/2020-0001", "2020-PI-0001", "PI2020-0001"] |
Ankush Menat | 9b3f5d5 | 2021-03-03 12:38:52 +0530 | [diff] [blame] | 21 | for name in valid_names: |
| 22 | doc = frappe._dict(name=name, posting_date=posting_date) |
| 23 | try: |
| 24 | validate_document_name(doc) |
| 25 | except frappe.ValidationError: |
| 26 | self.fail("Valid name {} throwing error".format(name)) |
| 27 | |
| 28 | @patch("frappe.get_cached_value") |
| 29 | def test_validate_document_name_not_india(self, mock_get_cached): |
| 30 | mock_get_cached.return_value = "Not India" |
| 31 | doc = frappe._dict(name="SI$123", posting_date="2021-05-01") |
| 32 | |
| 33 | try: |
| 34 | validate_document_name(doc) |
| 35 | except frappe.ValidationError: |
| 36 | self.fail("Regional validation related to India are being applied to other countries") |