Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle test: Add conference_send_message test. #116

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ COPY test /build/test
RUN . /path/to/venv/bin/activate \
&& coverage run -m unittest discover -v -p "*_test.py"
RUN . /path/to/venv/bin/activate \
&& coverage report -m
&& coverage report -m --fail-under=65
1 change: 1 addition & 0 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ TESTS = glob(["**/*.py"])
name = src[:-3],
size = "small",
srcs = [src],
args = ["-v"],
tags = ["no-cross"],
deps = ["//py_toxcore_c:pytox"],
) for src in TESTS]
Expand Down
100 changes: 95 additions & 5 deletions test/auto_tests/auto_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(self, index: int) -> None:
self.index = index
self.friends = collections.defaultdict(FriendInfo)
self.conferences = collections.defaultdict(ConferenceInfo)
self.name = f"tox{index}".encode("utf-8")

def handle_self_connection_status(self,
connection_status: core.Tox_Connection
Expand Down Expand Up @@ -271,11 +272,11 @@ def test_name(self) -> None:
self._wait_for_friend_online()
friend_number = self.tox2.friend_by_public_key(self.tox1.public_key)
friend = self.tox2.friends[friend_number]
self.assertEqual(self.tox1.name, b"")
self.assertEqual(self.tox1.name, b"tox1")
self.tox1.name = b"Now that's a name I haven't heard in a long time"
self.assertEqual(self.tox1.name,
b"Now that's a name I haven't heard in a long time")
self._iterate(100, lambda: friend.name == b"")
self._iterate(100, lambda: friend.name == b"tox1")
self.assertEqual(friend.name,
b"Now that's a name I haven't heard in a long time")
self.assertEqual(
Expand Down Expand Up @@ -318,14 +319,103 @@ def test_read_receipt(self) -> None:
def test_conference_invite(self) -> None:
self._wait_for_friend_online()
# tox1 creates conference.
cnum = self.tox1.conference_new()
self.assertListEqual(self.tox1.conference_chatlist, [cnum])
cnum1 = self.tox1.conference_new()
self.assertListEqual(self.tox1.conference_chatlist, [cnum1])
# tox1 invites tox2 to conference.
self.tox1.conference_invite(
self.tox1.friend_by_public_key(self.tox2.public_key), cnum)
self.tox1.friend_by_public_key(self.tox2.public_key), cnum1)
# wait for tox2 to join conference.
self._iterate(100, lambda: not self.tox2.conference_chatlist)
self.assertEqual(len(self.tox2.conference_chatlist), 1)
# wait for group connection.
cnum2 = self.tox2.conference_chatlist[0]
self._iterate(100, lambda: not self.tox2.conferences[cnum2].connected)
# tox2 invites tox3 to conference.
self.tox2.conference_invite(
self.tox2.friend_by_public_key(self.tox3.public_key), cnum2)
# wait for tox3 to join conference.
self._iterate(100, lambda: not self.tox3.conference_chatlist)
self.assertEqual(len(self.tox3.conference_chatlist), 1)
# test conference_by_id.
self.assertEqual(
self.tox1.conference_by_id(self.tox1.conference_get_id(cnum1)),
cnum1)
self.assertEqual(self.tox1.conference_get_type(cnum1),
core.TOX_CONFERENCE_TYPE_TEXT)

def test_conference_message(self) -> None:
self._wait_for_friend_online()
cnum1 = self.tox1.conference_chatlist[0]
cnum2 = self.tox2.conference_chatlist[0]
cnum3 = self.tox3.conference_chatlist[0]
# wait for all toxes to see all 3 peers.
self._iterate(
100,
lambda: any(
len(tox.conferences[tox.conference_chatlist[0]].peers) < 2
for tox in (self.tox1, self.tox2, self.tox3)),
)
# wait for group connection.
self._iterate(100, lambda: not self.tox2.conferences[cnum2].connected)
# check that none of the toxes have messages, yet.
self.assertFalse(self.tox1.conferences[cnum1].messages)
self.assertFalse(self.tox2.conferences[cnum2].messages)
self.assertFalse(self.tox3.conferences[cnum3].messages)
# tox2 sends message to conference.
self.tox2.conference_send_message(cnum2, core.TOX_MESSAGE_TYPE_NORMAL,
b"hello there!")
# wait for toxes to receive message.
self._iterate(
100,
lambda: any(not tox.conferences[tox.conference_chatlist[0]].
messages for tox in (self.tox1, self.tox2, self.tox3)),
)
# check message contents.
self.assertEqual(
self.tox1.conferences[cnum1].messages[0],
(1, core.TOX_MESSAGE_TYPE_NORMAL, b"hello there!"),
)
self.assertEqual(
self.tox2.conferences[cnum2].messages[0],
(1, core.TOX_MESSAGE_TYPE_NORMAL, b"hello there!"),
)
self.assertEqual(
self.tox3.conferences[cnum3].messages[0],
(1, core.TOX_MESSAGE_TYPE_NORMAL, b"hello there!"),
)

def test_conference_peer_name(self) -> None:
self._wait_for_friend_online()
cnum1 = self.tox1.conference_chatlist[0]
cnum2 = self.tox2.conference_chatlist[0]
cnum3 = self.tox3.conference_chatlist[0]
# check peer names.
self.assertEqual(self.tox1.conferences[cnum1].peers[1].name, b"tox2")
self.assertEqual(self.tox2.conferences[cnum2].peers[1].name, b"tox2")
self.assertEqual(self.tox2.conferences[cnum2].peers[2].name, b"tox3")
self.assertEqual(self.tox3.conferences[cnum3].peers[1].name, b"tox2")

def test_conference_title(self) -> None:
self._wait_for_friend_online()
cnum1 = self.tox1.conference_chatlist[0]
cnum2 = self.tox2.conference_chatlist[0]
cnum3 = self.tox3.conference_chatlist[0]
# check title isn't set yet.
self.assertEqual(self.tox1.conferences[cnum1].title, (0, b""))
self.assertEqual(self.tox2.conferences[cnum2].title, (0, b""))
self.assertEqual(self.tox3.conferences[cnum3].title, (0, b""))
# tox2 sets title.
self.tox2.conference_set_title(cnum1, b"TokTok dev chat")
# wait for title to be set for tox1 and tox3.
self._iterate(
100,
lambda: any(tox.conferences[tox.conference_chatlist[0]].title[1] ==
b"" for tox in (self.tox1, self.tox3)),
)
self.assertEqual(self.tox1.conferences[cnum2].title,
(1, b"TokTok dev chat"))
self.assertEqual(self.tox3.conferences[cnum3].title,
(1, b"TokTok dev chat"))


if __name__ == "__main__":
Expand Down