Commits

Tetsuya Morimoto  committed 9498bb1

refactored SleepingTicketReminderTask component tests

  • Participants
  • Parent commits cfaea4d

Comments (0)

Files changed (2)

File src/traccron/task.py

     """
     implements(ICronTask, ITemplateProvider)
 
+    delay_days = 3
+
     select_assigned_ticket = """
         SELECT t.id , t.owner
         FROM ticket t, ticket_change tc
         OrphanedTicketNotification(self.env).remind(dico, delay)
 
     def wake_up(self, *args):
-        delay = 3
+        delay = SleepingTicketReminderTask.delay_days
         if len(args) > 0:
             delay = int(args[0])
 

File tests/test_sleeping_ticket_reminder_task.py

     assert 'sleeping_ticket' == sleeping_ticket_reminder_task.getId()
 
 
+@pytest.mark.parametrize(('args', 'subtract_days'), [
+    ((), 5),
+    ((), 2),
+    ((2,), 5),
+    ((7, 'test'), 5),
+    ((7, 'test'), 10),
+])
 def test_sleeping_ticket_reminder_task_wake_up(sleeping_ticket_reminder_task,
-                                               caplog):
+                                               caplog, args, subtract_days):
+    from traccron.task import SleepingTicketReminderTask
     env = sleeping_ticket_reminder_task.env
     caplog.setLevel(logging.DEBUG, logger=env.log.name)
 
     # create tickets
-    when = datetime.now(utc) - timedelta(days=5)
-    t1 = create_new_tickets(env, 3, owner='sleeper1', when=when)
-    o1 = create_orphaned_ticket(env, when=when)
-
-    sleeping_ticket_reminder_task.wake_up()
-    expected_messages = [
-        'applying config',
-        'stop existing ticker',
-        'ticker is disabled',
-        'action controllers for ticket workflow',
-        'warning sleeping ticket',
-        'warning ticket',
-    ]
-    assert has_log_message(caplog, expected_messages)
-
-
-@pytest.mark.parametrize('args', [
-    (2,),
-    (7, 'test'),
-])
-def test_sleeping_ticket_reminder_task_wake_up_args(
-        sleeping_ticket_reminder_task, caplog, args):
-    env = sleeping_ticket_reminder_task.env
-    caplog.setLevel(logging.DEBUG, logger=env.log.name)
-
-    # create tickets
-    ticket_subtract_days = 5
-    when = datetime.now(utc) - timedelta(days=ticket_subtract_days)
+    when = datetime.now(utc) - timedelta(days=subtract_days)
     t1 = create_new_tickets(env, 3, owner='sleeper1', when=when)
     o1 = create_orphaned_ticket(env, when=when)
 
         'ticker is disabled',
         'action controllers for ticket workflow',
     ]
-    if args[0] <= ticket_subtract_days:
+
+    if not args:
+        args = (SleepingTicketReminderTask.delay_days,)
+
+    if args[0] <= subtract_days:
         expected_messages.extend([
             'warning sleeping ticket',
             'warning ticket',