blob: a16f56c704aef3df65b90e54ff23f99c03141b73 [file] [log] [blame]
Ankush Menat9b3f5d52021-03-03 12:38:52 +05301from __future__ import unicode_literals
2
3import unittest
4import frappe
5from unittest.mock import patch
6from erpnext.regional.india.utils import validate_document_name
7
8
9class 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
Nabin Hait10c61372021-04-13 15:46:01 +053015 invalid_names = ["SI$1231", "012345678901234567", "SI 2020 05",
16 "SI.2020.0001", "PI2021 - 001"]
Ankush Menat9b3f5d52021-03-03 12:38:52 +053017 for name in invalid_names:
18 doc = frappe._dict(name=name, posting_date=posting_date)
19 self.assertRaises(frappe.ValidationError, validate_document_name, doc)
20
Nabin Hait10c61372021-04-13 15:46:01 +053021 valid_names = ["012345678901236", "SI/2020/0001", "SI/2020-0001",
22 "2020-PI-0001", "PI2020-0001"]
Ankush Menat9b3f5d52021-03-03 12:38:52 +053023 for name in valid_names:
24 doc = frappe._dict(name=name, posting_date=posting_date)
25 try:
26 validate_document_name(doc)
27 except frappe.ValidationError:
28 self.fail("Valid name {} throwing error".format(name))
29
30 @patch("frappe.get_cached_value")
31 def test_validate_document_name_not_india(self, mock_get_cached):
32 mock_get_cached.return_value = "Not India"
33 doc = frappe._dict(name="SI$123", posting_date="2021-05-01")
34
35 try:
36 validate_document_name(doc)
37 except frappe.ValidationError:
38 self.fail("Regional validation related to India are being applied to other countries")