fix: delete event after deleting the live class

This commit is contained in:
Jannat Patel
2026-03-04 20:35:51 +05:30
parent 292b48fbac
commit 701814060d
2 changed files with 3 additions and 88 deletions

View File

@@ -30,9 +30,9 @@ class LMSLiveClass(Document):
self._update_linked_event()
def on_trash(self):
if self.event and frappe.db.exists("Event", self.event):
frappe.delete_doc("Event", self.event, ignore_permissions=True)
def after_delete(self):
if self.event:
frappe.delete_doc("Event", self.event, force=True)
def get_participants(self):
participants = frappe.get_all("LMS Batch Enrollment", {"batch": self.batch_name}, pluck="member")

View File

@@ -129,13 +129,6 @@ class TestLMSLiveClass(BaseTestUtils):
self.assertEqual(event.sync_with_google_calendar, 1)
self.assertEqual(event.add_video_conferencing, 1)
self.assertEqual(event.google_calendar, self.google_calendar.name)
def test_google_meet_live_class_event_has_correct_times(self):
"""The linked Event should have correct start and end times."""
live_class = self._create_live_class()
live_class.reload()
event = frappe.get_doc("Event", live_class.event)
self.assertIn("10:00", str(event.starts_on))
self.assertIn("11:00", str(event.ends_on))
@@ -183,31 +176,6 @@ class TestLMSLiveClass(BaseTestUtils):
self.google_meet_settings.google_calendar = old_calendar
self.google_meet_settings.save()
def test_zoom_live_class_not_affected(self):
"""Creating a Zoom-style live class should still work (regression test)."""
live_class = frappe.get_doc(
{
"doctype": "LMS Live Class",
"title": f"Zoom Class {frappe.generate_hash(length=6)}",
"host": "Administrator",
"date": add_days(nowdate(), 1),
"time": "14:00:00",
"duration": 45,
"timezone": "Asia/Kolkata",
"batch_name": self.batch.name,
"conferencing_provider": "Zoom",
"join_url": "https://zoom.us/j/123456",
"start_url": "https://zoom.us/s/123456",
}
)
live_class.insert(ignore_permissions=True)
self.cleanup_items.append(("LMS Live Class", live_class.name))
self.assertTrue(frappe.db.exists("LMS Live Class", live_class.name))
self.assertEqual(live_class.join_url, "https://zoom.us/j/123456")
# --- T10: Unit tests for event update and cancellation sync ---
def test_update_live_class_date_updates_event(self):
"""Rescheduling a live class should update the linked Event."""
live_class = self._create_live_class()
@@ -270,40 +238,8 @@ class TestLMSLiveClass(BaseTestUtils):
(t, n) for t, n in self.cleanup_items if not (t == "LMS Live Class" and n == live_class.name)
]
frappe.delete_doc("LMS Live Class", live_class.name, force=True)
self.assertFalse(frappe.db.exists("Event", event_name))
def test_delete_zoom_live_class_with_event(self):
"""Deleting a Zoom live class with a linked event should also delete the event (regression)."""
live_class = self._create_live_class(provider="Zoom")
# Zoom classes created via direct insert won't have an event from calendar flow,
# but if one is set manually, on_trash should clean it up
event = frappe.get_doc(
{
"doctype": "Event",
"subject": "Test Zoom Event",
"event_type": "Public",
"starts_on": f"{add_days(nowdate(), 1)} 14:00:00",
"ends_on": f"{add_days(nowdate(), 1)} 15:00:00",
}
)
event.insert(ignore_permissions=True)
self.cleanup_items.append(("Event", event.name))
frappe.db.set_value("LMS Live Class", live_class.name, "event", event.name)
live_class.reload()
self.cleanup_items = [
(t, n) for t, n in self.cleanup_items if not (t == "LMS Live Class" and n == live_class.name)
]
# Remove event from cleanup too since on_trash will delete it
self.cleanup_items = [(t, n) for t, n in self.cleanup_items if not (t == "Event" and n == event.name)]
frappe.delete_doc("LMS Live Class", live_class.name, force=True)
self.assertFalse(frappe.db.exists("Event", event.name))
# --- T11: Integration tests for end-to-end workflow ---
def test_batch_validation_google_meet_without_account(self):
"""Saving a batch with Google Meet provider but no account should fail."""
self.batch.conferencing_provider = "Google Meet"
@@ -311,7 +247,6 @@ class TestLMSLiveClass(BaseTestUtils):
with self.assertRaises(frappe.exceptions.ValidationError):
self.batch.save()
# Reset
self.batch.reload()
def test_batch_validation_google_meet_with_valid_account(self):
@@ -324,7 +259,6 @@ class TestLMSLiveClass(BaseTestUtils):
self.assertEqual(self.batch.conferencing_provider, "Google Meet")
self.assertEqual(self.batch.google_meet_account, self.google_meet_settings.name)
# Reset
self.batch.conferencing_provider = ""
self.batch.google_meet_account = ""
self.batch.save()
@@ -335,23 +269,4 @@ class TestLMSLiveClass(BaseTestUtils):
self.batch.zoom_account = ""
with self.assertRaises(frappe.exceptions.ValidationError):
self.batch.save()
# Reset
self.batch.reload()
def test_update_attendance_skips_google_meet(self):
"""The Zoom attendance scheduler should skip Google Meet classes."""
live_class = self._create_live_class()
live_class.reload()
# The update_attendance function uses conferencing_provider != "Google Meet"
# to filter out Google Meet classes from Zoom attendance processing.
# Verify a Google Meet class is excluded by that filter.
past_classes = frappe.get_all(
"LMS Live Class",
{
"conferencing_provider": ["!=", "Google Meet"],
},
pluck="name",
)
self.assertNotIn(live_class.name, past_classes)