def test_send_success_message(self):
     callback = JiraRegistry.get('write_success_comment')
     issue = Issue({}, None)
     issue.id = 'JIRA-42'
     callback(self.jira_plugin, issue, self, "a message")
     self.jira_plugin.jira_client.add_comment.assert_called_once_with(issue, mock.ANY)
     self.assertEqual(0, len(self.jira_plugin.regressions))
Exemplo n.º 2
0
def register_transition(registration_name, jira_transition,
                        transition_message_format):
    """
    register a transition you want to apply on test run.
    Example, To send back a ticket to development you can probably use

    .. sourcecode:: python

        register_transition('write_failure_and_back_to_dev', 'Set as To Do', 'A failure was found by {test}:'
                                                                             'details: {message}')

    this will register a new function with `write_failure_and_back_to_dev` as name. This function will apply the \
    transition ``Set as To Do`` when called. You just need to add ``failed,In QA,write_failure_and_back_to_dev`` \
    in your unittest.cfg file.

    :param registration_name: the callback name as used in the configuration file.
    :param jira_transition: The transition to apply
    :param transition_message_format: the transition message format. As of 1.0 we use ``str.format`` syntax and
    accepted keys are ``test`` and ``message``
    :return: the registered callback
    """
    return JiraRegistry.register(
        registration_name,
        True,
        jira_transition=jira_transition,
        message_format=transition_message_format)(apply_jira_transition)
    def test_try_to_add_existing(self):
        def add():
            def new_do_nothing(*_):
                pass

            return JiraRegistry.register(self.id(), False)(new_do_nothing)
        self.assertRaises(ValueError, add)
        self.assertEqual(self.base_function, JiraRegistry.get(self.id()))
 def test_warn_regression(self):
     callback = JiraRegistry.get('warn_regression')
     issue = Issue({}, None)
     issue.id = 'JIRA-42'
     callback(self.jira_plugin, issue, self, "a message")
     self.jira_plugin.jira_client.add_comment.assert_called_once_with(issue, mock.ANY)
     self.assertEqual(1, len(self.jira_plugin.regressions))
     self.assertEqual(self.jira_plugin.regressions[0].issue_id, issue.id)
    def test_override_existing(self):
        def add():
            def new_do_nothing(*_):
                pass

            return JiraRegistry.register(self.id(), True)(new_do_nothing)

        callback = add()
        self.assertEqual(callback, JiraRegistry.get(self.id()))
 def test_apply_jira_transition(self):
     register_transition('write_failure_and_back_in_dev', 'Set as To Do', 'test={test} message={message}')
     callback = JiraRegistry.get('write_failure_and_back_in_dev')
     issue = Issue({}, None)
     issue.id = 'JIRA-42'
     callback(self.jira_plugin, issue, self, "a message")
     self.jira_plugin.jira_client.add_comment.assert_called_once_with(issue,
                                                                      'test={test} message={message}'.format(
                                                                          message='a message',
                                                                          test=self
                                                                      ))
     self.jira_plugin.jira_client.find_transitionid_by_name\
         .assert_called_once_with(issue, 'Set as To Do')
     self.jira_plugin.jira_client.transition_issue\
         .assert_called_once_with(issue, 1)
     self.assertEqual(0, len(self.jira_plugin.regressions))
        def add():
            def new_do_nothing(*_):
                pass

            return JiraRegistry.register(self.id(), True)(new_do_nothing)
    def setUp(self):

        JiraRegistry.register(self.id(), False)(lambda *args: args)
        self.base_function = JiraRegistry.get(self.id())
Exemplo n.º 9
0
    :param jira_issue: the jira issue object
    :param test: the test case
    :param message: the success message
    :param message_format: the message format. As of 1.0 we use ``str.format`` syntax and accepted keys are ``test``
    and ``message``
    """
    if not jira_plugin.connected:
        return
    jira_plugin.jira_client.add_comment(
        jira_issue, message_format.format(test=test, message=message))
    jira_plugin.logger.info("Comment sent to %(jira_issue_id)s for %(test)s",
                            extra=dict(jira_issue_id=jira_issue.id, test=test))


JiraRegistry.register('write_success_comment',
                      False,
                      message_format="{test} has successed.")(add_comment)


def apply_jira_transition(jira_plugin, jira_issue, test, message, *,
                          jira_transition, message_format):
    """
    apply a transition in jira workflow

    :param jira_issue: the jira issue object
    :type jira_issue: jira.resources.Issue
    :param test: the testcase object
    :param message: the message to send to jira
    :param jira_transition: The transition to apply
    :param message_format: the transition message format. As of 1.0 we use ``str.format`` syntax and accepted keys are
    ``test`` and ``message``. To bypass "transition message submission" give ``None``