From 18e5a67aa7ffa087ff97e9f14e57ac3d3248fdc9 Mon Sep 17 00:00:00 2001 From: missytake Date: Mon, 19 Aug 2024 14:11:46 +0200 Subject: [PATCH] chore: specify dev dependencies in setup.cfg, add CI (#12) * chore: specify dev dependencies in setup.cfg * added CI * fix lint * fix flaky test --- .github/workflows/ci.yml | 23 ++++++++++++++++++++ README.md | 3 +-- setup.cfg | 8 +++++++ src/team_bot/pyinfra.py | 4 +--- tests/test_bot.py | 45 ++++++++++++++++++++++++++++------------ 5 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4012c58 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,23 @@ +name: CI + +on: + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.8', '3.11'] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install '.[dev]' + - run: tox + diff --git a/README.md b/README.md index 51bfcc9..6e2cbd0 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,6 @@ run: ``` python3 -m venv venv . venv/bin/activate -pip install pytest tox black pytest-xdist pytest-timeout -pip install -e . +pip install -e .[dev] tox ``` diff --git a/setup.cfg b/setup.cfg index fbbbd85..6c3b9e5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -26,6 +26,14 @@ install_requires = qrcode deltachat>=1.136.2 +[options.extras_require] +dev = + pytest + tox + black + pytest-xdist + pytest-timeout + [options.packages.find] where = src diff --git a/src/team_bot/pyinfra.py b/src/team_bot/pyinfra.py index 2116597..359bc1a 100644 --- a/src/team_bot/pyinfra.py +++ b/src/team_bot/pyinfra.py @@ -6,9 +6,7 @@ from pyinfra import host from pyinfra.facts.systemd import SystemdStatus -def deploy_team_bot( - unix_user: str, bot_email: str, bot_passwd: str, dbdir: str = None -): +def deploy_team_bot(unix_user: str, bot_email: str, bot_passwd: str, dbdir: str = None): """Deploy TeamsBot to a UNIX user, with specified credentials :param unix_user: the existing UNIX user of the bot diff --git a/tests/test_bot.py b/tests/test_bot.py index b5937c1..27a684d 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -6,7 +6,7 @@ import pytest from deltachat.capi import lib as dclib -TIMEOUT = 20 +TIMEOUT = 40 def get_user_crew(crewuser: deltachat.Account) -> deltachat.Chat: @@ -27,38 +27,57 @@ def test_not_relay_groups(relaycrew, outsider, lp): bot = relaycrew.bot user = relaycrew.user - lp.sec("bot <-> outsider 1:1 chat") + text = "outsider -> bot 1:1 chat" + lp.sec(text) outsider_botcontact = outsider.create_contact(bot.get_config("addr")) outsider_outside_chat = outsider.create_chat(outsider_botcontact) - outsider_outside_chat.send_text("test 1:1 message to bot") - + outsider_outside_chat.send_text(text) + lp.sec("receiving message from outsider in 1:1 chat") bot_message_from_outsider = bot._evtracker.wait_next_incoming_message() bot_outside_chat = bot_message_from_outsider.chat + assert bot_message_from_outsider.text == text assert not bot.relayplugin.is_relay_group(bot_outside_chat) - lp.sec("bot <-> outsider group chat") + text = "outsider -> bot group chat" + lp.sec(text) outsider_bot_group = outsider.create_group_chat( "test with outsider", contacts=[outsider_botcontact] ) - outsider_bot_group.send_text("test message to outsider group") + outsider_bot_group.send_text(text) + lp.sec("receiving message from outsider in group chat") bot_message_from_outsider = bot._evtracker.wait_next_incoming_message() + assert bot_message_from_outsider.text == text assert not bot.relayplugin.is_relay_group(bot_message_from_outsider.chat) - lp.sec("bot <-> user 1:1 chat") + text = "user -> bot 1:1 chat" + lp.sec(text) user_botcontact = user.create_contact(bot.get_config("addr")) user_to_bot = user.create_chat(user_botcontact) - user_to_bot.send_text("test message to bot") + user_to_bot.send_text(text) + lp.sec("receiving message from user in 1:1 chat") + # somehow the message doesn't trigger DC_EVENT_INCOMING_MSG - bot_message_from_user = bot.get_chats()[-3].get_messages()[-1] # bot._evtracker.wait_next_incoming_message() - while bot_message_from_user.text != "test message to bot": - bot_message_from_user = bot.get_chats()[-3].get_messages()[-1] # bot._evtracker.wait_next_incoming_message() + # bot._evtracker.wait_next_incoming_message() + def find_msg(ac, text): + for chat in ac.get_chats(): + for msg in chat.get_messages(): + if msg.text == text: + return msg + + bot_message_from_user = find_msg(bot, text) + while not bot_message_from_user: + bot_message_from_user = find_msg(bot, text) time.sleep(1) + assert bot_message_from_user.text == text assert not bot.relayplugin.is_relay_group(bot_message_from_user.chat) - lp.sec("bot <-> user group chat") + text = "user -> bot group chat" + lp.sec(text) user_group = user.create_group_chat("test with user", contacts=[user_botcontact]) - user_group.send_text("testing message to user group") + user_group.send_text(text) + lp.sec("receiving message from user in group chat") bot_message_from_user = bot._evtracker.wait_next_incoming_message() + assert bot_message_from_user.text == text assert not bot.relayplugin.is_relay_group(bot_message_from_user.chat)