Skip to content

Commit

Permalink
chore: specify dev dependencies in setup.cfg, add CI (#12)
Browse files Browse the repository at this point in the history
* chore: specify dev dependencies in setup.cfg
* added CI
* fix lint
* fix flaky test
  • Loading branch information
missytake authored Aug 19, 2024
1 parent f3daeee commit 18e5a67
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 18 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
8 changes: 8 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions src/team_bot/pyinfra.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
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
Expand Down
45 changes: 32 additions & 13 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from deltachat.capi import lib as dclib


TIMEOUT = 20
TIMEOUT = 40


def get_user_crew(crewuser: deltachat.Account) -> deltachat.Chat:
Expand All @@ -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)


Expand Down

0 comments on commit 18e5a67

Please sign in to comment.