Skip to content

Commit e7534b0

Browse files
committed
Merge remote-tracking branch 'origin/master' into feature/support-invites-after-channel-creation
2 parents 91e7a19 + eb27b1f commit e7534b0

File tree

9 files changed

+99
-35
lines changed

9 files changed

+99
-35
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ matrix:
55
- python: 3.5
66
- python: 3.6
77
- python: 3.7
8+
- python: 3.8
89
sudo: true
910
cache: pip
1011
install:

CHANGELOG

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Mar 3, 2020 - 1.1.
2+
- Add support for client.get_message
3+
4+
## Nov 7, 2019 - 1.0.2
5+
- Bump crypto requirements
6+
17
## Oct 21th, 2019 - 1.0.1
28
- Fixed app update method parameter passing
39

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
requests = "requests>=2.22.0,<3"
77

88
install_requires = [
9-
"pycryptodomex==3.8.1",
9+
"pycryptodomex>=3.8.1,<4",
1010
requests,
1111
"pyjwt==1.7.1",
1212
"six>=1.12.0",

stream_chat/__pkg__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__author__ = "Tommaso Barbugli"
22
__copyright__ = "Copyright 2019, Stream.io, Inc"
3-
__version__ = "1.0.1"
3+
__version__ = "1.1.1"
44
__maintainer__ = "Tommaso Barbugli"
55
__email__ = "[email protected]"
66
__status__ = "Production"

stream_chat/channel.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,19 @@ def unban_user(self, target_id, **options):
221221
target_id, type=self.channel_type, id=self.id, **options
222222
)
223223

224-
def accept_invite(self, user_id):
225-
raise NotImplementedError
224+
def accept_invite(self, user_id, **data):
225+
payload = add_user_id(data, user_id)
226+
payload['accept_invite'] = True
227+
response = self.client.post(self.url, data=payload)
228+
self.custom_data = response['channel']
229+
return response
226230

227-
def reject_invite(self, user_id):
228-
raise NotImplementedError
231+
def reject_invite(self, user_id, **data):
232+
payload = add_user_id(data, user_id)
233+
payload['reject_invite'] = True
234+
response = self.client.post(self.url, data=payload)
235+
self.custom_data = response['channel']
236+
return response
229237

230238
def send_file(self, url, name, user, content_type=None):
231239
return self.client.send_file("{}/file".format(self.url), url, name, user, content_type=content_type)

stream_chat/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def create_token(self, user_id, exp=None):
9292
payload = {"user_id": user_id}
9393
if exp is not None:
9494
payload["exp"] = exp
95-
return jwt.encode(payload, self.api_secret, algorithm="HS256")
95+
return jwt.encode(payload, self.api_secret, algorithm="HS256").decode()
9696

9797
def update_app_settings(self, **settings):
9898
return self.patch("app", data=settings)
@@ -188,6 +188,9 @@ def update_message(self, message):
188188
def delete_message(self, message_id, **options):
189189
return self.delete("messages/{}".format(message_id), options)
190190

191+
def get_message(self, message_id):
192+
return self.get("messages/{}".format(message_id))
193+
191194
def query_users(self, filter_conditions, sort=None, **options):
192195
sort_fields = []
193196
if sort is not None:

stream_chat/tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def pytest_runtest_setup(item):
1818
if previousfailed is not None:
1919
pytest.xfail("previous test failed (%s)" % previousfailed.name)
2020

21+
def pytest_configure(config):
22+
config.addinivalue_line(
23+
"markers", "incremental: mark test incremental"
24+
)
2125

2226
@pytest.fixture(scope="module")
2327
def client():

stream_chat/tests/test_channel.py

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import uuid
2+
13
import pytest
24

5+
from stream_chat.exceptions import StreamAPIException
6+
37

48
@pytest.mark.incremental
59
class TestChannel(object):
@@ -130,15 +134,15 @@ def test_get_reactions(self, channel, random_user):
130134
assert response["reactions"][0]["count"] == 42
131135

132136
def test_send_and_delete_file(self, channel, random_user):
133-
url = "https://getstream.io/blog/wp-content/themes/stream-theme-wordpress_2018-05-24_10-41/assets/images/stream_logo.png";
134-
resp = channel.send_file(url, "logo.png", random_user)
135-
assert "logo.png" in resp['file']
137+
url = "https://homepages.cae.wisc.edu/~ece533/images/lena.png"
138+
resp = channel.send_file(url, "lena.png", random_user)
139+
assert "lena.png" in resp['file']
136140
resp = channel.delete_file(resp['file'])
137141

138142
def test_send_and_delete_image(self, channel, random_user):
139-
url = "https://getstream.io/blog/wp-content/themes/stream-theme-wordpress_2018-05-24_10-41/assets/images/stream_logo.png";
140-
resp = channel.send_image(url, "logo.png", random_user, content_type="image/png")
141-
assert "logo.png" in resp['file']
143+
url = "https://homepages.cae.wisc.edu/~ece533/images/lena.png"
144+
resp = channel.send_image(url, "lena.png", random_user, content_type="image/png")
145+
assert "lena.png" in resp['file']
142146
# resp = channel.delete_image(resp['file'])
143147

144148
def test_channel_hide_show(self, client, channel, random_users):
@@ -165,7 +169,37 @@ def test_channel_hide_show(self, client, channel, random_users):
165169
response = client.query_channels({"id": channel.id}, user_id=random_users[0]['id'])
166170
assert len(response['channels']) == 0
167171
# send message
168-
msg = channel.send_message({"text": "hi"}, random_users[1]["id"])
172+
channel.send_message({"text": "hi"}, random_users[1]["id"])
169173
# channel should be listed now
170174
response = client.query_channels({"id": channel.id}, user_id=random_users[0]['id'])
171175
assert len(response['channels']) == 1
176+
177+
def test_invites(self, client, channel):
178+
members = ["john", "paul", "george", "pete", "ringo", "eric"]
179+
client.update_users([{"id": m} for m in members])
180+
channel = client.channel(
181+
"team", "beatles-" + str(uuid.uuid4()), {
182+
"members": members,
183+
"invites": ["ringo", "eric"]
184+
})
185+
channel.create("john")
186+
# accept the invite when not a member
187+
with pytest.raises(StreamAPIException):
188+
channel.accept_invite("brian")
189+
# accept the invite when a member
190+
accept = channel.accept_invite("ringo")
191+
for m in accept['members']:
192+
if m['user_id'] == 'ringo':
193+
assert m['invited'] is True
194+
assert "invite_accepted_at" in m
195+
# cannot accept again
196+
with pytest.raises(StreamAPIException):
197+
channel.accept_invite("ringo")
198+
reject = channel.reject_invite("eric")
199+
for m in reject['members']:
200+
if m['user_id'] == 'eric':
201+
assert m['invited'] is True
202+
assert "invite_rejected_at" in m
203+
# cannot reject again
204+
with pytest.raises(StreamAPIException):
205+
reject = channel.reject_invite("eric")

stream_chat/tests/test_client.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ def test_mute_user(self, client, random_users):
1414
assert response["mute"]["user"]["id"] == random_users[1]["id"]
1515
client.unmute_user(random_users[0]["id"], random_users[1]["id"])
1616

17+
def test_get_message(self, client, channel, random_user):
18+
msg_id = str(uuid.uuid4())
19+
channel.send_message({"id": msg_id, "text": "helloworld"}, random_user["id"])
20+
client.delete_message(msg_id)
21+
msg_id = str(uuid.uuid4())
22+
channel.send_message({"id": msg_id, "text": "helloworld"}, random_user["id"])
23+
message = client.get_message(msg_id)
24+
assert message["message"]["id"] == msg_id
25+
1726
def test_auth_exception(self):
1827
client = StreamChat(api_key="bad", api_secret="guy")
1928
with pytest.raises(StreamAPIException):
@@ -34,6 +43,7 @@ def test_update_channel_type(self, client):
3443

3544
def test_create_token(self, client):
3645
token = client.create_token("tommaso")
46+
assert type(token) is str
3747
payload = jwt.decode(token, client.api_secret, algorithms=["HS256"])
3848
assert payload.get("user_id") == "tommaso"
3949

@@ -56,13 +66,10 @@ def test_update_users(self, client):
5666
def test_update_user_partial(self, client):
5767
user_id = str(uuid.uuid4())
5868
client.update_user({"id": user_id, "field": "value"})
59-
60-
response = client.update_user_partial({
61-
"id": user_id,
62-
"set": {
63-
"field": "updated"
64-
}
65-
})
69+
70+
response = client.update_user_partial(
71+
{"id": user_id, "set": {"field": "updated"}}
72+
)
6673

6774
assert "users" in response
6875
assert user_id in response["users"]
@@ -129,7 +136,7 @@ def test_delete_message(self, client, channel, random_user):
129136
client.delete_message(msg_id)
130137
msg_id = str(uuid.uuid4())
131138
channel.send_message({"id": msg_id, "text": "helloworld"}, random_user["id"])
132-
resp = client.delete_message(msg_id, hard=True)
139+
client.delete_message(msg_id, hard=True)
133140

134141
def test_flag_message(self, client, channel, random_user, server_user):
135142
msg_id = str(uuid.uuid4())
@@ -163,26 +170,27 @@ def test_devices(self, client, random_user):
163170

164171
def test_search(self, client, channel, random_user):
165172
query = "supercalifragilisticexpialidocious"
166-
channel.send_message({"text": "How many syllables are there in {}?".format(query)}, random_user['id'])
167-
channel.send_message({"text": "Does 'cious' count as one or two?"}, random_user['id'])
173+
channel.send_message(
174+
{"text": "How many syllables are there in {}?".format(query)},
175+
random_user["id"],
176+
)
177+
channel.send_message(
178+
{"text": "Does 'cious' count as one or two?"}, random_user["id"]
179+
)
168180
response = client.search(
169-
{"type": "messaging"},
170-
query,
171-
**{"limit": 2, "offset": 0}
181+
{"type": "messaging"}, query, **{"limit": 2, "offset": 0}
172182
)
173183
# searches all channels so make sure at least one is found
174-
assert len(response['results']) >= 1
175-
assert query in response['results'][0]['message']['text']
184+
assert len(response["results"]) >= 1
185+
assert query in response["results"][0]["message"]["text"]
176186
response = client.search(
177-
{"type": "messaging"},
178-
"cious",
179-
**{"limit": 12, "offset": 0})
180-
for message in response['results']:
181-
assert query not in message['message']['text']
187+
{"type": "messaging"}, "cious", **{"limit": 12, "offset": 0}
188+
)
189+
for message in response["results"]:
190+
assert query not in message["message"]["text"]
182191

183192
def test_query_channels_members_in(self, client, fellowship_of_the_ring):
184193
response = client.query_channels({"members": {"$in": ["gimli"]}}, {"id": 1})
185194
assert len(response["channels"]) == 1
186195
assert response["channels"][0]["channel"]["id"] == "fellowship-of-the-ring"
187196
assert len(response["channels"][0]["members"]) == 9
188-

0 commit comments

Comments
 (0)