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