Ejemplo n.º 1
0
    def test_connection_fail(self):
        slack = Slack(token='spam_ham_egg',
                      plugins=(('spam.ham.egg.onion', {}),),
                      max_workers=1)

        with patch.object(slack.client,
                          'request',
                          side_effect=Exception) as mock_connect:
            with pytest.raises(SarahSlackException) as e:
                slack.connect()

            assert_that(str(e)).matches("Slack request error on /rtm.start\.")
            assert_that(mock_connect.call_count).is_equal_to(1)
Ejemplo n.º 2
0
    def test_connection_ok(self):
        slack = Slack(token='spam_ham_egg',
                      plugins=(('spam.ham.egg.onion', {}),),
                      max_workers=1)

        with patch.object(slack.client,
                          'get',
                          return_value={'url': 'ws://localhost:80/'}):
            with patch.object(sarah.bot.slack.WebSocketApp,
                              'run_forever',
                              return_value=True) as mock_connect:
                slack.connect()

                assert_that(mock_connect.call_count).is_equal_to(1)
Ejemplo n.º 3
0
    def test_connection_response_error(self):
        slack = Slack(token='spam_ham_egg',
                      plugins=(('spam.ham.egg.onion', {}),),
                      max_workers=1)

        with patch.object(slack.client,
                          'get',
                          return_value={"dummy": "spam"}) as mock_connect:
            with pytest.raises(SarahSlackException) as e:
                slack.connect()

            assert_that(mock_connect.call_count).is_equal_to(1)
            assert_that(str(e)).matches("Slack response did not contain "
                                        "connecting url. {'dummy': 'spam'}")
Ejemplo n.º 4
0
    def test_add_schedule_job(self):
        slack = Slack(
            token='spam_ham_egg',
            max_workers=1,
            plugins=(('sarah.bot.plugins.bmw_quotes',
                      {'channels': 'U06TXXXXX'}),))
        slack.connect = lambda: True
        slack.run()

        jobs = slack.scheduler.get_jobs()
        assert_that(jobs).is_length(1)
        assert_that(jobs[0]).has_id('sarah.bot.plugins.bmw_quotes.bmw_quotes')
        assert_that(jobs[0].trigger).has_interval_length(300)
Ejemplo n.º 5
0
    def test_missing_channel_config(self):
        logging.warning = MagicMock()

        slack = Slack(
            token='spam_ham_egg',
            plugins=(('sarah.bot.plugins.bmw_quotes', {"dummy": "spam"}),),
            max_workers=1)
        slack.connect = lambda: True
        slack.run()

        assert_that(logging.warning.call_count).is_equal_to(1)
        assert_that(logging.warning.call_args) \
            .is_equal_to(call('Missing channels configuration for schedule '
                              'job. sarah.bot.plugins.bmw_quotes. Skipping.'))
Ejemplo n.º 6
0
    def test_missing_config(self):
        logging.warning = MagicMock()

        slack = Slack(token='spam_ham_egg',
                      plugins=(('sarah.bot.plugins.bmw_quotes',),),
                      max_workers=1)
        slack.connect = lambda: True
        slack.run()

        assert_that(slack.scheduler.get_jobs()) \
            .described_as("No module is loaded") \
            .is_empty()
        assert_that(logging.warning.call_count).is_equal_to(1)
        assert_that(logging.warning.call_args) \
            .is_equal_to(call('Missing configuration for schedule job. '
                              'sarah.bot.plugins.bmw_quotes. Skipping.'))