Skip to content

Commit

Permalink
fix a lot of linter stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
larsborasmussen committed Dec 20, 2024
1 parent 407c399 commit 3bea61a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ mmpy_bot
.docker-token
.rewritten.json
fix_messages.py
__pycache__
29 changes: 16 additions & 13 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
#!/usr/bin/env python
"""chatgpt mattermost bot"""
import logging

from environs import Env
from mmpy_bot import Bot, Settings
from plugins.chatgpt import ChatGPT
from plugins.docker import Docker
from plugins.pushups import Pushups
from plugins.users import Users
from plugins.tts import TTS
from plugins.shellcmds import ShellCmds
from plugins.redistool import RedisTool
from plugins.ollama import Ollama

# from plugins.ollama import Ollama
from plugins.anthropic import Anthropic
from plugins.hibp import HIPB
from plugins.calc import Calc
from plugins.chatgpt import ChatGPT
from plugins.giphy import Giphy
from plugins.ntp import Ntp
from plugins.hibp import HIPB
from plugins.jira import Jira
from plugins.ntp import Ntp

# from plugins.docker import Docker
from plugins.pushups import Pushups
from plugins.redistool import RedisTool
from plugins.shellcmds import ShellCmds
from plugins.tts import TTS
from plugins.users import Users
from plugins.version import Version
import logging

env = Env()
log_channel = env.str("MM_BOT_LOG_CHANNEL")
Expand All @@ -28,7 +31,7 @@
logging.basicConfig(level=logging.INFO)

# read the version file and set the version
with open("version") as f:
with open("version", encoding="utf-8") as f:
version = f.read().strip()

bot = Bot(
Expand Down Expand Up @@ -61,4 +64,4 @@
],
enable_logging=True,
)
bot.run()
bot.run()
25 changes: 15 additions & 10 deletions tests/plugins_helper_test.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
""" Tests for the helper plugin """

from unittest.mock import Mock, patch

import pytest
from unittest.mock import patch, Mock

from plugins import helper


@pytest.fixture
def helper_instance():
"""helper instance fixture"""
mock_driver = Mock()
return helper.Helper(mock_driver)


# pylint: disable=redefined-outer-name
def test_strip_self_username(helper_instance):
"""Test strip_self_username"""
helper_instance.driver.client.username = "testuser"
message = "@testuser Hello, world!"
expected = "Hello, world!"
Expand Down Expand Up @@ -44,45 +50,44 @@ def test_strip_self_username(helper_instance):
)
@patch("requests.head")
def test_validate_input(
mock_requests_head, helper_instance, input, expected_result, validate_type
mock_requests_head, helper_instance, input_val, expected_result, validate_type
):
"""Test validate_input"""
mock_requests_head.return_value.status_code = 200

result = helper_instance.validate_input(input, types=[validate_type])
result = helper_instance.validate_input(input_val, types=[validate_type])
assert result == expected_result


def test_urlencode_text(helper_instance):
"""Test urlencode_text"""
text = "Hello, world!"
expected = "Hello%2C+world%21"
result = helper_instance.urlencode_text(text)
assert result == expected


def test_redis_serialize_json(helper_instance):
"""Test redis_serialize_json"""
data = {"key": "value"}
expected = '{"key": "value"}'
result = helper_instance.redis_serialize_json(data)
assert result == expected


def test_redis_deserialize_json(helper_instance):
"""Test redis_deserialize_json"""
data = '{"key": "value"}'
expected = {"key": "value"}
result = helper_instance.redis_deserialize_json(data)
assert result == expected


def test_create_tmp_filename(helper_instance):
import uuid

# this is only to get the length of the uuid which is used in the test
uuid_len = len(str(uuid.uuid4()))
"""Test create_tmp_filename"""
extension = "png"
begin = "/tmp/"
end = f".{extension}"
result = helper_instance.create_tmp_filename(extension)
# the result should start with /tmp/ and end with .png
assert result.startswith(begin) and result.endswith(end)
# the length of the result should be the length of /tmp/ + the length of the uuid + the length of .png
assert len(result) == len(begin) + uuid_len + len(end)
2 changes: 1 addition & 1 deletion watch.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
find plugins/ -type f | entr -r make dev
find . -type f -name '*.py' -or -name "Pipfile*" | entr -r make dev

0 comments on commit 3bea61a

Please sign in to comment.