Exemplo n.º 1
0
    def test_expected_handled(self):
        bot = common.make_bot(simple_config=True)

        m = common.make_message(text="brain dump bob", to_me=True)
        self.assertTrue(brain.DumpHandler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="brain no list", to_me=True)
        self.assertFalse(brain.DumpHandler.handles(m, c.TARGETED, bot.config))
Exemplo n.º 2
0
    def test_expected_handled(self):
        bot = common.make_bot()

        m = common.make_message(text="help me", to_me=True)
        self.assertTrue(help_me.Handler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="help anyone", to_me=True)
        self.assertEqual(help_me.Handler.handles(m, c.TARGETED, bot.config),
                         None)
Exemplo n.º 3
0
    def test_expected_handled(self):
        bot = common.make_bot()

        m = common.make_message(text="version", to_me=True)
        self.assertTrue(version.Handler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="vrsn", to_me=True)
        self.assertEqual(version.Handler.handles(m, c.TARGETED, bot.config),
                         None)
Exemplo n.º 4
0
    def test_expected_handled(self):
        bot = common.make_bot()

        m = common.make_message(text="shutdown", to_me=True)
        self.assertTrue(shutdown.Handler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="please, kill yourself", to_me=True)
        self.assertEqual(shutdown.Handler.handles(m, c.TARGETED, bot.config),
                         None)
Exemplo n.º 5
0
    def test_expected_handled(self):
        bot = common.make_bot()

        m = common.make_message(text="ldap list", to_me=True)
        self.assertTrue(ldap.ListHandler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="ldap not list, lol", to_me=True)
        self.assertEqual(
            ldap.ListHandler.handles(m, c.TARGETED, bot.config), None)
Exemplo n.º 6
0
    def test_expected_handled(self):
        bot = common.make_bot()

        m = common.make_message(text="restart", to_me=True)
        self.assertTrue(
            restart.Handler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="not restart", to_me=True)
        self.assertEqual(
            restart.Handler.handles(m, c.TARGETED, bot.config), None)
    def test_expected_handled(self):
        bot = common.make_bot()

        m = common.make_message(text="periodics show", to_me=True)
        self.assertTrue(schedule.ShowHandler.handles(m, c.TARGETED,
                                                     bot.config))

        m = common.make_message(text="periodics do now show", to_me=True)
        self.assertEqual(
            schedule.ShowHandler.handles(m, c.TARGETED, bot.config), None)
    def test_expected_handled(self):
        bot = common.make_bot()

        m = common.make_message(text="periodics pause 1", to_me=True)
        self.assertTrue(
            schedule.PauseHandler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="do something else", to_me=True)
        self.assertEqual(
            schedule.PauseHandler.handles(m, c.TARGETED, bot.config), None)
Exemplo n.º 9
0
    def test_expected_handled(self):
        bot = common.make_bot()

        m = common.make_message(text="tell me a joke", to_me=True)
        self.assertTrue(tell_joke.Handler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="please, don't tell me anything",
                                to_me=True)
        self.assertEqual(
            tell_joke.Handler.handles(m, c.TARGETED, bot.config), None)
Exemplo n.º 10
0
    def test_expected_handled(self):
        bot = common.make_bot(simple_config=True)

        m = common.make_message(text="alias add b c", to_me=True)
        self.assertTrue(alias.AddHandler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="alias remove b c", to_me=True)
        self.assertTrue(alias.RemoveHandler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="alias clear", to_me=True)
        self.assertTrue(alias.ClearHandler.handles(m, c.TARGETED, bot.config))
Exemplo n.º 11
0
    def test_expected_handled(self):
        bot = common.make_bot()

        m = common.make_message(text="ldap describe user", to_me=True)
        self.assertTrue(
            ldap.DescribeUserHandler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="ldap do anything please",
                                to_me=True)
        self.assertEqual(
            ldap.DescribeUserHandler.handles(m, c.TARGETED, bot.config), None)
Exemplo n.º 12
0
    def test_openstack_handles_messages(self):
        bot = common.make_bot()

        m = common.make_message(text="openstack server show", to_me=True)
        self.assertTrue(
            openstack.DescribeServerHandler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="openstack not server show", to_me=True)
        self.assertEqual(
            openstack.DescribeServerHandler.handles(m, c.TARGETED, bot.config),
            None)
Exemplo n.º 13
0
    def test_expected_handled(self):
        bot = mock.MagicMock()
        bot.config = munch.Munch()

        m = common.make_message(text="pull request report", to_me=True)
        self.assertTrue(ghh.PRScanReportHandler.handles(
            m, c.TARGETED, bot.config))

        m = common.make_message(text="help", to_me=True)
        self.assertFalse(ghh.PRScanReportHandler.handles(
            m, c.TARGETED, bot.config))
Exemplo n.º 14
0
    def test_expected_handled(self):
        bot = common.make_bot()

        m = common.make_message(text="stock", to_me=True)
        self.assertTrue(stock.Handler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="stock gddy", to_me=True)
        self.assertTrue(stock.Handler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="stocks", to_me=True)
        self.assertEqual(stock.Handler.handles(m, c.TARGETED, bot.config),
                         None)
Exemplo n.º 15
0
    def test_expected_handled(self):
        bot = mock.MagicMock()
        bot.config = munch.Munch()
        bot.clients = munch.Munch()

        m = common.make_message(text="jira unplanned 'blah blah'", to_me=True)
        self.assertTrue(
            jira.UnplannedHandler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="jira not unplanned 'blah blah'",
                                to_me=True)
        self.assertFalse(
            jira.UnplannedHandler.handles(m, c.TARGETED, bot.config))
Exemplo n.º 16
0
    def test_expected_handled(self):
        bot = common.make_bot()

        m = common.make_message(text="what are you", to_me=True)
        self.assertTrue(what_are_you.Handler.handles(m, c.TARGETED,
                                                     bot.config))

        m = common.make_message(text="what are you?", to_me=True)
        self.assertTrue(what_are_you.Handler.handles(m, c.TARGETED,
                                                     bot.config))

        m = common.make_message(text="tell me what are you?", to_me=True)
        self.assertEqual(
            what_are_you.Handler.handles(m, c.TARGETED, bot.config), None)
Exemplo n.º 17
0
    def test_expected_handled(self):
        bot = common.make_bot()

        m = common.make_message(text="what would trump say", to_me=True)
        self.assertTrue(trump.Handler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="what would trump say?", to_me=True)
        self.assertTrue(trump.Handler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="trump say something", to_me=True)
        self.assertTrue(trump.Handler.handles(m, c.TARGETED, bot.config))

        m = common.make_message(text="trump, it's enough", to_me=True)
        self.assertEqual(trump.Handler.handles(m, c.TARGETED, bot.config),
                         None)
Exemplo n.º 18
0
    def test_kick_not_empty_no_skip_paused(self):
        bot = common.make_bot()
        jobs = {}
        for i in range(0, 10):
            job = mock.MagicMock()
            if i == 0:
                job.next_run_time = self.ZERO_DT
            else:
                if i % 2 == 0:
                    job.next_run_time = self.IN_ONE_HOUR_DT
                else:
                    job.next_run_time = None
            job.id = str(i)
            jobs[job.id] = job
        bot.scheduler.get_jobs.return_value = list(jobs.values())
        bot.scheduler.submitted_jobs = {}
        bot.scheduler.submitted_jobs["1"] = self.ZERO_DT

        m = common.make_message(text="periodics run all",
                                to_me=True,
                                user_id="me")
        h = schedule.RunAllHandler(bot, m)

        h.run(handler.HandlerMatch("skip_paused=false"))
        m.reply_text.assert_called_with("Kicked 10 jobs and skipped 0 jobs.",
                                        prefixed=False,
                                        threaded=True)
Exemplo n.º 19
0
    def test_add_alias(self):
        bot = common.make_bot(simple_config=True)

        m = common.make_message(text="alias add b c", to_me=True, user_id="me")
        h = alias.AddHandler(bot, m)
        h.run(handler.HandlerMatch("b c"))
        self.assertEqual(bot.brain.storage,
                         {'user:me': {'aliases': {'c': 'b'}}})
Exemplo n.º 20
0
    def test_remove_alias(self):
        bot = common.make_bot(simple_config=True)
        bot.brain = common.MockBrain({'user:me': {'aliases': {'c': 'b'}}})

        m = common.make_message(text="alias remove c",
                                to_me=True, user_id="me")
        h = alias.RemoveHandler(bot, m)
        h.run(handler.HandlerMatch("c"))
        self.assertEqual(bot.brain.storage,
                         {'user:me': {'aliases': {}}})
Exemplo n.º 21
0
    def test_restart_check_bot_really_restarted(self):
        bot = common.make_bot()

        m = common.make_message(text="restart",
                                to_me=True, user_id="me")

        h = restart.Handler(bot, m)
        h.run(handler.HandlerMatch())

        self.assertEqual(e.Event.RESTART, bot.dead.value)
Exemplo n.º 22
0
    def test_clear_alias(self):
        bot = common.make_bot(simple_config=True)
        bot.brain = common.MockBrain({
            'user:me': {'aliases': {'c': 'b', 'e': 'f'}},
        })

        m = common.make_message(text="alias clear", to_me=True, user_id="me")
        h = alias.ClearHandler(bot, m)
        h.run(handler.HandlerMatch())
        self.assertEqual(bot.brain.storage,
                         {'user:me': {'aliases': {}}})
Exemplo n.º 23
0
    def test_periodic_no_run_missing(self):
        bot = common.make_bot()

        jobs = {}
        bot.scheduler.get_job.side_effect = lambda job_id: jobs.get(job_id)
        m = common.make_message(text="periodics run one 1",
                                to_me=True,
                                user_id="me")

        h = schedule.RunOneHandler(bot, m)
        self.assertRaises(excp.NotFound, h.run, handler.HandlerMatch("1"))
Exemplo n.º 24
0
    def test_info_with_metadata(self):
        bot = common.make_bot()

        m = common.make_message(text="what are you?", to_me=True, user_id="me")

        h = what_are_you.Handler(bot, m)
        with mock.patch('pkginfo.get_metadata'):
            h.run(handler.HandlerMatch())

        m.reply_text.assert_not_called()
        m.reply_attachments.assert_called_once()
Exemplo n.º 25
0
    def test_openstack_runs_default(self):
        bot = common.make_bot()
        bot.topo_loader.env_names = tuple(['test'])

        m = common.make_message(text="openstack server show",
                                to_me=True,
                                user_id="me")
        h = openstack.DescribeServerHandler(bot, m)
        h.run(handler.HandlerMatch('blah-svrnm'))

        bot.topo_loader.load_one.assert_called()
Exemplo n.º 26
0
    def test_help_me_call(self):
        bot = common.make_bot()

        m = common.make_message(text="consult me", to_me=True, user_id="me")

        with requests_mock.mock() as req_m:
            req_m.get(help_me.Handler.buzz_url, text="you have been helped")
            h = help_me.Handler(bot, m)
            h.run(handler.HandlerMatch())

        m.reply_text.assert_called_once()
Exemplo n.º 27
0
    def test_restart_get_message(self):
        bot = common.make_bot()

        m = common.make_message(text="restart",
                                to_me=True, user_id="me")

        h = restart.Handler(bot, m)
        h.run(handler.HandlerMatch())

        m.reply_text.assert_called_once_with(
            'Restart acknowledged. Be back in a bit!',
            prefixed=False, threaded=True)
Exemplo n.º 28
0
    def test_version_with_distribution(self, get_dist):
        bot = common.make_bot()

        get_dist.return_value = munch.Munch({'version': '1.0.0'})

        m = common.make_message(text="version", to_me=True, user_id="me")

        h = version.Handler(bot, m)
        h.run(handler.HandlerMatch())

        m.reply_text.assert_called_once_with('I am padre version `1.0.0`.',
                                             prefixed=False,
                                             threaded=True)
Exemplo n.º 29
0
    def test_uptime_is_zero(self):
        bot = common.make_bot()
        bot.started_at = None

        m = common.make_message(text="uptime", to_me=True, user_id="me")

        h = uptime.Handler(bot, m)
        h.run(handler.HandlerMatch())

        m.reply_text.assert_called_once_with(
            "I am not alive, how are you sending this?",
            threaded=True,
            prefixed=False)
Exemplo n.º 30
0
    def test_uptime_is_not_zero(self, mock_now):
        bot = common.make_bot()
        bot.started_at = datetime.now(tz=pytz.timezone('UTC'))
        bot.config.tz = 'UTC'
        mock_now.return_value = bot.started_at

        m = common.make_message(text="uptime", to_me=True, user_id="me")

        h = uptime.Handler(bot, m)
        h.run(handler.HandlerMatch())

        m.reply_text.assert_called_once_with(
            'I have been alive for 0 seconds.', prefixed=False, threaded=True)