Skip to content

Commit eb27b1f

Browse files
authored
Merge pull request #18 from GetStream/task/implement-invitations
implement invitations
2 parents 3556611 + 5796777 commit eb27b1f

File tree

3 files changed

+57
-11
lines changed

3 files changed

+57
-11
lines changed

stream_chat/channel.py

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

215-
def accept_invite(self, user_id):
216-
raise NotImplementedError
215+
def accept_invite(self, user_id, **data):
216+
payload = add_user_id(data, user_id)
217+
payload['accept_invite'] = True
218+
response = self.client.post(self.url, data=payload)
219+
self.custom_data = response['channel']
220+
return response
217221

218-
def reject_invite(self, user_id):
219-
raise NotImplementedError
222+
def reject_invite(self, user_id, **data):
223+
payload = add_user_id(data, user_id)
224+
payload['reject_invite'] = True
225+
response = self.client.post(self.url, data=payload)
226+
self.custom_data = response['channel']
227+
return response
220228

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

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):
@@ -122,15 +126,15 @@ def test_get_reactions(self, channel, random_user):
122126
assert response["reactions"][0]["count"] == 42
123127

124128
def test_send_and_delete_file(self, channel, random_user):
125-
url = "https://getstream.io/blog/wp-content/themes/stream-theme-wordpress_2018-05-24_10-41/assets/images/stream_logo.png";
126-
resp = channel.send_file(url, "logo.png", random_user)
127-
assert "logo.png" in resp['file']
129+
url = "https://homepages.cae.wisc.edu/~ece533/images/lena.png"
130+
resp = channel.send_file(url, "lena.png", random_user)
131+
assert "lena.png" in resp['file']
128132
resp = channel.delete_file(resp['file'])
129133

130134
def test_send_and_delete_image(self, channel, random_user):
131-
url = "https://getstream.io/blog/wp-content/themes/stream-theme-wordpress_2018-05-24_10-41/assets/images/stream_logo.png";
132-
resp = channel.send_image(url, "logo.png", random_user, content_type="image/png")
133-
assert "logo.png" in resp['file']
135+
url = "https://homepages.cae.wisc.edu/~ece533/images/lena.png"
136+
resp = channel.send_image(url, "lena.png", random_user, content_type="image/png")
137+
assert "lena.png" in resp['file']
134138
# resp = channel.delete_image(resp['file'])
135139

136140
def test_channel_hide_show(self, client, channel, random_users):
@@ -157,7 +161,37 @@ def test_channel_hide_show(self, client, channel, random_users):
157161
response = client.query_channels({"id": channel.id}, user_id=random_users[0]['id'])
158162
assert len(response['channels']) == 0
159163
# send message
160-
msg = channel.send_message({"text": "hi"}, random_users[1]["id"])
164+
channel.send_message({"text": "hi"}, random_users[1]["id"])
161165
# channel should be listed now
162166
response = client.query_channels({"id": channel.id}, user_id=random_users[0]['id'])
163167
assert len(response['channels']) == 1
168+
169+
def test_invites(self, client, channel):
170+
members = ["john", "paul", "george", "pete", "ringo", "eric"]
171+
client.update_users([{"id": m} for m in members])
172+
channel = client.channel(
173+
"team", "beatles-" + str(uuid.uuid4()), {
174+
"members": members,
175+
"invites": ["ringo", "eric"]
176+
})
177+
channel.create("john")
178+
# accept the invite when not a member
179+
with pytest.raises(StreamAPIException):
180+
channel.accept_invite("brian")
181+
# accept the invite when a member
182+
accept = channel.accept_invite("ringo")
183+
for m in accept['members']:
184+
if m['user_id'] == 'ringo':
185+
assert m['invited'] is True
186+
assert "invite_accepted_at" in m
187+
# cannot accept again
188+
with pytest.raises(StreamAPIException):
189+
channel.accept_invite("ringo")
190+
reject = channel.reject_invite("eric")
191+
for m in reject['members']:
192+
if m['user_id'] == 'eric':
193+
assert m['invited'] is True
194+
assert "invite_rejected_at" in m
195+
# cannot reject again
196+
with pytest.raises(StreamAPIException):
197+
reject = channel.reject_invite("eric")

0 commit comments

Comments
 (0)