Beispiel #1
0
    def test_get_word_failure(self, monkeypatch):
        class MockResponse:
            @staticmethod
            def json():
                return None

            @staticmethod
            def raise_for_status():
                raise requests.HTTPError

        def mock_get(self, *args, **kwargs):
            return MockResponse()

        cfg = {'apiUrl': "http://api.url", 'commandPrefix': "?", 'guildId': 1}
        t = bot.Taalbot(cfg)

        monkeypatch.setattr(requests, "get", mock_get)
        with pytest.raises(requests.HTTPError):
            LidwoordCog(t).get_or_learn_word('word')
Beispiel #2
0
    def test_get_word_success(self, monkeypatch):
        class MockResponse:
            @staticmethod
            def json():
                return {'id': 1, 'word': "word", 'article': "article"}

            @staticmethod
            def raise_for_status():
                pass

        def mock_get(self, *args, **kwargs):
            return MockResponse()

        cfg = {'apiUrl': "http://api.url", 'commandPrefix': "?", 'guildId': 1}
        t = bot.Taalbot(cfg)

        monkeypatch.setattr(requests, "get", mock_get)
        result = LidwoordCog(t).get_or_learn_word('word')
        assert result['id'] == 1 and result['word'] == "word"
Beispiel #3
0
 def test_no_log_channel(self, caplog):
     caplog.set_level(logging.INFO)
     cfg = {'apiUrl': "http://api.url", 'commandPrefix': "?", 'guildId': 1}
     t = bot.Taalbot(cfg)
     t.log_channel = t.get_log_channel()
     assert not t.log_channel and "No channel name was given" in caplog.text
Beispiel #4
0
 def test_new_bot_instance_init_method(self):
     cfg = {'apiUrl': "http://api.url", 'commandPrefix': "?", 'guildId': 1}
     t = bot.Taalbot(cfg)
     assert cfg.get('apiUrl') == t.api_url and \
         cfg.get('commandPrefix') == t.config.get('commandPrefix') and \
         cfg.get('guildId') == t.config.get('guildId')