blob: 61a0e97fe3eac99b1ac47e33cf254684fa85f1d7 [file] [log] [blame]
Ankush Menat9b3f5d52021-03-03 12:38:52 +05301
2import unittest
Ankush Menat9b3f5d52021-03-03 12:38:52 +05303from unittest.mock import patch
Chillar Anand915b3432021-09-02 16:44:59 +05304
5import frappe
6
Ankush Menat9b3f5d52021-03-03 12:38:52 +05307from erpnext.regional.india.utils import validate_document_name
8
9
10class 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 Hait10c61372021-04-13 15:46:01 +053016 invalid_names = ["SI$1231", "012345678901234567", "SI 2020 05",
17 "SI.2020.0001", "PI2021 - 001"]
Ankush Menat9b3f5d52021-03-03 12:38:52 +053018 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 Hait10c61372021-04-13 15:46:01 +053022 valid_names = ["012345678901236", "SI/2020/0001", "SI/2020-0001",
23 "2020-PI-0001", "PI2020-0001"]
Ankush Menat9b3f5d52021-03-03 12:38:52 +053024 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")