Source

trac.plugins.traccron / tests / test_unreachable_milestone_task.py

# -*- coding: utf-8 -*-
import logging
from datetime import datetime, timedelta

import pytest
from utils import create_milestone_ticket
from utils import has_log_message

from trac.util.datefmt import utc


def pytest_funcarg__unreachable_milestone_task(request, component):
    unreachable_milestone_task = component['unreachable_milestone_task']
    return unreachable_milestone_task


def test_unreachable_milestone_task_getId(unreachable_milestone_task):
    from traccron.core import CronConfig
    task = unreachable_milestone_task
    assert CronConfig.UNREACHABLE_MILESTONE_TASK_BASEKEY == task.getId()


def test_unreachable_milestone_task_wake_up(unreachable_milestone_task,
                                            caplog):
    env = unreachable_milestone_task.env
    caplog.setLevel(logging.DEBUG, logger=env.log.name)

    # TODO: should be more simple
    # create tickets
    duedate = datetime.now(utc)
    duedate_plus_5days = duedate + timedelta(days=5)
    create_milestone_ticket(env, 'ms1', duedate, 'owner1', 'repo1')
    create_milestone_ticket(env, 'ms1', duedate, 'owner1', 'repo1'),
    create_milestone_ticket(env, 'ms1', duedate, 'owner2', 'repo2'),
    create_milestone_ticket(env, 'ms2', duedate_plus_5days, 'owner1', 'repo1')
    create_milestone_ticket(env, 'ms3', duedate, 'owner1', 'repo1')

    unreachable_milestone_task.wake_up()
    expected_messages = [
        'applying config',
        'stop existing ticker',
        'ticker is disabled',
        'action controllers for ticket workflow',
        "Creating new milestone 'ms1'",
        "Creating new milestone 'ms2'",
        "Creating new milestone 'ms3'",
        'warning ticket 1 will probably miss its milestone ms1',
        'warning ticket 2 will probably miss its milestone ms1',
        'warning ticket 3 will probably miss its milestone ms1',
        'warning ticket 5 will probably miss its milestone ms3',
        'notify unreachable milestone: ms3, UnreachableMilestoneNotification',
        'notify unreachable milestone: ms1, UnreachableMilestoneNotification',
        'notify opened ticket: owner1, ms3, OwnerOpenedTicketNotification',
        'notify opened ticket: owner1, ms1, OwnerOpenedTicketNotification',
        'notify opened ticket: owner2, ms1, OwnerOpenedTicketNotification',
        'notify opened ticket: repo1, ms3, ReporterOpenedTicketNotification',
        'notify opened ticket: repo1, ms1, ReporterOpenedTicketNotification',
        'notify opened ticket: repo2, ms1, ReporterOpenedTicketNotification',
    ]
    assert has_log_message(caplog, expected_messages)
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.