fix: test cases for web forms

This commit is contained in:
shadrak gurupnor 2021-09-14 21:00:40 +05:30
parent 5343b28ab5
commit 930dddc558
2 changed files with 19 additions and 3 deletions

View file

@ -104,7 +104,7 @@ def rate_limit(key: str=None, limit: Union[int, Callable] = 5, seconds: int= 24*
@wraps(fun)
def wrapper(*args, **kwargs):
# Do not apply rate limits if method is not opted to check
if methods != 'ALL' and frappe.request.method.upper() not in methods:
if methods != 'ALL' and frappe.request and frappe.request.method and frappe.request.method.upper() not in methods:
return frappe.call(fun, **frappe.form_dict or kwargs)
_limit = limit() if callable(limit) else limit

View file

@ -16,15 +16,26 @@ class TestWebForm(unittest.TestCase):
def tearDown(self):
frappe.conf.disable_website_cache = False
frappe.local.path = None
frappe.local.request_ip = None
frappe.form_dict.web_form = None
frappe.form_dict.data = None
frappe.form_dict.docname = None
def test_accept(self):
frappe.set_user("Administrator")
accept(web_form='manage-events', data=json.dumps({
doc = {
'doctype': 'Event',
'subject': '_Test Event Web Form',
'description': '_Test Event Description',
'starts_on': '2014-09-09'
}))
}
frappe.form_dict.web_form = "manage-events"
frappe.form_dict.data = json.dumps(doc)
frappe.local.request_ip = '127.0.0.1'
accept(web_form='manage-events', data=json.dumps(doc))
self.event_name = frappe.db.get_value("Event",
{"subject": "_Test Event Web Form"})
@ -32,6 +43,7 @@ class TestWebForm(unittest.TestCase):
def test_edit(self):
self.test_accept()
doc={
'doctype': 'Event',
'subject': '_Test Event Web Form',
@ -43,6 +55,10 @@ class TestWebForm(unittest.TestCase):
self.assertNotEqual(frappe.db.get_value("Event",
self.event_name, "description"), doc.get('description'))
frappe.form_dict.web_form = 'manage-events'
frappe.form_dict.docname = self.event_name
frappe.form_dict.data = json.dumps(doc)
accept(web_form='manage-events', docname=self.event_name, data=json.dumps(doc))
self.assertEqual(frappe.db.get_value("Event",