From 84f970185ade5e972f5b0eba312f57a4250ee685 Mon Sep 17 00:00:00 2001 From: Erwan Leroy Date: Tue, 5 Jul 2022 16:18:43 -0700 Subject: [PATCH 1/5] Replace non-ascii apostrophe with ascii character --- rocketchat_API/APISections/channels.py | 8 ++++---- rocketchat_API/APISections/groups.py | 14 +++++++------- rocketchat_API/APISections/im.py | 4 ++-- rocketchat_API/APISections/users.py | 10 +++++----- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/rocketchat_API/APISections/channels.py b/rocketchat_API/APISections/channels.py index 00ac562..2f411d5 100644 --- a/rocketchat_API/APISections/channels.py +++ b/rocketchat_API/APISections/channels.py @@ -14,7 +14,7 @@ def channels_list_joined(self, **kwargs): return self.call_api_get("channels.list.joined", kwargs=kwargs) def channels_info(self, room_id=None, channel=None, **kwargs): - """Gets a channel’s information.""" + """Gets a channel's information.""" if room_id: return self.call_api_get("channels.info", roomId=room_id, kwargs=kwargs) if channel: @@ -92,11 +92,11 @@ def channels_unarchive(self, room_id, **kwargs): return self.call_api_post("channels.unarchive", roomId=room_id, kwargs=kwargs) def channels_close(self, room_id, **kwargs): - """Removes the channel from the user’s list of channels.""" + """Removes the channel from the user's list of channels.""" return self.call_api_post("channels.close", roomId=room_id, kwargs=kwargs) def channels_open(self, room_id, **kwargs): - """Adds the channel back to the user’s list of channels.""" + """Adds the channel back to the user's list of channels.""" return self.call_api_post("channels.open", roomId=room_id, kwargs=kwargs) def channels_create(self, name, **kwargs): @@ -218,7 +218,7 @@ def channels_members(self, room_id=None, channel=None, **kwargs): raise RocketMissingParamException("room_id or channel required") def channels_roles(self, room_id=None, room_name=None, **kwargs): - """Lists all user’s roles in the channel.""" + """Lists all user's roles in the channel.""" if room_id: return self.call_api_get("channels.roles", roomId=room_id, kwargs=kwargs) if room_name: diff --git a/rocketchat_API/APISections/groups.py b/rocketchat_API/APISections/groups.py index a2c71e5..2f68a04 100644 --- a/rocketchat_API/APISections/groups.py +++ b/rocketchat_API/APISections/groups.py @@ -51,7 +51,7 @@ def groups_remove_owner(self, room_id, user_id, **kwargs): ) def groups_archive(self, room_id, **kwargs): - """Archives a private group, only if you’re part of the group.""" + """Archives a private group, only if you're part of the group.""" return self.call_api_post("groups.archive", roomId=room_id, kwargs=kwargs) def groups_unarchive(self, room_id, **kwargs): @@ -59,11 +59,11 @@ def groups_unarchive(self, room_id, **kwargs): return self.call_api_post("groups.unarchive", roomId=room_id, kwargs=kwargs) def groups_close(self, room_id, **kwargs): - """Removes the private group from the user’s list of groups, only if you’re part of the group.""" + """Removes the private group from the user's list of groups, only if you're part of the group.""" return self.call_api_post("groups.close", roomId=room_id, kwargs=kwargs) def groups_create(self, name, **kwargs): - """Creates a new private group, optionally including users, only if you’re part of the group.""" + """Creates a new private group, optionally including users, only if you're part of the group.""" return self.call_api_post("groups.create", name=name, kwargs=kwargs) def groups_get_integrations(self, room_id, **kwargs): @@ -73,7 +73,7 @@ def groups_get_integrations(self, room_id, **kwargs): ) def groups_info(self, room_id=None, room_name=None, **kwargs): - """GRetrieves the information about the private group, only if you’re part of the group.""" + """GRetrieves the information about the private group, only if you're part of the group.""" if room_id: return self.call_api_get("groups.info", roomId=room_id, kwargs=kwargs) if room_name: @@ -93,11 +93,11 @@ def groups_kick(self, room_id, user_id, **kwargs): ) def groups_leave(self, room_id, **kwargs): - """Causes the callee to be removed from the private group, if they’re part of it and are not the last owner.""" + """Causes the callee to be removed from the private group, if they're part of it and are not the last owner.""" return self.call_api_post("groups.leave", roomId=room_id, kwargs=kwargs) def groups_open(self, room_id, **kwargs): - """Adds the private group back to the user’s list of private groups.""" + """Adds the private group back to the user's list of private groups.""" return self.call_api_post("groups.open", roomId=room_id, kwargs=kwargs) def groups_rename(self, room_id, name, **kwargs): @@ -181,7 +181,7 @@ def groups_members(self, room_id=None, group=None, **kwargs): raise RocketMissingParamException("room_id or group required") def groups_roles(self, room_id=None, room_name=None, **kwargs): - """Lists all user’s roles in the private group.""" + """Lists all user's roles in the private group.""" if room_id: return self.call_api_get("groups.roles", roomId=room_id, kwargs=kwargs) if room_name: diff --git a/rocketchat_API/APISections/im.py b/rocketchat_API/APISections/im.py index af8d803..23ce35d 100644 --- a/rocketchat_API/APISections/im.py +++ b/rocketchat_API/APISections/im.py @@ -26,11 +26,11 @@ def im_create_multiple(self, usernames, **kwargs): ) def im_open(self, room_id, **kwargs): - """Adds the direct message back to the user’s list of direct messages.""" + """Adds the direct message back to the user's list of direct messages.""" return self.call_api_post("im.open", roomId=room_id, kwargs=kwargs) def im_close(self, room_id, **kwargs): - """Removes the direct message from the user’s list of direct messages.""" + """Removes the direct message from the user's list of direct messages.""" return self.call_api_post("im.close", roomId=room_id, kwargs=kwargs) def im_members(self, room_id, **kwargs): diff --git a/rocketchat_API/APISections/users.py b/rocketchat_API/APISections/users.py index 61fed16..2b1b586 100644 --- a/rocketchat_API/APISections/users.py +++ b/rocketchat_API/APISections/users.py @@ -11,7 +11,7 @@ def me(self, **kwargs): return self.call_api_get("me", kwargs=kwargs) def users_info(self, user_id=None, username=None, **kwargs): - """Gets a user’s information, limited to the caller’s permissions.""" + """Gets a user's information, limited to the caller's permissions.""" if user_id: return self.call_api_get("users.info", userId=user_id, kwargs=kwargs) if username: @@ -59,7 +59,7 @@ def users_register(self, email, name, password, username, **kwargs): ) def users_get_avatar(self, user_id=None, username=None, **kwargs): - """Gets the URL for a user’s avatar.""" + """Gets the URL for a user's avatar.""" if user_id: response = self.call_api_get( "users.getAvatar", userId=user_id, kwargs=kwargs @@ -84,7 +84,7 @@ def users_get_avatar(self, user_id=None, username=None, **kwargs): return response def users_set_avatar(self, avatar_url, **kwargs): - """Set a user’s avatar""" + """Set a user's avatar""" if avatar_url.startswith("http://") or avatar_url.startswith("https://"): return self.call_api_post( "users.setAvatar", avatarUrl=avatar_url, kwargs=kwargs @@ -101,7 +101,7 @@ def users_set_avatar(self, avatar_url, **kwargs): return self.call_api_post("users.setAvatar", files=avatar_file, kwargs=kwargs) def users_reset_avatar(self, user_id=None, username=None, **kwargs): - """Reset a user’s avatar""" + """Reset a user's avatar""" if user_id: return self.call_api_post( "users.resetAvatar", userId=user_id, kwargs=kwargs @@ -146,7 +146,7 @@ def users_get_preferences(self, **kwargs): return self.call_api_get("users.getPreferences", kwargs=kwargs) def users_set_preferences(self, user_id, data, **kwargs): - """Set user’s preferences.""" + """Set user's preferences.""" return self.call_api_post( "users.setPreferences", userId=user_id, data=data, kwargs=kwargs ) From 830d4dbd54a34c003a145b5a7c6bd1755f8ec2db Mon Sep 17 00:00:00 2001 From: Erwan Leroy Date: Tue, 5 Jul 2022 17:09:16 -0700 Subject: [PATCH 2/5] Replace f-strings with str.format() for python 2 backward compatibility --- rocketchat_API/APISections/livechat.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rocketchat_API/APISections/livechat.py b/rocketchat_API/APISections/livechat.py index 44e0ee5..446ceaa 100644 --- a/rocketchat_API/APISections/livechat.py +++ b/rocketchat_API/APISections/livechat.py @@ -18,19 +18,19 @@ def livechat_inquiries_take(self, inquiry_id, **kwargs): def livechat_get_users(self, user_type, **kwargs): """Get a list of agents or managers.""" - return self.call_api_get(f"livechat/users/{user_type}", kwargs=kwargs) + return self.call_api_get("livechat/users/{}".format(user_type), kwargs=kwargs) def livechat_create_user(self, user_type, **kwargs): """Register a new agent or manager.""" - return self.call_api_post(f"livechat/users/{user_type}", kwargs=kwargs) + return self.call_api_post("livechat/users/{}".format(user_type), kwargs=kwargs) def livechat_get_user(self, user_type, user_id, **kwargs): """Get info about an agent or manager.""" - return self.call_api_get(f"livechat/users/{user_type}/{user_id}", kwargs=kwargs) + return self.call_api_get("livechat/users/{}/{}".format(user_type, user_id), kwargs=kwargs) def livechat_delete_user(self, user_type, user_id): """Removes an agent or manager.""" - return self.call_api_delete(f"livechat/users/{user_type}/{user_id}") + return self.call_api_delete("livechat/users/{}/{}".format(user_type, user_id)) def livechat_register_visitor(self, token, **kwargs): """Register a new Livechat visitor.""" @@ -41,7 +41,7 @@ def livechat_register_visitor(self, token, **kwargs): def livechat_get_visitor(self, token): """Retrieve a visitor data.""" - return self.call_api_get(f"livechat/visitor/{token}") + return self.call_api_get("livechat/visitor/{}".format(token)) def livechat_room(self, token, **kwargs): """Get the Livechat room data or open a new room.""" @@ -56,5 +56,5 @@ def livechat_message(self, token, rid, msg, **kwargs): def livechat_messages_history(self, rid, token, **kwargs): """Load Livechat messages history.""" return self.call_api_get( - f"livechat/messages.history/{rid}", token=token, kwargs=kwargs + "livechat/messages.history/{}".format(rid), token=token, kwargs=kwargs ) From b61193f18fa2966c14f9527485970c16be883203 Mon Sep 17 00:00:00 2001 From: Erwan Leroy Date: Mon, 11 Jul 2022 14:58:55 -0700 Subject: [PATCH 3/5] Enable 2.7 tests, format code with black --- .github/workflows/build.yml | 2 +- rocketchat_API/APISections/livechat.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b10be69..7f6e356 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ '3.6', '3.7', '3.8', '3.9' ] + python-version: [ '2.7', '3.6', '3.7', '3.8', '3.9' ] steps: - name: Checkout uses: actions/checkout@v2.3.4 diff --git a/rocketchat_API/APISections/livechat.py b/rocketchat_API/APISections/livechat.py index 446ceaa..8208237 100644 --- a/rocketchat_API/APISections/livechat.py +++ b/rocketchat_API/APISections/livechat.py @@ -26,7 +26,9 @@ def livechat_create_user(self, user_type, **kwargs): def livechat_get_user(self, user_type, user_id, **kwargs): """Get info about an agent or manager.""" - return self.call_api_get("livechat/users/{}/{}".format(user_type, user_id), kwargs=kwargs) + return self.call_api_get( + "livechat/users/{}/{}".format(user_type, user_id), kwargs=kwargs + ) def livechat_delete_user(self, user_type, user_id): """Removes an agent or manager.""" From 739ebd40da008aa16e18b7762c575fa89f03ba96 Mon Sep 17 00:00:00 2001 From: Erwan Leroy Date: Mon, 11 Jul 2022 15:19:38 -0700 Subject: [PATCH 4/5] Skip black test when in the python 2.7 matrix --- .github/workflows/build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7f6e356..e8fb137 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,9 +27,13 @@ jobs: with: python-version: ${{ matrix.python-version }} - name: Install dependencies - run: pip install pytest-cov black requests + run: pip install pytest-cov requests + - name: Install black + run: pip install black + if: matrix.python-version != '2.7' # Black does not run on python 2.7 - name: Lint with black run: black --check . + if: matrix.python-version != '2.7' # Black does not run on python 2.7 - name: Wait for rocket.chat server to be online run: until curl --silent http://localhost:3000/api/info/; do sleep 15; echo "waiting for Rocket.Chat server to start"; done - name: Run tests From 1afa8d1550627041d898292bbe20d19aa84ba0d8 Mon Sep 17 00:00:00 2001 From: Erwan Leroy Date: Mon, 11 Jul 2022 15:22:57 -0700 Subject: [PATCH 5/5] Remove f-string from tests for 2.7 compatibility --- tests/test_user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_user.py b/tests/test_user.py index 85b493b..a67207c 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -140,7 +140,7 @@ def test_users_create_token(logged_rocket, user): def test_users_create_update_delete(logged_rocket, user): name = str(uuid.uuid1()) users_create = logged_rocket.users_create( - email=f"{name}@domain.com", + email="{}@domain.com".format(name), name=name, password=user.password, username=name,