-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* 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> (cherry picked from commit b601131) Co-authored-by: Akhil Narang <me@akhilnarang.dev>
- Loading branch information
1 parent
0eaa472
commit 502b907
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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.get_doc(doctype=self.doctype_name, rating=-1) | ||
doc.insert() | ||
self.assertEqual(doc.rating, 0) | ||
|
||
def test_positive_rating(self): | ||
doc = frappe.get_doc(doctype=self.doctype_name, rating=5) | ||
doc.insert() | ||
self.assertEqual(doc.rating, 1) |