Files
encoach_backend_new_v2/odoo/addons/lunch/tests/test_alert.py
Yamen Ahmad 3e83d8d7d5 feat: add complete EnCoach backend — Odoo 19 + all addons
Includes:
- Odoo 19 framework (odoo/)
- 27 custom EnCoach addons (new_project/custom_addons/)
  - encoach_core, encoach_api, encoach_lms_api, encoach_adaptive_api
  - encoach_exam, encoach_taxonomy, encoach_adaptive, encoach_assignment
  - encoach_ai, encoach_ai_grading, encoach_ai_generation, encoach_ai_media
  - encoach_courseware, encoach_communication, encoach_subscription
  - encoach_notification, encoach_approval, encoach_branding
  - encoach_classroom, encoach_registration, encoach_stats
  - encoach_faq, encoach_ticket, encoach_training, encoach_resources
  - encoach_adaptive_ai, encoach_sis
- 21 OpenEduCat Enterprise modules (new_project/enterprise-19/)
- 14 OpenEduCat Community modules (new_project/openeducat_erp-19.0/)
- Configuration: odoo.conf, requirements.txt, scripts
- 200+ REST API endpoints with JWT authentication
- SRS and test documentation

Made-with: Cursor
2026-04-01 17:10:04 +04:00

61 lines
2.4 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
from datetime import datetime, timedelta
from odoo import fields
from odoo.tests import common
from odoo.addons.lunch.tests.common import TestsCommon
class TestAlarm(TestsCommon):
@common.users('cle-lunch-manager')
def test_cron_sync_create(self):
cron_ny = self.alert_ny.cron_id.sudo()
self.assertTrue(cron_ny.active)
self.assertEqual(cron_ny.name, "Lunch: alert chat notification (New York UTC-5)")
self.assertEqual(
[line for line in cron_ny.code.splitlines() if not line.lstrip().startswith("#")],
["env['lunch.alert'].browse([%i])._notify_chat()" % self.alert_ny.id])
self.assertEqual(cron_ny.nextcall, datetime(2021, 1, 29, 15, 0)) # New-york is UTC-5
tokyo_cron = self.alert_tokyo.cron_id.sudo()
self.assertEqual(tokyo_cron.nextcall, datetime(2021, 1, 29, 23, 0)) # Tokyo is UTC+9 but the cron is posponed
@common.users('cle-lunch-manager')
def test_cron_sync_active(self):
cron_ny = self.alert_ny.cron_id.sudo()
self.alert_ny.active = False
self.assertFalse(cron_ny.active)
self.alert_ny.active = True
self.assertTrue(cron_ny.active)
self.alert_ny.mode = 'alert'
self.assertFalse(cron_ny.active)
self.alert_ny.mode = 'chat'
self.assertTrue(cron_ny.active)
ctx_today = fields.Date.context_today(self.alert_ny, self.fakenow)
self.alert_ny.until = ctx_today - timedelta(days=1)
self.assertFalse(cron_ny.active)
self.alert_ny.until = ctx_today + timedelta(days=2)
self.assertTrue(cron_ny.active)
self.alert_ny.until = False
self.assertTrue(cron_ny.active)
@common.users('cle-lunch-manager')
def test_cron_sync_nextcall(self):
cron_ny = self.alert_ny.cron_id.sudo()
old_nextcall = cron_ny.nextcall
self.alert_ny.notification_time -= 5
self.assertEqual(cron_ny.nextcall, old_nextcall - timedelta(hours=5) + timedelta(days=1))
# Simulate cron execution
cron_ny.lastcall = old_nextcall - timedelta(hours=5)
cron_ny.nextcall += timedelta(days=1)
self.alert_ny.notification_time += 7
self.assertEqual(cron_ny.nextcall, old_nextcall + timedelta(days=1, hours=2))
self.alert_ny.notification_time -= 1
self.assertEqual(cron_ny.nextcall, old_nextcall + timedelta(days=1, hours=1))