Skip to content

Commit c74e4be

Browse files
authored
Set base url to edge (#70)
* Set base url to edge * Drop namespace for updates in campaigns * Fix uploads * Add test file
1 parent 865acf3 commit c74e4be

File tree

6 files changed

+30
-46
lines changed

6 files changed

+30
-46
lines changed

helloworld.jpg

16.8 KB
Loading

stream_chat/async_chat/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ async def update_segment(self, segment_id, data):
483483
"""
484484
Update a segment by id
485485
"""
486-
return await self.put(f"segments/{segment_id}", data={"segment": data})
486+
return await self.put(f"segments/{segment_id}", data=data)
487487

488488
async def delete_segment(self, segment_id):
489489
"""
@@ -507,13 +507,13 @@ async def list_campaigns(self, **params):
507507
"""
508508
List campaigns
509509
"""
510-
return await self.get("campaigns/", params)
510+
return await self.get("campaigns", params)
511511

512512
async def update_campaign(self, campaign_id, data):
513513
"""
514514
Update a campaign
515515
"""
516-
return await self.put(f"campaigns/{campaign_id}", data={"campaign": data})
516+
return await self.put(f"campaigns/{campaign_id}", data=data)
517517

518518
async def delete_campaign(self, campaign_id):
519519
"""

stream_chat/base/client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ def __init__(self, api_key, api_secret, timeout=6.0, **options):
1515
self.api_secret = api_secret
1616
self.timeout = timeout
1717
self.options = options
18-
self.base_url = options.get(
19-
"base_url", "https://chat-us-east-1.stream-io-api.com"
20-
)
18+
self.base_url = options.get("base_url", "https://chat.stream-io-api.com")
2119
self.auth_token = jwt.encode(
2220
{"server": True}, self.api_secret, algorithm="HS256"
2321
)

stream_chat/client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,12 @@ def send_file(self, uri, url, name, user, content_type=None):
319319
}
320320
parts = urlparse(url)
321321
if parts[0] == "":
322-
url = "file://" + url
323-
content = urlopen(Request(url, headers={"User-Agent": "Mozilla/5.0"})).read()
322+
with open(url, "rb") as f:
323+
content = f.read()
324+
else:
325+
content = urlopen(
326+
Request(url, headers={"User-Agent": "Mozilla/5.0"})
327+
).read()
324328
response = requests.post(
325329
f"{self.base_url}/{uri}",
326330
params=self.get_default_params(),
@@ -471,7 +475,7 @@ def update_segment(self, segment_id, data):
471475
"""
472476
Update a segment by id
473477
"""
474-
return self.put(f"segments/{segment_id}", data={"segment": data})
478+
return self.put(f"segments/{segment_id}", data=data)
475479

476480
def delete_segment(self, segment_id):
477481
"""
@@ -501,7 +505,7 @@ def update_campaign(self, campaign_id, data):
501505
"""
502506
Update a campaign
503507
"""
504-
return self.put(f"campaigns/{campaign_id}", data={"campaign": data})
508+
return self.put(f"campaigns/{campaign_id}", data=data)
505509

506510
def delete_campaign(self, campaign_id):
507511
"""

stream_chat/tests/async_chat/test_channel.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import uuid
2-
32
import pytest
43

54
from stream_chat.base.exceptions import StreamAPIException
@@ -29,7 +28,7 @@ async def test_create_without_id(self, event_loop, client, random_users):
2928
assert channel.id is not None
3029

3130
@pytest.mark.asyncio
32-
async def test_send_message_with_optinos(self, event_loop, channel, random_user):
31+
async def test_send_message_with_options(self, event_loop, channel, random_user):
3332
response = await channel.send_message(
3433
{"text": "hi"}, random_user["id"], skip_push=True
3534
)
@@ -175,29 +174,19 @@ async def test_get_reactions(self, event_loop, channel, random_user):
175174

176175
@pytest.mark.asyncio
177176
async def test_send_and_delete_file(self, event_loop, channel, random_user):
178-
url = "https://homepages.cae.wisc.edu/~ece533/images/lena.png"
179-
resp = await channel.send_file(url, "lena.png", random_user)
180-
assert "lena.png" in resp["file"]
181-
resp = await channel.delete_file(resp["file"])
177+
url = "helloworld.jpg"
178+
resp = await channel.send_file(url, "helloworld.jpg", random_user)
179+
assert "helloworld.jpg" in resp["file"]
180+
await channel.delete_file(resp["file"])
182181

183182
@pytest.mark.asyncio
184183
async def test_send_and_delete_image(self, event_loop, channel, random_user):
185-
url = "https://homepages.cae.wisc.edu/~ece533/images/lena.png"
186-
resp = await channel.send_image(
187-
url, "lena.png", random_user, content_type="image/png"
188-
)
189-
assert "lena.png" in resp["file"]
190-
# resp = channel.delete_image(resp['file'])
191-
192-
@pytest.mark.asyncio
193-
async def test_send_image_with_bot_blocked(self, event_loop, channel, random_user):
194-
# following url blocks bots and we set a generic header to skip it
195-
# but it can start failing again, see initial discussion here: https://github.com/GetStream/stream-chat-python/pull/30#discussion_r444209891
196-
url = "https://api.twilio.com/2010-04-01/Accounts/AC3e136e1a00279f4dadcb10a9f1a1e8a3/Messages/MM547edf6f4846a30231c3033fa20f8419/Media/ME498020f8fe0b0ba2ff83ac99e4782e02"
184+
url = "helloworld.jpg"
197185
resp = await channel.send_image(
198-
url, "js.png", random_user, content_type="image/png"
186+
url, "helloworld.jpg", random_user, content_type="image/jpeg"
199187
)
200-
assert "js.png" in resp["file"]
188+
assert "helloworld.jpg" in resp["file"]
189+
await channel.delete_image(resp["file"])
201190

202191
@pytest.mark.asyncio
203192
async def test_channel_hide_show(self, event_loop, client, channel, random_users):

stream_chat/tests/test_channel.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_create_without_id(self, client, random_users):
2626
channel.create(random_users[0]["id"])
2727
assert channel.id is not None
2828

29-
def test_send_message_with_optinos(self, channel, random_user):
29+
def test_send_message_with_options(self, channel, random_user):
3030
response = channel.send_message(
3131
{"text": "hi"}, random_user["id"], skip_push=True
3232
)
@@ -152,25 +152,18 @@ def test_get_reactions(self, channel, random_user):
152152
assert response["reactions"][0]["count"] == 42
153153

154154
def test_send_and_delete_file(self, channel, random_user):
155-
url = "https://homepages.cae.wisc.edu/~ece533/images/lena.png"
156-
resp = channel.send_file(url, "lena.png", random_user)
157-
assert "lena.png" in resp["file"]
158-
resp = channel.delete_file(resp["file"])
155+
url = "helloworld.jpg"
156+
resp = channel.send_file(url, "helloworld.jpg", random_user)
157+
assert "helloworld.jpg" in resp["file"]
158+
channel.delete_file(resp["file"])
159159

160160
def test_send_and_delete_image(self, channel, random_user):
161-
url = "https://homepages.cae.wisc.edu/~ece533/images/lena.png"
161+
url = "helloworld.jpg"
162162
resp = channel.send_image(
163-
url, "lena.png", random_user, content_type="image/png"
163+
url, "helloworld.jpg", random_user, content_type="image/jpeg"
164164
)
165-
assert "lena.png" in resp["file"]
166-
# resp = channel.delete_image(resp['file'])
167-
168-
def test_send_image_with_bot_blocked(self, channel, random_user):
169-
# following url blocks bots and we set a generic header to skip it
170-
# but it can start failing again, see initial discussion here: https://github.com/GetStream/stream-chat-python/pull/30#discussion_r444209891
171-
url = "https://api.twilio.com/2010-04-01/Accounts/AC3e136e1a00279f4dadcb10a9f1a1e8a3/Messages/MM547edf6f4846a30231c3033fa20f8419/Media/ME498020f8fe0b0ba2ff83ac99e4782e02"
172-
resp = channel.send_image(url, "js.png", random_user, content_type="image/png")
173-
assert "js.png" in resp["file"]
165+
assert "helloworld.jpg" in resp["file"]
166+
channel.delete_image(resp["file"])
174167

175168
def test_channel_hide_show(self, client, channel, random_users):
176169
# setup

0 commit comments

Comments
 (0)