test: add missing tests

This commit is contained in:
Ankush Menat 2022-05-31 11:49:28 +05:30
parent b7a032e7e8
commit 7739da536d
2 changed files with 26 additions and 1 deletions

View file

@ -144,6 +144,7 @@ class DocumentNamingSettings(Document):
if self.prefix:
prefix = NamingSeries(self.prefix).get_prefix()
self.current_value = frappe.db.get_value("Series", prefix, "current", order_by="name")
return self.current_value
@frappe.whitelist()
def update_series_start(self):
@ -155,7 +156,7 @@ class DocumentNamingSettings(Document):
db_prefix = NamingSeries(self.prefix).get_prefix()
if frappe.db.get_value("Series", db_prefix, "name", order_by="name") is None:
series.insert(db_prefix, 0).columns(series.name, series.current).run()
frappe.db.sql("insert into `tabSeries` (`name`, `current`) values (%s, 0)", (db_prefix))
(
frappe.qb.update(series)

View file

@ -7,6 +7,7 @@ from frappe.core.doctype.document_naming_settings.document_naming_settings impor
)
from frappe.model.naming import get_default_naming_series
from frappe.tests.utils import FrappeTestCase
from frappe.utils import cint
class TestNamingSeries(FrappeTestCase):
@ -16,6 +17,11 @@ class TestNamingSeries(FrappeTestCase):
def tearDown(self):
frappe.db.rollback()
def get_valid_serieses(self):
VALID_SERIES = ["SINV-", "SI-.{field}.", "SI-#.###", ""]
exisiting_series = self.dns.get_transactions_and_prefixes()["prefixes"]
return VALID_SERIES + exisiting_series
def test_naming_preview(self):
self.dns.transaction_type = "Webhook"
@ -39,3 +45,21 @@ class TestNamingSeries(FrappeTestCase):
def test_default_naming_series(self):
self.assertIn("HOOK", get_default_naming_series("Webhook"))
self.assertIsNone(get_default_naming_series("DocType"))
def test_updates_naming_options(self):
self.dns.transaction_type = "Webhook"
test_series = "KOOHBEW.###"
self.dns.naming_series_options = self.dns.get_options() + "\n" + test_series
self.dns.update_series()
self.assertIn(test_series, frappe.get_meta("Webhook").get_naming_series_options())
def test_update_series_counter(self):
for series in self.get_valid_serieses():
if not series:
continue
self.dns.prefix = series
current_count = cint(self.dns.get_current())
new_count = self.dns.current_value = current_count + 1
self.dns.update_series_start()
self.assertEqual(self.dns.get_current(), new_count)