blob: 2c77c8d8aa8f4e5b0f46089a087727b7603fbab7 [file] [log] [blame]
Ankush Menat9b3f5d52021-03-03 12:38:52 +05301from __future__ import unicode_literals
2
3import unittest
Ankush Menat9b3f5d52021-03-03 12:38:52 +05304from unittest.mock import patch
Chillar Anand915b3432021-09-02 16:44:59 +05305
6import frappe
7
Ankush Menat9b3f5d52021-03-03 12:38:52 +05308from erpnext.regional.india.utils import validate_document_name
9
10
11class TestIndiaUtils(unittest.TestCase):
12 @patch("frappe.get_cached_value")
13 def test_validate_document_name(self, mock_get_cached):
14 mock_get_cached.return_value = "India" # mock country
15 posting_date = "2021-05-01"
16
Nabin Hait10c61372021-04-13 15:46:01 +053017 invalid_names = ["SI$1231", "012345678901234567", "SI 2020 05",
18 "SI.2020.0001", "PI2021 - 001"]
Ankush Menat9b3f5d52021-03-03 12:38:52 +053019 for name in invalid_names:
20 doc = frappe._dict(name=name, posting_date=posting_date)
21 self.assertRaises(frappe.ValidationError, validate_document_name, doc)
22
Nabin Hait10c61372021-04-13 15:46:01 +053023 valid_names = ["012345678901236", "SI/2020/0001", "SI/2020-0001",
24 "2020-PI-0001", "PI2020-0001"]
Ankush Menat9b3f5d52021-03-03 12:38:52 +053025 for name in valid_names:
26 doc = frappe._dict(name=name, posting_date=posting_date)
27 try:
28 validate_document_name(doc)
29 except frappe.ValidationError:
30 self.fail("Valid name {} throwing error".format(name))
31
32 @patch("frappe.get_cached_value")
33 def test_validate_document_name_not_india(self, mock_get_cached):
34 mock_get_cached.return_value = "Not India"
35 doc = frappe._dict(name="SI$123", posting_date="2021-05-01")
36
37 try:
38 validate_document_name(doc)
39 except frappe.ValidationError:
40 self.fail("Regional validation related to India are being applied to other countries")