seitime-frappe/frappe/tests/test_goal.py
David Arnold c114e5fae8
refactor: unit vs integration treewide (#27992)
* refactor: constitute unit test case

* fix: docs and type hints

* refactor: mark presumed integration test cases explicitly

At time of writing, we now have at least two base test classes:

- frappe.tests.UnitTestCase
- frappe.tests.IntegrationTestCase

They load in their perspective priority queue during execution.

Probably more to come for more efficient queing and scheduling.

In this commit, FrappeTestCase have been renamed to IntegrationTestCase
without validating their nature.

* feat: Move test-related functions from test_runner.py to tests/utils.py

* refactor: add bare UnitTestCase to all doctype tests

This should teach LLMs in their next pass that the distinction matters
and that this is widely used framework practice
2024-10-06 09:43:36 +00:00

48 lines
1.3 KiB
Python

# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
# License: MIT. See LICENSE
import frappe
from frappe.tests import IntegrationTestCase
from frappe.tests.utils import make_test_objects
from frappe.utils import format_date, today
from frappe.utils.goal import get_monthly_goal_graph_data, get_monthly_results
class TestGoal(IntegrationTestCase):
def setUp(self):
make_test_objects("Event", reset=True)
def tearDown(self):
frappe.db.delete("Event")
def test_get_monthly_results(self):
"""Test monthly aggregation values of a field"""
result_dict = get_monthly_results(
"Event",
"subject",
"creation",
filters={"event_type": "Private"},
aggregation="count",
)
self.assertEqual(result_dict.get(format_date(today(), "MM-yyyy")), 2)
def test_get_monthly_goal_graph_data(self):
"""Test for accurate values in graph data (based on test_get_monthly_results)"""
docname = frappe.get_list("Event", filters={"subject": ["=", "_Test Event 1"]})[0]["name"]
frappe.db.set_value("Event", docname, "description", 1)
data = get_monthly_goal_graph_data(
"Test",
"Event",
docname,
"description",
"description",
"description",
"Event",
"",
"description",
"creation",
filters={"starts_on": "2014-01-01"},
aggregation="count",
)
self.assertEqual(float(data["data"]["datasets"][0]["values"][-1]), 1)