Skip to content

Commit 18e5a67

Browse files
authored
chore: specify dev dependencies in setup.cfg, add CI (#12)
* chore: specify dev dependencies in setup.cfg * added CI * fix lint * fix flaky test
1 parent f3daeee commit 18e5a67

File tree

5 files changed

+65
-18
lines changed

5 files changed

+65
-18
lines changed

.github/workflows/ci.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python-version: ['3.8', '3.11']
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Set up Python ${{ matrix.python-version }}
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: ${{ matrix.python-version }}
18+
- name: Install dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
python -m pip install '.[dev]'
22+
- run: tox
23+

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ run:
103103
```
104104
python3 -m venv venv
105105
. venv/bin/activate
106-
pip install pytest tox black pytest-xdist pytest-timeout
107-
pip install -e .
106+
pip install -e .[dev]
108107
tox
109108
```

setup.cfg

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ install_requires =
2626
qrcode
2727
deltachat>=1.136.2
2828

29+
[options.extras_require]
30+
dev =
31+
pytest
32+
tox
33+
black
34+
pytest-xdist
35+
pytest-timeout
36+
2937
[options.packages.find]
3038
where = src
3139

src/team_bot/pyinfra.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
from pyinfra.facts.systemd import SystemdStatus
77

88

9-
def deploy_team_bot(
10-
unix_user: str, bot_email: str, bot_passwd: str, dbdir: str = None
11-
):
9+
def deploy_team_bot(unix_user: str, bot_email: str, bot_passwd: str, dbdir: str = None):
1210
"""Deploy TeamsBot to a UNIX user, with specified credentials
1311
1412
:param unix_user: the existing UNIX user of the bot

tests/test_bot.py

+32-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from deltachat.capi import lib as dclib
77

88

9-
TIMEOUT = 20
9+
TIMEOUT = 40
1010

1111

1212
def get_user_crew(crewuser: deltachat.Account) -> deltachat.Chat:
@@ -27,38 +27,57 @@ def test_not_relay_groups(relaycrew, outsider, lp):
2727
bot = relaycrew.bot
2828
user = relaycrew.user
2929

30-
lp.sec("bot <-> outsider 1:1 chat")
30+
text = "outsider -> bot 1:1 chat"
31+
lp.sec(text)
3132
outsider_botcontact = outsider.create_contact(bot.get_config("addr"))
3233
outsider_outside_chat = outsider.create_chat(outsider_botcontact)
33-
outsider_outside_chat.send_text("test 1:1 message to bot")
34-
34+
outsider_outside_chat.send_text(text)
35+
lp.sec("receiving message from outsider in 1:1 chat")
3536
bot_message_from_outsider = bot._evtracker.wait_next_incoming_message()
3637
bot_outside_chat = bot_message_from_outsider.chat
38+
assert bot_message_from_outsider.text == text
3739
assert not bot.relayplugin.is_relay_group(bot_outside_chat)
3840

39-
lp.sec("bot <-> outsider group chat")
41+
text = "outsider -> bot group chat"
42+
lp.sec(text)
4043
outsider_bot_group = outsider.create_group_chat(
4144
"test with outsider", contacts=[outsider_botcontact]
4245
)
43-
outsider_bot_group.send_text("test message to outsider group")
46+
outsider_bot_group.send_text(text)
47+
lp.sec("receiving message from outsider in group chat")
4448
bot_message_from_outsider = bot._evtracker.wait_next_incoming_message()
49+
assert bot_message_from_outsider.text == text
4550
assert not bot.relayplugin.is_relay_group(bot_message_from_outsider.chat)
4651

47-
lp.sec("bot <-> user 1:1 chat")
52+
text = "user -> bot 1:1 chat"
53+
lp.sec(text)
4854
user_botcontact = user.create_contact(bot.get_config("addr"))
4955
user_to_bot = user.create_chat(user_botcontact)
50-
user_to_bot.send_text("test message to bot")
56+
user_to_bot.send_text(text)
57+
lp.sec("receiving message from user in 1:1 chat")
58+
5159
# somehow the message doesn't trigger DC_EVENT_INCOMING_MSG
52-
bot_message_from_user = bot.get_chats()[-3].get_messages()[-1] # bot._evtracker.wait_next_incoming_message()
53-
while bot_message_from_user.text != "test message to bot":
54-
bot_message_from_user = bot.get_chats()[-3].get_messages()[-1] # bot._evtracker.wait_next_incoming_message()
60+
# bot._evtracker.wait_next_incoming_message()
61+
def find_msg(ac, text):
62+
for chat in ac.get_chats():
63+
for msg in chat.get_messages():
64+
if msg.text == text:
65+
return msg
66+
67+
bot_message_from_user = find_msg(bot, text)
68+
while not bot_message_from_user:
69+
bot_message_from_user = find_msg(bot, text)
5570
time.sleep(1)
71+
assert bot_message_from_user.text == text
5672
assert not bot.relayplugin.is_relay_group(bot_message_from_user.chat)
5773

58-
lp.sec("bot <-> user group chat")
74+
text = "user -> bot group chat"
75+
lp.sec(text)
5976
user_group = user.create_group_chat("test with user", contacts=[user_botcontact])
60-
user_group.send_text("testing message to user group")
77+
user_group.send_text(text)
78+
lp.sec("receiving message from user in group chat")
6179
bot_message_from_user = bot._evtracker.wait_next_incoming_message()
80+
assert bot_message_from_user.text == text
6281
assert not bot.relayplugin.is_relay_group(bot_message_from_user.chat)
6382

6483

0 commit comments

Comments
 (0)