* feat: don't allow setting an invalid rating Convert anything <0 to 0, and anything >1 to 1 Signed-off-by: Akhil Narang <me@akhilnarang.dev> * chore: add in tests for rating Signed-off-by: Akhil Narang <me@akhilnarang.dev> --------- Signed-off-by: Akhil Narang <me@akhilnarang.dev>
29 lines
677 B
Python
29 lines
677 B
Python
import frappe
|
|
from frappe.core.doctype.doctype.test_doctype import new_doctype
|
|
from frappe.tests.utils import FrappeTestCase
|
|
|
|
|
|
class TestRating(FrappeTestCase):
|
|
def setUp(self):
|
|
doc = new_doctype(
|
|
fields=[
|
|
{
|
|
"fieldname": "rating",
|
|
"fieldtype": "Rating",
|
|
"label": "rating",
|
|
"reqd": 1, # mandatory
|
|
},
|
|
],
|
|
)
|
|
doc.insert()
|
|
self.doctype_name = doc.name
|
|
|
|
def test_negative_rating(self):
|
|
doc = frappe.new_doc(doctype=self.doctype_name, rating=-1)
|
|
doc.insert()
|
|
self.assertEqual(doc.rating, 0)
|
|
|
|
def test_positive_rating(self):
|
|
doc = frappe.new_doc(doctype=self.doctype_name, rating=5)
|
|
doc.insert()
|
|
self.assertEqual(doc.rating, 1)
|