2021-03-03 07:08:52 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
from unittest.mock import patch
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2021-03-03 07:08:52 +00:00
|
|
|
import frappe
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2021-03-03 07:08:52 +00:00
|
|
|
from erpnext.regional.india.utils import validate_document_name
|
|
|
|
|
|
|
|
|
|
|
|
class TestIndiaUtils(unittest.TestCase):
|
|
|
|
@patch("frappe.get_cached_value")
|
|
|
|
def test_validate_document_name(self, mock_get_cached):
|
|
|
|
mock_get_cached.return_value = "India" # mock country
|
|
|
|
posting_date = "2021-05-01"
|
|
|
|
|
2021-04-13 10:16:01 +00:00
|
|
|
invalid_names = ["SI$1231", "012345678901234567", "SI 2020 05",
|
|
|
|
"SI.2020.0001", "PI2021 - 001"]
|
2021-03-03 07:08:52 +00:00
|
|
|
for name in invalid_names:
|
|
|
|
doc = frappe._dict(name=name, posting_date=posting_date)
|
|
|
|
self.assertRaises(frappe.ValidationError, validate_document_name, doc)
|
|
|
|
|
2021-04-13 10:16:01 +00:00
|
|
|
valid_names = ["012345678901236", "SI/2020/0001", "SI/2020-0001",
|
|
|
|
"2020-PI-0001", "PI2020-0001"]
|
2021-03-03 07:08:52 +00:00
|
|
|
for name in valid_names:
|
|
|
|
doc = frappe._dict(name=name, posting_date=posting_date)
|
|
|
|
try:
|
|
|
|
validate_document_name(doc)
|
|
|
|
except frappe.ValidationError:
|
|
|
|
self.fail("Valid name {} throwing error".format(name))
|
|
|
|
|
|
|
|
@patch("frappe.get_cached_value")
|
|
|
|
def test_validate_document_name_not_india(self, mock_get_cached):
|
|
|
|
mock_get_cached.return_value = "Not India"
|
|
|
|
doc = frappe._dict(name="SI$123", posting_date="2021-05-01")
|
|
|
|
|
|
|
|
try:
|
|
|
|
validate_document_name(doc)
|
|
|
|
except frappe.ValidationError:
|
|
|
|
self.fail("Regional validation related to India are being applied to other countries")
|