Skip to content

Commit 772fdb8

Browse files
authored
Custom command crud (#38)
1 parent d28816a commit 772fdb8

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ secrets.*sh
5959
.venv
6060
pip-selfcheck.json
6161
.idea
62-
62+
.vscode
6363
*,cover
6464
.eggs

stream_chat/client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,21 @@ def channel(self, channel_type, channel_id=None, data=None):
239239
"""
240240
return Channel(self, channel_type, channel_id, data)
241241

242+
def list_commands(self):
243+
return self.get("commands")
244+
245+
def create_command(self, data):
246+
return self.post("commands", data=data)
247+
248+
def delete_command(self, name):
249+
return self.delete("commands/{}".format(name))
250+
251+
def get_command(self, name):
252+
return self.get("commands/{}".format(name))
253+
254+
def update_command(self, name, **settings):
255+
return self.put("commands/{}".format(name), data=settings)
256+
242257
def add_device(self, device_id, push_provider, user_id):
243258
"""
244259
Add a device to a user

stream_chat/tests/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ def pytest_configure(config):
2525

2626
@pytest.fixture(scope="module")
2727
def client():
28+
base_url = os.environ.get("STREAM_HOST")
29+
options = {"base_url": base_url} if base_url else {}
2830
return StreamChat(
2931
api_key=os.environ["STREAM_KEY"],
3032
api_secret=os.environ["STREAM_SECRET"],
3133
timeout=10,
34+
**options,
3235
)
3336

3437

@@ -67,6 +70,15 @@ def channel(client, random_user):
6770
return channel
6871

6972

73+
@pytest.fixture(scope="function")
74+
def command(client):
75+
response = client.create_command(
76+
dict(name=str(uuid.uuid4()), description="My command")
77+
)
78+
79+
return response["command"]
80+
81+
7082
@pytest.fixture(scope="module")
7183
def fellowship_of_the_ring(client):
7284
members = [

stream_chat/tests/test_client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ def test_update_channel_type(self, client):
5252
assert "commands" in response
5353
assert response["commands"] == ["ban", "unban"]
5454

55+
def test_get_command(self, client, command):
56+
response = client.get_command(command["name"])
57+
assert command["name"] == response["name"]
58+
59+
def test_update_command(self, client, command):
60+
response = client.update_command(command["name"], description="My new command")
61+
assert "command" in response
62+
assert "My new command" == response["command"]["description"]
63+
64+
def test_delete_command(self, client, command):
65+
response = client.delete_command(command["name"])
66+
with pytest.raises(StreamAPIException):
67+
client.get_command(command["name"])
68+
69+
def test_list_commands(self, client):
70+
response = client.list_commands()
71+
assert "commands" in response
72+
5573
def test_create_token(self, client):
5674
token = client.create_token("tommaso")
5775
assert type(token) is str

0 commit comments

Comments
 (0)