Ejemplo n.º 1
0
 def test_messages_when_nothing_interesting_happening(self):
     jira = MockJira(issues=[
         {
             "id": "XXX-1",
             "summary": "My first Jira",
             "status": "Backlog"
         },
         {
             "id": "XXX-2",
             "summary": "My second Jira",
             "status": "Backlog"
         },
     ])
     slack = MockSlack()
     bot = JiraBot(jira,
                   slack,
                   "XXX",
                   "LABEL",
                   None,
                   "#channel",
                   wip_limit=3,
                   logger=self.logger,
                   supress_quotes=True)
     bot.send_periodic_update()
     self.assertEqual(len(slack.outgoing_messages), 2)
     self.assertEqual(":partyparrot:",
                      slack.outgoing_messages[1]["message"])
Ejemplo n.º 2
0
 def test_new_issues_in_backlog_notified_on_channel(self):
     jira = MockJira(issues=[{
         "id": "AAA-2",
         "summary": "I am new",
         "status": "Backlog",
         "created": u'2016-08-10T07:55:00.000+0100'
     }, {
         "id": "AAA-1",
         "summary": "I am not new",
         "status": "Backlog",
         "created": u'2016-08-08T14:50:36.000+0100'
     }])
     slack = MockSlack()
     bot = JiraBot(jira,
                   slack,
                   "AAA",
                   "LABEL",
                   None,
                   "#whatever",
                   logger=self.logger,
                   supress_quotes=True)
     bot.send_periodic_update()
     self.assertEqual(3, len(slack.outgoing_messages))
     self.assertEqual("There are no warnings. It's all good!",
                      slack.outgoing_messages[0]["message"])
     self.assertEqual(':partyparrot:',
                      slack.outgoing_messages[1]["message"])
     self.assertEqual(':memo: New issue AAA-2 added',
                      slack.outgoing_messages[2]["message"])
Ejemplo n.º 3
0
 def test_message_sent_if_too_many_issues_in_progress(self):
     jira = MockJira(issues=[
         {
             "id": "XXX-1",
             "summary": "My first Jira",
             "assignee": "Busy Bob",
             "status": "In Progress"
         },
         {
             "id": "XXX-2",
             "summary": "My second Jira",
             "assignee": "Busy Bob",
             "status": "In Progress"
         },
         {
             "id": "XXX-3",
             "summary": "My third Jira",
             "assignee": "Busy Bob",
             "status": "In Progress"
         },
         {
             "id": "XXX-4",
             "summary": "My fourth Jira",
             "assignee": "Busy Bob",
             "status": "In Progress"
         },
         {
             "id": "XXX-5",
             "summary": "My fifth Jira",
             "assignee": "Busy Bob",
             "status": "In Progress"
         },
         {
             "id": "XXX-6",
             "summary": "My sixth Jira",
             "assignee": "Lazy Susan",
             "status": "In Progress"
         },
     ])
     slack = MockSlack()
     bot = JiraBot(jira,
                   slack,
                   "XXX",
                   "LABEL",
                   None,
                   "#chan1",
                   3,
                   logger=self.logger,
                   supress_quotes=True)
     bot.send_periodic_update()
     self.assertEqual(len(slack.outgoing_messages), 1)
     self.assertEqual("#chan1", slack.outgoing_messages[0]["recipient"])
     self.assertEqual(
         ":warning: *Busy Bob* currently has 5 jira issues in progress. That's too many. Here's a list: XXX-1, XXX-2, XXX-3, XXX-4, XXX-5",
         slack.outgoing_messages[0]["message"])
Ejemplo n.º 4
0
 def test_attachment_added_for_single_jira_id(self):
     jira = MockJira(server="https://myjira.atlassian.net",
                     issues=[{
                         "id": "XXX-123",
                         "summary": "I am a Jira"
                     }])
     output = MessageToJiraAttachmentConverter(jira).apply(
         "The best Jira is XXX-123")
     self.assertEqual(1, len(output))
     self.assertEqual("https://myjira.atlassian.net/browse/XXX-123",
                      output[0]["title_link"])
     self.assertEqual("XXX-123: I am a Jira", output[0]["title"])
Ejemplo n.º 5
0
 def test_request_to_show_everything(self):
     jira = MockJira(issues=self.get_test_issue_set())
     slack = MockSlack()
     bot = JiraBot(jira,
                   slack,
                   "AAA",
                   "LABEL",
                   None,
                   "#things",
                   logger=self.logger,
                   supress_quotes=True)
     slack.add_incoming({u'text': u'<@BOTID> show warnings'})
     bot.process_messages()
     self.assertEqual(1, len(slack.outgoing_messages))
Ejemplo n.º 6
0
 def test_request_to_show_progress_chart(self):
     jira = MockJira().with_n_fake_issues(50)
     slack = MockSlack()
     bot = JiraBot(jira,
                   slack,
                   "XXX",
                   "LABEL",
                   "#channel_4",
                   3,
                   logger=self.logger,
                   supress_quotes=True)
     slack.add_incoming({u'text': u'<@BOTID> chart progress'})
     bot.process_messages()
     self.assertEqual(1, len(slack.uploaded_files))
     self.assertEqual(0, len(slack.outgoing_messages))
Ejemplo n.º 7
0
 def test_request_status_summary(self):
     jira = MockJira(issues=self.get_test_issue_set())
     slack = MockSlack()
     bot = JiraBot(jira,
                   slack,
                   "AAA",
                   "LABEL",
                   None,
                   "#things",
                   logger=self.logger,
                   supress_quotes=True)
     slack.add_incoming({u'text': u'<@BOTID> status summary'})
     bot.process_messages()
     self.assertEqual(1, len(slack.outgoing_messages))
     msg = slack.outgoing_messages[0]["message"].lower()
     self.assertTrue("backlog: *3*" in msg)
     self.assertTrue("to do: *1*" in msg)
     self.assertTrue("in progress: *2*" in msg)
Ejemplo n.º 8
0
 def test_unknown_command(self):
     jira = MockJira(issues=[])
     slack = MockSlack()
     bot = JiraBot(jira,
                   slack,
                   "AAA",
                   "LABEL",
                   None,
                   "#things",
                   logger=self.logger,
                   supress_quotes=True)
     slack.add_incoming({
         u'text': u'<@BOTID> herrings are obfuscation cheese',
         u'user': u'USER_ID'
     })
     bot.process_messages()
     self.assertEqual(1, len(slack.outgoing_messages))
     self.assertTrue("<@USER_ID>" in slack.outgoing_messages[0]["message"])
Ejemplo n.º 9
0
    def do_leaderboard(self, msg="leader board", issues=None):
        if not issues:
            issues = self.get_completed_issue_set()

        jira = MockJira(issues=issues)
        slack = MockSlack(name_lookup=self.get_name_lookup_for_leaderboard())
        bot = JiraBot(jira,
                      slack,
                      "XXX",
                      "LABEL",
                      None,
                      "#channel_name",
                      3,
                      logger=self.logger,
                      supress_quotes=True)
        slack.add_incoming({u'text': u'<@BOTID> {0}'.format(msg)})
        bot.process_messages()
        self.assertEqual(len(slack.outgoing_messages), 1)
        self.assertEqual("#channel_name",
                         slack.outgoing_messages[0]["recipient"])
        message = slack.outgoing_messages[0]["message"]
        return message
Ejemplo n.º 10
0
 def test_message_sent_if_issue_assigned_but_not_in_progress(self):
     jira = MockJira(issues=[
         {
             "id": "XXX-1",
             "summary": "My first Jira",
             "assignee": "Fred Bloggs",
             "status": "Backlog"
         },
         {
             "id": "XXX-2",
             "summary": "My second Jira",
             "assignee": "None",
             "status": "Backlog"
         },
         {
             "id": "XXX-3",
             "summary": "My third Jira",
             "assignee": "Fred Jones",
             "status": "In Progress"
         },
     ])
     slack = MockSlack()
     bot = JiraBot(jira,
                   slack,
                   "XXX",
                   "LABEL",
                   None,
                   "#channel_name",
                   3,
                   logger=self.logger,
                   supress_quotes=True)
     bot.send_periodic_update()
     self.assertEqual(len(slack.outgoing_messages), 1)
     self.assertEqual("#channel_name",
                      slack.outgoing_messages[0]["recipient"])
     self.assertEqual(
         ':warning: XXX-1 is assigned to *Fred Bloggs* but still in the Backlog state',
         slack.outgoing_messages[0]["message"])
Ejemplo n.º 11
0
 def test_message_sent_if_issue_in_progress_but_not_assigned(self):
     jira = MockJira(issues=[
         {
             "id": "XXX-1",
             "summary": "My first Jira",
             "assignee": "Cheesy Phil",
             "status": "In Progress"
         },
         {
             "id": "XXX-2",
             "summary": "My second Jira",
             "assignee": "None",
             "status": "In Progress"
         },
         {
             "id": "XXX-3",
             "summary": "My third Jira",
             "assignee": "Fred Jones",
             "status": "In Progress"
         },
     ])
     slack = MockSlack()
     bot = JiraBot(jira,
                   slack,
                   "XXX",
                   "LABEL",
                   None,
                   "#the_channel",
                   logger=self.logger,
                   supress_quotes=True)
     bot.send_periodic_update()
     self.assertEqual(1, len(slack.outgoing_messages))
     self.assertEqual("#the_channel",
                      slack.outgoing_messages[0]["recipient"])
     self.assertEqual(
         ":warning: XXX-2 is marked as In Progress but not assigned to anyone",
         slack.outgoing_messages[0]["message"])
Ejemplo n.º 12
0
 def test_name_lookups_for_mentions(self):
     jira = MockJira(issues=[{
         "id": "XXX-1",
         "summary": "My first Jira",
         "assignee": "Fred Bloggs",
         "status": "Backlog"
     }])
     slack = MockSlack(name_lookup={"Fred Bloggs": "BLOGGSID"})
     bot = JiraBot(jira,
                   slack,
                   "XXX",
                   "LABEL",
                   None,
                   "#channel_name",
                   3,
                   logger=self.logger,
                   supress_quotes=True)
     bot.send_periodic_update()
     self.assertEqual(len(slack.outgoing_messages), 1)
     self.assertEqual("#channel_name",
                      slack.outgoing_messages[0]["recipient"])
     self.assertEqual(
         ':warning: XXX-1 is assigned to <@BLOGGSID> but still in the Backlog state',
         slack.outgoing_messages[0]["message"])
Ejemplo n.º 13
0
 def test_new_issues_not_repeated_in_channel(self):
     jira = MockJira(issues=[{
         "id": "AAA-2",
         "summary": "I am new",
         "status": "Backlog",
         "created": u'2016-08-10T07:55:00.000+0100'
     }, {
         "id": "AAA-1",
         "summary": "I am not new",
         "status": "Backlog",
         "created": u'2016-08-08T14:50:36.000+0100'
     }])
     slack = MockSlack()
     bot = JiraBot(jira,
                   slack,
                   "AAA",
                   "LABEL",
                   None,
                   "#things",
                   logger=self.logger,
                   supress_quotes=True)
     bot.send_periodic_update()
     bot.send_periodic_update()
     self.assertEqual(3, len(slack.outgoing_messages))
Ejemplo n.º 14
0
 def test_no_attachments_added_for_string_with_no_jira_ids(self):
     attachments = MessageToJiraAttachmentConverter(
         jira=MockJira()).apply("This text doesn't contain any Jira IDs")
     self.assertEqual(0, len(attachments))