Skip to content

Commit 9bcf5e6

Browse files
authored
Add custom_user_status API section (#378)
1 parent 0cae9ca commit 9bcf5e6

3 files changed

Lines changed: 113 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from rocketchat_API.APISections.base import RocketChatBase
2+
3+
4+
class RocketChatCustomUserStatus(RocketChatBase):
5+
def custom_user_status_list(self, **kwargs):
6+
"""Lists all available custom user's status."""
7+
return self.call_api_get("custom-user-status.list", kwargs=kwargs)
8+
9+
def custom_user_status_create(self, name, status_type, **kwargs):
10+
"""Creates custom user status.
11+
12+
:param name: The name of the custom status.
13+
:param status_type: The statusType of the custom status. Valid status type includes: Online, Busy, Away, Offline.
14+
"""
15+
return self.call_api_post(
16+
"custom-user-status.create",
17+
name=name,
18+
statusType=status_type,
19+
kwargs=kwargs,
20+
)
21+
22+
def custom_user_status_delete(self, custom_user_status_id, **kwargs):
23+
"""Deletes a custom user status."""
24+
return self.call_api_post(
25+
"custom-user-status.delete",
26+
customUserStatusId=custom_user_status_id,
27+
kwargs=kwargs,
28+
)
29+
30+
def custom_user_status_update(
31+
self, custom_user_status_id, name, status_type, **kwargs
32+
):
33+
"""Updates a custom user status."""
34+
return self.call_api_post(
35+
"custom-user-status.update",
36+
_id=custom_user_status_id,
37+
name=name,
38+
statusType=status_type,
39+
kwargs=kwargs,
40+
)

rocketchat_API/rocketchat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from rocketchat_API.APISections.chat import RocketChatChat
77
from rocketchat_API.APISections.dm import RocketChatDM
88
from rocketchat_API.APISections.custom_emoji import RocketChatCustomEmoji
9+
from rocketchat_API.APISections.custom_user_status import RocketChatCustomUserStatus
910
from rocketchat_API.APISections.groups import RocketChatGroups
1011
from rocketchat_API.APISections.integrations import RocketChatIntegrations
1112
from rocketchat_API.APISections.invites import RocketChatInvites
@@ -31,6 +32,7 @@ class RocketChat(
3132
RocketChatChat,
3233
RocketChatDM,
3334
RocketChatCustomEmoji,
35+
RocketChatCustomUserStatus,
3436
RocketChatGroups,
3537
RocketChatIntegrations,
3638
RocketChatInvites,

tests/test_custom_user_status.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import uuid
2+
3+
import pytest
4+
5+
6+
@pytest.fixture
7+
def status_name():
8+
return "test_status_" + str(uuid.uuid1()).replace("-", "")[:12]
9+
10+
11+
@pytest.fixture
12+
def created_status(logged_rocket, status_name):
13+
result = logged_rocket.custom_user_status_create(
14+
name=status_name, status_type="online"
15+
)
16+
status = result.get("customUserStatus")
17+
assert status is not None
18+
19+
yield status
20+
21+
logged_rocket.custom_user_status_delete(custom_user_status_id=status["_id"])
22+
23+
24+
def test_custom_user_status_list(logged_rocket, created_status):
25+
result = logged_rocket.custom_user_status_list()
26+
assert "statuses" in result
27+
found = any(s["_id"] == created_status["_id"] for s in result["statuses"])
28+
assert found
29+
30+
31+
def test_custom_user_status_create_delete(logged_rocket):
32+
name = "test_status_" + str(uuid.uuid1()).replace("-", "")[:12]
33+
result = logged_rocket.custom_user_status_create(name=name, status_type="busy")
34+
status = result.get("customUserStatus")
35+
assert status is not None
36+
assert status["name"] == name
37+
assert status["statusType"] == "busy"
38+
39+
logged_rocket.custom_user_status_delete(custom_user_status_id=status["_id"])
40+
41+
statuses = logged_rocket.custom_user_status_list().get("statuses", [])
42+
assert not any(s["_id"] == status["_id"] for s in statuses)
43+
44+
45+
def test_custom_user_status_update(logged_rocket, created_status):
46+
new_name = created_status["name"] + "_upd"
47+
result = logged_rocket.custom_user_status_update(
48+
custom_user_status_id=created_status["_id"],
49+
name=new_name,
50+
status_type="away",
51+
)
52+
updated = result.get("customUserStatus")
53+
assert updated is not None
54+
assert updated["name"] == new_name
55+
assert updated["statusType"] == "away"
56+
57+
58+
def test_custom_user_status_create_all_types(logged_rocket):
59+
created_ids = []
60+
for status_type in ("online", "busy", "away", "offline"):
61+
name = "test_" + status_type + "_" + str(uuid.uuid1()).replace("-", "")[:8]
62+
result = logged_rocket.custom_user_status_create(
63+
name=name, status_type=status_type
64+
)
65+
status = result.get("customUserStatus")
66+
assert status is not None
67+
assert status["statusType"] == status_type
68+
created_ids.append(status["_id"])
69+
70+
for sid in created_ids:
71+
logged_rocket.custom_user_status_delete(custom_user_status_id=sid)

0 commit comments

Comments
 (0)