Skip to content

Commit 5154abb

Browse files
committed
remove f-format
1 parent 52d94d6 commit 5154abb

File tree

5 files changed

+31
-29
lines changed

5 files changed

+31
-29
lines changed

stream_chat/channel.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, client, channel_type, channel_id=None, custom_data=None):
1414
def url(self):
1515
if self.id is None:
1616
raise StreamChannelException("channel does not have an id")
17-
return f"channels/{self.channel_type}/{self.id}"
17+
return "channels/{}/{}".format(self.channel_type, self.id)
1818

1919
def send_message(self, message, user_id):
2020
"""
@@ -25,7 +25,7 @@ def send_message(self, message, user_id):
2525
:return: the Server Response
2626
"""
2727
payload = {"message": add_user_id(message, user_id)}
28-
return self.client.post(f"{self.url}/message", data=payload)
28+
return self.client.post("{}/message".format(self.url), data=payload)
2929

3030
def send_event(self, event, user_id):
3131
"""
@@ -36,7 +36,7 @@ def send_event(self, event, user_id):
3636
:return: the Server Response
3737
"""
3838
payload = {"event": add_user_id(event, user_id)}
39-
return self.client.post(f"{self.url}/event", data=payload)
39+
return self.client.post("{}/event".format(self.url), data=payload)
4040

4141
def send_reaction(self, message_id, reaction, user_id):
4242
"""
@@ -48,7 +48,7 @@ def send_reaction(self, message_id, reaction, user_id):
4848
:return: the Server Response
4949
"""
5050
payload = {"reaction": add_user_id(reaction, user_id)}
51-
return self.client.post(f"messages/{message_id}/reaction", data=payload)
51+
return self.client.post("messages/{}/reaction".format(message_id), data=payload)
5252

5353
def delete_reaction(self, message_id, reaction_type, user_id):
5454
"""
@@ -60,7 +60,7 @@ def delete_reaction(self, message_id, reaction_type, user_id):
6060
:return: the Server Response
6161
"""
6262
return self.client.delete(
63-
f"messages/{message_id}/reaction/{reaction_type}",
63+
"messages/{}/reaction/{}".format(message_id, reaction_type),
6464
params={"user_id": user_id},
6565
)
6666

@@ -84,11 +84,11 @@ def query(self, **options):
8484
payload = {"state": True, "data": self.custom_data}
8585
payload.update(options)
8686

87-
url = f"channels/{self.channel_type}"
87+
url = "channels/{}".format(self.channel_type)
8888
if self.id is not None:
89-
url = f"{url}/{self.id}"
89+
url = "{}/{}".format(url, self.id)
9090

91-
state = self.client.post(f"{url}/query", data=payload)
91+
state = self.client.post("{}/query".format(url), data=payload)
9292

9393
if self.id is None:
9494
self.id = state["channel"]["id"]
@@ -120,7 +120,7 @@ def truncate(self):
120120
121121
:return: The server response
122122
"""
123-
return self.client.post(f"{self.url}/truncate")
123+
return self.client.post("{}/truncate".format(self.url))
124124

125125
def add_members(self, user_ids):
126126
"""
@@ -167,7 +167,7 @@ def mark_read(self, user_id, **data):
167167
:return: The server response
168168
"""
169169
payload = add_user_id(data, user_id)
170-
return self.client.post(f"{self.url}/read", data=payload)
170+
return self.client.post("{}/read".format(self.url), data=payload)
171171

172172
def get_replies(self, parent_id, **options):
173173
"""
@@ -177,17 +177,17 @@ def get_replies(self, parent_id, **options):
177177
:param options: Pagination params, ie {limit:10, idlte: 10}
178178
:return: A response with a list of messages
179179
"""
180-
return self.client.get(f"messages/{parent_id}/replies", params=options)
180+
return self.client.get("messages/{}/replies".format(parent_id), params=options)
181181

182182
def get_reactions(self, message_id, **options):
183183
"""
184184
List the reactions, supports pagination
185185
186-
:param message_id: Tthe message id
186+
:param message_id: The message id
187187
:param options: Pagination params, ie {"limit":10, "idlte": 10}
188188
:return: A response with a list of reactions
189189
"""
190-
return self.client.get(f"messages/{message_id}/reactions", params=options)
190+
return self.client.get("messages/{}/reactions".format(message_id), params=options)
191191

192192
def ban_user(self, user_id, **options):
193193
"""

stream_chat/client.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _make_request(self, method, relative_url, params=None, data=None):
5959
headers["Authorization"] = self.auth_token
6060
headers["stream-auth-type"] = "jwt"
6161

62-
url = "%s/%s" % (self.base_url, relative_url)
62+
url = "{}/{}".format(self.base_url, relative_url)
6363

6464
if method.__name__ in ["post", "put", "patch"]:
6565
serialized = json.dumps(data)
@@ -107,13 +107,13 @@ def update_user(self, user):
107107
return self.update_users([user])
108108

109109
def delete_user(self, user_id, **options):
110-
return self.delete(f"users/{user_id}", options)
110+
return self.delete("users/{}".format(user_id), options)
111111

112112
def deactivate_user(self, user_id, **options):
113-
return self.post(f"users/{user_id}/deactivate", options)
113+
return self.post("users/{}/deactivate".format(user_id), options)
114114

115115
def export_user(self, user_id, **options):
116-
return self.get(f"users/{user_id}/export", options)
116+
return self.get("users/{}/export".format(user_id), options)
117117

118118
def ban_user(self, target_id, **options):
119119
data = dict(target_user_id=target_id)
@@ -154,10 +154,10 @@ def mark_all_read(self, user_id):
154154
def update_message(self, message):
155155
if message.get("id") is None:
156156
raise ValueError("message must have an id")
157-
return self.post(f"messages/{message['id']}", data={"message": message})
157+
return self.post("messages/{}".format(message['id']), data={"message": message})
158158

159159
def delete_message(self, message_id):
160-
return self.delete(f"messages/{message_id}")
160+
return self.delete("messages/{}".format(message_id))
161161

162162
def query_users(self, filter_conditions, sort=None, **options):
163163
sort_fields = []
@@ -182,13 +182,13 @@ def create_channel_type(self, data):
182182
return self.post("channeltypes", data=data)
183183

184184
def get_channel_type(self, channel_type):
185-
return self.get(f"channeltypes/{channel_type}")
185+
return self.get("channeltypes/{}".format(channel_type))
186186

187187
def list_channel_types(self):
188188
return self.get("channeltypes")
189189

190190
def update_channel_type(self, channel_type, **settings):
191-
return self.put(f"channeltypes/{channel_type}", **settings)
191+
return self.put("channeltypes/{}".format(channel_type), **settings)
192192

193193
def delete_channel_type(self, channel_type):
194194
"""
@@ -197,7 +197,7 @@ def delete_channel_type(self, channel_type):
197197
:param channel_type: the channel type
198198
:return:
199199
"""
200-
return self.delete(f"channeltypes/{channel_type}")
200+
return self.delete("channeltypes/{}".format(channel_type))
201201

202202
def channel(self, channel_type, channel_id=None, data=None):
203203
"""

stream_chat/exceptions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
from json import JSONDecodeError
32

43

@@ -23,6 +22,6 @@ def __init__(self, response):
2322

2423
def __str__(self):
2524
if self.json_response:
26-
return f"StreamChat error code {self.error_code}: {self.error_message}"
25+
return "StreamChat error code {}: {}".format(self.error_code, self.error_message)
2726
else:
28-
return f"StreamChat error HTTP code: {self.response.status_code}"
27+
return "StreamChat error HTTP code: {}".format(self.response.status_code)

stream_chat/tests/test_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import jwt
22
import pytest
33
import uuid
4+
from stream_chat import StreamChat
5+
from stream_chat.exceptions import StreamAPIException
46

57

68
@pytest.mark.incremental
@@ -12,6 +14,11 @@ def test_mute_user(self, client, random_users):
1214
assert response["mute"]["user"]["id"] == random_users[1]["id"]
1315
client.unmute_user(random_users[0]["id"], random_users[1]["id"])
1416

17+
def test_auth_exception(self):
18+
client = StreamChat(api_key="bad", api_secret="guy")
19+
with pytest.raises(StreamAPIException):
20+
client.get_channel_type("team")
21+
1522
def test_get_channel_types(self, client):
1623
response = client.get_channel_type("team")
1724
assert "permissions" in response

stream_chat/types.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)