brotherton-erpnext/erpnext/regional/india/test_utils.py
Chillar Anand 915b34391c
chore: Clean up imports (#27302)
* chore: Added isort to pre-commit config

* chore: Sort imports with isort

* chore: Clean up imports with pycln

* chore: Sort imports with isort

* chore: Fix import issues

* chore: Clean up sider issues

* chore: Remove import errors from flake8 ignore list

* chore: Clean up lint issues
2021-09-02 16:44:59 +05:30

41 lines
1.3 KiB
Python

from __future__ import unicode_literals
import unittest
from unittest.mock import patch
import frappe
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"
invalid_names = ["SI$1231", "012345678901234567", "SI 2020 05",
"SI.2020.0001", "PI2021 - 001"]
for name in invalid_names:
doc = frappe._dict(name=name, posting_date=posting_date)
self.assertRaises(frappe.ValidationError, validate_document_name, doc)
valid_names = ["012345678901236", "SI/2020/0001", "SI/2020-0001",
"2020-PI-0001", "PI2020-0001"]
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")