Commits

Tetsuya Morimoto committed 4600c0d

fixed to be able to run tests both 0.12 and 1.0 by configuring its logger name explicitly

Comments (0)

Files changed (6)

tests/conftest.py

 
 def make_trac_environment_with_plugin():
     env = EnvironmentStub(enable=['traccron.*'])
+
+    # replace default logger name with own testing name since
+    # the log handler settings is defferent from trac-0.12 and 1.0
+    import logging
+    env.log = logging.getLogger('traccron-test')
+    env.log.addHandler(env._log_handler)
+
     component = {
         'core': CronCore(env),
         'memory_history_store': MemoryHistoryStore(env),

tests/test_core.py

         expected_messages = [
             'applying config',
             'ticker is enabled',
+            'ticker is disabled',
             'check existing task',
             'check task:',
             'looking for schedule of type:',
     assert _isinstances(listener_list, listener_classes)
 
 
-def test_check_task(env, core, caplog):
-    caplog.setLevel(logging.DEBUG, logger=env.log.name)
+def test_check_task(core, caplog):
+    caplog.setLevel(logging.DEBUG, logger=core.env.log.name)
     core.check_task()
     expected_messages = [
+        'applying config',
+        'stop existing ticker',
+        'ticker is disabled',
         'check existing task',
         'check task:',
         'nothing to do:',
     assert has_log_message(caplog, expected_messages)
 
 
-def test_run_task(env, core, component, caplog):
-    caplog.setLevel(logging.DEBUG, logger=env.log.name)
+def test_run_task(core, component, caplog):
+    caplog.setLevel(logging.DEBUG, logger=core.env.log.name)
     core.runTask(component['heart_beat_task'])
     expected_messages = [
+        'applying config',
+        'stop existing ticker',
+        'ticker is disabled',
         'executing task: heart_beat',
         'Heart beat: boom boom !!!',
         'task execution result is SUCCESS',

tests/test_heart_beat_task.py

 def test_heart_beat_task_wake_up(heart_beat_task, caplog):
     caplog.setLevel(logging.DEBUG, logger=heart_beat_task.env.log.name)
     heart_beat_task.wake_up()
-    expected_messages = ['Heart beat: boom boom !!!']
+    expected_messages = [
+        'applying config',
+        'stop existing ticker',
+        'ticker is disabled',
+        'Heart beat: boom boom !!!',
+    ]
     assert has_log_message(caplog, expected_messages)
 
 
 def test_heart_beat_task_wake_up_with_args(heart_beat_task, caplog, args):
     caplog.setLevel(logging.DEBUG, logger=heart_beat_task.env.log.name)
     heart_beat_task.wake_up(*args)
-    expected_messages = ['Heart beat: ']
+    expected_messages = [
+        'applying config',
+        'stop existing ticker',
+        'ticker is disabled',
+        'Heart beat: ',
+    ]
     assert has_log_message(caplog, expected_messages)

tests/test_sleeping_ticket_reminder_task.py

 
     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',
     o1 = create_orphaned_ticket(env, when=when)
 
     sleeping_ticket_reminder_task.wake_up(*args)
-    expected_messages = ['action controllers for ticket workflow']
+    expected_messages = [
+        'applying config',
+        'stop existing ticker',
+        'ticker is disabled',
+        'action controllers for ticket workflow',
+    ]
     if args[0] <= ticket_subtract_days:
         expected_messages.extend([
             'warning sleeping ticket',

tests/test_ticker.py

         assert not ticker.timer.isAlive()
 
 
-def test_create_new_timer(ticker):
+def test_ticker_create_new_timer(ticker):
     try:
         assert ticker.timer.isAlive()
         prev_timer_id = id(ticker.timer)
         ticker.cancel(wait=True)
 
 
-def test_wake_up(ticker, caplog):
+def test_ticker_wake_up(ticker, caplog):
     caplog.setLevel(logging.DEBUG, logger=ticker.env.log.name)
     try:
         ticker.callback = lambda: ticker.env.log.debug('only logging')
         ticker.create_new_timer(wait=True, delay=1)
         time.sleep(2)
         expected_messages = [
+            'applying config',
+            'stop existing ticker',
+            'ticker is disabled',
             'create new ticker',
             'new ticker started',
             'ticker wake up',
             'last wake up time ',
             'next wake up time ',
             'current time ',
-            'adjusted wait 60 secondes',
+            'adjusted wait',
             'create new ticker',
             'new ticker started',
         ]
 
 from trac.ticket.model import Ticket
 
+_IGNORE_UNLOGGED_MESSAGES = [
+    'stop existing ticker',
+]
+
 
 def has_log_message(caplog, expected_messages, strict=True):
     log_status = dict((msg, False) for msg in expected_messages)
 
     if strict:
         for msg, is_logged in log_status.items():
+            if msg in _IGNORE_UNLOGGED_MESSAGES:
+                continue
             assert is_logged, 'unlogged message: "%s"' % msg
     return True
 
     db = env.get_db_cnx()
     cursor = db.cursor()
     cursor.execute("update ticket set status='new' where id=%s", (t.id,))
+    db.commit()
     return t
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.