feat: doctype collection level APIs - meta, count
This commit is contained in:
parent
cfd3fb9341
commit
47538f7601
3 changed files with 32 additions and 2 deletions
|
|
@ -155,6 +155,14 @@ def run_doc_method(method: str, document: dict[str, Any] | str, kwargs=None):
|
|||
return response
|
||||
|
||||
|
||||
def count(doctype: str) -> int:
|
||||
from frappe.desk.reportview import get_count
|
||||
|
||||
# TODO: Rewrite
|
||||
frappe.form_dict.doctype = doctype
|
||||
return get_count()
|
||||
|
||||
|
||||
url_rules = [
|
||||
Rule("/method/login", endpoint=login),
|
||||
Rule("/method/logout", endpoint=logout),
|
||||
|
|
@ -176,4 +184,6 @@ url_rules = [
|
|||
methods=["GET", "POST"],
|
||||
endpoint=execute_doc_method,
|
||||
),
|
||||
Rule("/doctype/<doctype>/meta", methods=["GET"], endpoint=frappe.get_meta),
|
||||
Rule("/doctype/<doctype>/count", methods=["GET"], endpoint=count),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ def get_list():
|
|||
|
||||
@frappe.whitelist()
|
||||
@frappe.read_only()
|
||||
def get_count():
|
||||
def get_count() -> int:
|
||||
args = get_form_params()
|
||||
|
||||
if is_virtual_doctype(args.doctype):
|
||||
|
|
|
|||
|
|
@ -112,6 +112,9 @@ class FrappeAPITestCase(FrappeTestCase):
|
|||
def method_path(self, *method):
|
||||
return self.get_path("method", *method)
|
||||
|
||||
def doctype_path(self, *method):
|
||||
return self.get_path("doctype", *method)
|
||||
|
||||
def get_path(self, *parts):
|
||||
return urljoin(self.site_url, "/".join(("api", self.version, *parts)))
|
||||
|
||||
|
|
@ -316,7 +319,7 @@ class TestMethodAPIV1(FrappeAPITestCase):
|
|||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
|
||||
class TestResourceAPIV2(TestResourceAPI):
|
||||
class TestDocumentAPIV2(TestResourceAPI):
|
||||
version = "v2"
|
||||
|
||||
def setUp(self) -> None:
|
||||
|
|
@ -421,6 +424,23 @@ class TestMethodAPIV2(FrappeAPITestCase):
|
|||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
class TestDocTypeAPIV2(FrappeAPITestCase):
|
||||
version = "v2"
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.post(self.method_path("login"), {"sid": self.sid})
|
||||
return super().setUp()
|
||||
|
||||
def test_meta(self):
|
||||
response = self.get(self.doctype_path("ToDo", "meta"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json["data"]["name"], "ToDo")
|
||||
|
||||
def test_count(self):
|
||||
response = self.get(self.doctype_path("ToDo", "count"))
|
||||
self.assertIsInstance(response.json["data"], int)
|
||||
|
||||
|
||||
class TestReadOnlyMode(FrappeAPITestCase):
|
||||
"""During migration if read only mode can be enabled.
|
||||
Test if reads work well and writes are blocked"""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue