Ejemplo n.º 1
0
    def test_mute_unmute(self, client: StreamChat, channel: Channel,
                         random_users: List[Dict]):
        user_id = random_users[0]["id"]
        response = channel.mute(user_id, expiration=30000)
        assert "channel_mute" in response
        assert "expires" in response["channel_mute"]
        assert response["channel_mute"]["channel"]["cid"] == channel.cid
        assert response["channel_mute"]["user"]["id"] == user_id

        response = client.query_channels({
            "muted": True,
            "cid": channel.cid
        },
                                         user_id=user_id)
        assert len(response["channels"]) == 1

        channel.unmute(user_id)
        response = client.query_channels(
            {
                "muted": True,
                "cid": channel.cid
            },
            user_id=user_id,
        )
        assert len(response["channels"]) == 0
Ejemplo n.º 2
0
    def test_shadow_ban(
        self, client: StreamChat, random_user, server_user, channel: Channel
    ):
        msg_id = str(uuid.uuid4())
        response = channel.send_message(
            {"id": msg_id, "text": "hello world"}, random_user["id"]
        )

        response = client.get_message(msg_id)
        assert not response["message"]["shadowed"]

        response = client.shadow_ban(random_user["id"], user_id=server_user["id"])

        msg_id = str(uuid.uuid4())
        response = channel.send_message(
            {"id": msg_id, "text": "hello world"}, random_user["id"]
        )

        response = client.get_message(msg_id)
        assert response["message"]["shadowed"]

        response = client.remove_shadow_ban(
            random_user["id"], user_id=server_user["id"]
        )

        msg_id = str(uuid.uuid4())
        response = channel.send_message(
            {"id": msg_id, "text": "hello world"}, random_user["id"]
        )

        response = client.get_message(msg_id)
        assert not response["message"]["shadowed"]
Ejemplo n.º 3
0
 def test_send_reaction(self, channel: Channel, random_user: Dict):
     msg = channel.send_message({"text": "hi"}, random_user["id"])
     response = channel.send_reaction(msg["message"]["id"],
                                      {"type": "love"}, random_user["id"])
     assert "message" in response
     assert len(response["message"]["latest_reactions"]) == 1
     assert response["message"]["latest_reactions"][0]["type"] == "love"
Ejemplo n.º 4
0
    def test_add_members(self, channel: Channel, random_user: Dict):
        response = channel.remove_members([random_user["id"]])
        assert len(response["members"]) == 0

        response = channel.add_members([random_user["id"]])
        assert len(response["members"]) == 1
        assert not response["members"][0].get("is_moderator", False)
Ejemplo n.º 5
0
    def test_invite_members(self, channel: Channel, random_user: Dict):
        response = channel.remove_members([random_user["id"]])
        assert len(response["members"]) == 0

        response = channel.invite_members([random_user["id"]])
        assert len(response["members"]) == 1
        assert response["members"][0].get("invited", True)
Ejemplo n.º 6
0
    def test_add_members_with_additional_options(self, channel: Channel,
                                                 random_user: Dict):
        response = channel.remove_members([random_user["id"]])
        assert len(response["members"]) == 0

        response = channel.add_members([random_user["id"]], hide_history=True)
        assert len(response["members"]) == 1
Ejemplo n.º 7
0
    def test_invites(self, client: StreamChat, channel: Channel):
        members = ["john", "paul", "george", "pete", "ringo", "eric"]
        client.update_users([{"id": m} for m in members])
        channel = client.channel(
            "team",
            "beatles-" + str(uuid.uuid4()),
            {
                "members": members,
                "invites": ["ringo", "eric"]
            },
        )
        channel.create("john")
        # accept the invite when not a member
        with pytest.raises(StreamAPIException):
            channel.accept_invite("brian")
        # accept the invite when a member
        accept = channel.accept_invite("ringo")
        for m in accept["members"]:
            if m["user_id"] == "ringo":
                assert m["invited"] is True
                assert "invite_accepted_at" in m
        # can accept again, noop
        channel.accept_invite("ringo")

        reject = channel.reject_invite("eric")
        for m in reject["members"]:
            if m["user_id"] == "eric":
                assert m["invited"] is True
                assert "invite_rejected_at" in m
        # cannot reject again, noop
        channel.reject_invite("eric")
Ejemplo n.º 8
0
    def test_translate_message(
        self, client: StreamChat, channel: Channel, random_user: Dict
    ):
        msg = {"id": str(uuid.uuid4()), "text": "hello world"}
        channel.send_message(msg, random_user["id"])
        resp = client.translate_message(msg["id"], "hu")

        assert len(resp["message"]) > 0
Ejemplo n.º 9
0
 def test_send_and_delete_image(self, channel: Channel, random_user: Dict):
     url = "helloworld.jpg"
     resp = channel.send_image(url,
                               "helloworld.jpg",
                               random_user,
                               content_type="image/jpeg")
     assert "helloworld.jpg" in resp["file"]
     channel.delete_image(resp["file"])
Ejemplo n.º 10
0
 def test_get_messages(self, channel: Channel, random_user: Dict):
     msg_id = str(uuid.uuid4())
     channel.send_message({
         "id": msg_id,
         "text": "helloworld"
     }, random_user["id"])
     resp = channel.get_messages([msg_id])
     assert len(resp["messages"]) == 1
Ejemplo n.º 11
0
    def test_update_partial(self, channel: Channel):
        response = channel.update({"color": "blue", "age": 30})
        assert "channel" in response
        assert response["channel"]["color"] == "blue"
        assert response["channel"]["age"] == 30

        response = channel.update_partial(to_set={"color": "red"},
                                          to_unset=["age"])
        assert "channel" in response
        assert response["channel"]["color"] == "red"
        assert "age" not in response["channel"]
Ejemplo n.º 12
0
 def test_run_message_actions(
     self, client: StreamChat, channel: Channel, random_user: Dict
 ):
     msg = {"id": str(uuid.uuid4()), "text": "/giphy wave"}
     channel.send_message(msg, random_user["id"])
     client.run_message_action(
         msg["id"],
         {
             "user": {"id": random_user["id"]},
             "form_data": {"image_action": "shuffle"},
         },
     )
Ejemplo n.º 13
0
    def test_check_push(self, client: StreamChat, channel: Channel, random_user: Dict):
        msg = {"id": str(uuid.uuid4()), "text": "/giphy wave"}
        channel.send_message(msg, random_user["id"])
        resp = client.check_push(
            {
                "message_id": msg["id"],
                "skip_devices": True,
                "user_id": random_user["id"],
            }
        )

        assert len(resp["rendered_message"]) > 0
Ejemplo n.º 14
0
    def test_assign_roles_moderators(self, channel: Channel,
                                     random_user: Dict):
        member = {
            "user_id": random_user["id"],
            "channel_role": "channel_moderator"
        }
        response = channel.add_members([member])
        assert len(response["members"]) == 1
        assert response["members"][0]["channel_role"] == "channel_moderator"

        member["channel_role"] = "channel_member"
        response = channel.assign_roles([member])
        assert len(response["members"]) == 1
        assert response["members"][0]["channel_role"] == "channel_member"
Ejemplo n.º 15
0
 def test_send_message_with_options(self, channel: Channel,
                                    random_user: Dict):
     response = channel.send_message({"text": "hi"},
                                     random_user["id"],
                                     skip_push=True)
     assert "message" in response
     assert response["message"]["text"] == "hi"
Ejemplo n.º 16
0
 def test_truncate_with_options(self, channel: Channel, random_user: Dict):
     response = channel.truncate(
         skip_push=True,
         message={
             "text": "Truncating channel.",
             "user_id": random_user["id"],
         },
     )
     assert "channel" in response
Ejemplo n.º 17
0
    def channel(self, channel_type, channel_id=None, data=None):
        """
        Creates a channel object

        :param channel_type: the channel type
        :param channel_id: the id of the channel
        :param data: additional data, ie: {"members":[id1, id2, ...]}
        :return: Channel
        """
        return Channel(self, channel_type, channel_id, data)
Ejemplo n.º 18
0
    def test_export_channel(self, client: StreamChat, channel: Channel,
                            random_users: List[Dict]):
        channel.send_message({"text": "Hey Joni"}, random_users[0]["id"])

        resp = client.export_channel(channel.channel_type, channel.id)
        task_id = resp["task_id"]
        assert task_id != ""

        while True:
            resp = client.get_export_channel_status(task_id)
            assert resp["status"] != ""
            assert resp["created_at"] != ""
            assert resp["updated_at"] != ""
            if resp["status"] == "completed":
                assert len(resp["result"]) != 0
                assert resp["result"]["url"] != ""
                assert "error" not in resp
                break
            time.sleep(0.5)
Ejemplo n.º 19
0
    def test_query_members(self, client: StreamChat, channel: Channel):
        members = ["paul", "george", "john", "jessica", "john2"]
        client.update_users([{"id": m, "name": m} for m in members])
        for member in members:
            channel.add_members([member])

        response = channel.query_members(
            filter_conditions={"name": {
                "$autocomplete": "j"
            }},
            sort=[{
                "field": "created_at",
                "direction": 1
            }],
            offset=1,
            limit=10,
        )

        assert len(response) == 2
        assert response[0]["user"]["id"] == "jessica"
        assert response[1]["user"]["id"] == "john2"
Ejemplo n.º 20
0
 def test_channel_hide_show(self, client: StreamChat, channel: Channel,
                            random_users):
     # setup
     channel.add_members([u["id"] for u in random_users])
     # verify
     response = client.query_channels({"id": channel.id})
     assert len(response["channels"]) == 1
     response = client.query_channels({"id": channel.id},
                                      user_id=random_users[0]["id"])
     assert len(response["channels"]) == 1
     # hide
     channel.hide(random_users[0]["id"])
     response = client.query_channels({"id": channel.id},
                                      user_id=random_users[0]["id"])
     assert len(response["channels"]) == 0
     # search hidden channels
     response = client.query_channels({
         "id": channel.id,
         "hidden": True
     },
                                      user_id=random_users[0]["id"])
     assert len(response["channels"]) == 1
     # unhide
     channel.show(random_users[0]["id"])
     response = client.query_channels({"id": channel.id},
                                      user_id=random_users[0]["id"])
     assert len(response["channels"]) == 1
     # hide again
     channel.hide(random_users[0]["id"])
     response = client.query_channels({"id": channel.id},
                                      user_id=random_users[0]["id"])
     assert len(response["channels"]) == 0
     # send message
     channel.send_message({"text": "hi"}, random_users[1]["id"])
     # channel should be listed now
     response = client.query_channels({"id": channel.id},
                                      user_id=random_users[0]["id"])
     assert len(response["channels"]) == 1
Ejemplo n.º 21
0
 def test_ban_user(self, channel: Channel, random_user, server_user: Dict):
     channel.ban_user(random_user["id"], user_id=server_user["id"])
     channel.ban_user(
         random_user["id"],
         timeout=3600,
         reason="offensive language is not allowed here",
         user_id=server_user["id"],
     )
     channel.unban_user(random_user["id"])
Ejemplo n.º 22
0
    def test_get_reactions(self, channel: Channel, random_user: Dict):
        msg = channel.send_message({"text": "hi"}, random_user["id"])
        response = channel.get_reactions(msg["message"]["id"])

        assert "reactions" in response
        assert len(response["reactions"]) == 0

        channel.send_reaction(msg["message"]["id"], {
            "type": "love",
            "count": 42
        }, random_user["id"])

        channel.send_reaction(msg["message"]["id"], {"type": "clap"},
                              random_user["id"])

        response = channel.get_reactions(msg["message"]["id"])
        assert len(response["reactions"]) == 2

        response = channel.get_reactions(msg["message"]["id"], offset=1)
        assert len(response["reactions"]) == 1

        assert response["reactions"][0]["count"] == 42
Ejemplo n.º 23
0
    def test_get_replies(self, channel: Channel, random_user: Dict):
        msg = channel.send_message({"text": "hi"}, random_user["id"])
        response = channel.get_replies(msg["message"]["id"])
        assert "messages" in response
        assert len(response["messages"]) == 0

        for i in range(10):
            channel.send_message(
                {
                    "text": "hi",
                    "index": i,
                    "parent_id": msg["message"]["id"]
                },
                random_user["id"],
            )

        response = channel.get_replies(msg["message"]["id"])
        assert "messages" in response
        assert len(response["messages"]) == 10

        response = channel.get_replies(msg["message"]["id"], limit=3, offset=3)
        assert "messages" in response
        assert len(response["messages"]) == 3
        assert response["messages"][0]["index"] == 7
Ejemplo n.º 24
0
 def channel(  # type: ignore
     self, channel_type: str, channel_id: str = None, data: Dict = None
 ) -> Channel:
     return Channel(self, channel_type, channel_id, data)
Ejemplo n.º 25
0
 def test_mark_read(self, channel: Channel, random_user: Dict):
     response = channel.mark_read(random_user["id"])
     assert "event" in response
     assert response["event"]["type"] == "message.read"
Ejemplo n.º 26
0
 def test_truncate(self, channel: Channel):
     response = channel.truncate()
     assert "channel" in response
Ejemplo n.º 27
0
 def test_delete(self, channel: Channel):
     response = channel.delete()
     assert "channel" in response
     assert response["channel"].get("deleted_at") is not None
Ejemplo n.º 28
0
 def test_update(self, channel: Channel):
     response = channel.update({"motd": "one apple a day..."})
     assert "channel" in response
     assert response["channel"]["motd"] == "one apple a day..."
Ejemplo n.º 29
0
 def test_send_event(self, channel: Channel, random_user: Dict):
     response = channel.send_event({"type": "typing.start"},
                                   random_user["id"])
     assert "event" in response
     assert response["event"]["type"] == "typing.start"
Ejemplo n.º 30
0
 def test_send_and_delete_file(self, channel: Channel, random_user: Dict):
     url = "helloworld.jpg"
     resp = channel.send_file(url, "helloworld.jpg", random_user)
     assert "helloworld.jpg" in resp["file"]
     channel.delete_file(resp["file"])