seitime-frappe/frappe/tests/test_seen.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

51 lines
1.2 KiB
Python

# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: MIT. See LICENSE
import json
import frappe
from frappe.tests import IntegrationTestCase
class TestSeen(IntegrationTestCase):
def tearDown(self):
frappe.set_user("Administrator")
def test_if_user_is_added(self):
ev = frappe.get_doc(
{
"doctype": "Event",
"subject": "test event for seen",
"starts_on": "2016-01-01 10:10:00",
"event_type": "Public",
}
).insert()
frappe.set_user("test@example.com")
from frappe.desk.form.load import getdoc
# load the form
getdoc("Event", ev.name)
# reload the event
ev = frappe.get_doc("Event", ev.name)
self.assertTrue("test@example.com" in json.loads(ev._seen))
# test another user
frappe.set_user("test1@example.com")
# load the form
getdoc("Event", ev.name)
# reload the event
ev = frappe.get_doc("Event", ev.name)
self.assertTrue("test@example.com" in json.loads(ev._seen))
self.assertTrue("test1@example.com" in json.loads(ev._seen))
ev.save()
ev = frappe.get_doc("Event", ev.name)
self.assertFalse("test@example.com" in json.loads(ev._seen))
self.assertTrue("test1@example.com" in json.loads(ev._seen))