From 2229b68f06a9623e82b0c42a86f18f257be04903 Mon Sep 17 00:00:00 2001 From: Kirill Shtrykov Date: Tue, 19 Jun 2018 15:27:31 +0300 Subject: [PATCH 1/7] Add create/delete public rooms functions --- README.md | 2 ++ rocketchat/api.py | 22 ++++++++++++ .../calls/channels/create_public_room.py | 23 +++++++++++++ .../calls/channels/delete_public_room.py | 22 ++++++++++++ tests/test_api.py | 34 +++++++++++++++++++ 5 files changed, 103 insertions(+) create mode 100644 rocketchat/calls/channels/create_public_room.py create mode 100644 rocketchat/calls/channels/delete_public_room.py diff --git a/README.md b/README.md index 959f3fa..979ecca 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ Initialize the client with a username and password. This user *must* have Admin api.get_room_info('room_id') api.get_private_room_info('room_id') api.get_room_history('room_id') + api.create_public_room('room_name', members=[], readOnly=bool) + api.delete_public_room('room_id') api.get_my_info() check /rocketchat/calls/api.py for more. diff --git a/rocketchat/api.py b/rocketchat/api.py index d126838..38344b9 100644 --- a/rocketchat/api.py +++ b/rocketchat/api.py @@ -5,6 +5,8 @@ from rocketchat.calls.groups.get_private_room_info import GetPrivateRoomInfo from rocketchat.calls.channels.get_history import GetRoomHistory from rocketchat.calls.groups.get_private_room_history import GetPrivateRoomHistory +from rocketchat.calls.channels.create_public_room import CreatePublicRoom +from rocketchat.calls.channels.delete_public_room import DeletePublicRoom from rocketchat.calls.auth.get_me import GetMe from datetime import datetime @@ -107,6 +109,26 @@ def get_room_history( **kwargs ) + def create_public_room(self, name, **kwargs): + """ + Create room with given name + :param name: Room name + :param kwargs: + members: The users to add to the channel when it is created. Optional; Ex.: ["rocket.cat"], Default: [] + read_only: Set if the channel is read only or not. Optional; Ex.: True, Default: False + :return: + """ + return CreatePublicRoom(settings=self.settings, **kwargs).call(name=name, **kwargs) + + def delete_public_room(self, room_id, **kwargs): + """ + Delete room with given ID + :param room_id: Room ID + :param kwargs: + :return: + """ + return DeletePublicRoom(settings=self.settings, **kwargs).call(room_id=room_id, **kwargs) + def get_my_info(self, **kwargs): return GetMe(settings=self.settings, **kwargs).call(**kwargs) diff --git a/rocketchat/calls/channels/create_public_room.py b/rocketchat/calls/channels/create_public_room.py new file mode 100644 index 0000000..419069b --- /dev/null +++ b/rocketchat/calls/channels/create_public_room.py @@ -0,0 +1,23 @@ +import logging +import json + +from rocketchat.calls.base import PostMixin, RocketChatBase + +logger = logging.getLogger(__name__) + + +class CreatePublicRoom(PostMixin, RocketChatBase): + endpoint = '/api/v1/channels.create' + + def build_endpoint(self, **kwargs): + return self.endpoint + + def build_payload(self, **kwargs): + return json.dumps({ + 'name': kwargs.get('name'), + 'members': kwargs.get('members', []), + 'readOnly': kwargs.get('read_only', False) + }) + + def post_response(self, result): + return result diff --git a/rocketchat/calls/channels/delete_public_room.py b/rocketchat/calls/channels/delete_public_room.py new file mode 100644 index 0000000..a566e45 --- /dev/null +++ b/rocketchat/calls/channels/delete_public_room.py @@ -0,0 +1,22 @@ +import logging +import json + + +from rocketchat.calls.base import PostMixin, RocketChatBase + +logger = logging.getLogger(__name__) + + +class DeletePublicRoom(PostMixin, RocketChatBase): + endpoint = '/api/v1/channels.delete' + + def build_endpoint(self, **kwargs): + return self.endpoint + + def build_payload(self, **kwargs): + return json.dumps({ + 'roomId': kwargs.get('room_id') + }) + + def post_response(self, result): + return result diff --git a/tests/test_api.py b/tests/test_api.py index d50db6b..817c37d 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -82,6 +82,40 @@ def test_get_user_list(self, mock_request, set_auth_headers_mock, set_auth_mock) self.assertEqual(room_data['channel']['usernames'], ['testing', 'testing1', 'testing2']) +class CreatePublicRoomTestCase(APITestCase, unittest.TestCase): + + @mock.patch('rocketchat.calls.base.RocketChatBase.set_auth_token') + @mock.patch('rocketchat.calls.base.RocketChatBase.set_auth_headers') + @mock.patch('requests.Session.request') + def test_create_public_rooms(self, mock_request, set_auth_headers_mock, set_auth_mock): + set_auth_mock.return_value = None + set_auth_headers_mock.return_value = None + + mock_response = mock.Mock() + mock_response.json.return_value = PUBLIC_ROOM_TEST + + mock_request.return_value = mock_response + + self.api.create_public_room('Test Room #2') + + +class DeletePublicRoomTestCase(APITestCase, unittest.TestCase): + + @mock.patch('rocketchat.calls.base.RocketChatBase.set_auth_token') + @mock.patch('rocketchat.calls.base.RocketChatBase.set_auth_headers') + @mock.patch('requests.Session.request') + def test_create_public_rooms(self, mock_request, set_auth_headers_mock, set_auth_mock): + set_auth_mock.return_value = None + set_auth_headers_mock.return_value = None + + mock_response = mock.Mock() + mock_response.json.return_value = PUBLIC_ROOM_TEST + + mock_request.return_value = mock_response + + self.api.delete_public_room('123456') + + class GetMeTestCase(APITestCase, unittest.TestCase): @mock.patch('rocketchat.calls.base.RocketChatBase.set_auth_token') From 5961b1c40c46f69aa7730a4d78d3aa8cbb66d547 Mon Sep 17 00:00:00 2001 From: Kirill Shtrykov Date: Tue, 19 Jun 2018 17:57:48 +0300 Subject: [PATCH 2/7] Add Users calls and get_users function --- rocketchat/api.py | 10 +++++- rocketchat/calls/users/__init__.py | 0 rocketchat/calls/users/get_users.py | 37 ++++++++++++++++++++ tests/data.py | 54 ++++++++++++++++++++++++++++- tests/test_api.py | 29 +++++++++++++--- 5 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 rocketchat/calls/users/__init__.py create mode 100644 rocketchat/calls/users/get_users.py diff --git a/rocketchat/api.py b/rocketchat/api.py index 38344b9..20ed35f 100644 --- a/rocketchat/api.py +++ b/rocketchat/api.py @@ -8,6 +8,7 @@ from rocketchat.calls.channels.create_public_room import CreatePublicRoom from rocketchat.calls.channels.delete_public_room import DeletePublicRoom from rocketchat.calls.auth.get_me import GetMe +from rocketchat.calls.users.get_users import GetUsers from datetime import datetime @@ -130,5 +131,12 @@ def delete_public_room(self, room_id, **kwargs): return DeletePublicRoom(settings=self.settings, **kwargs).call(room_id=room_id, **kwargs) def get_my_info(self, **kwargs): - return GetMe(settings=self.settings, **kwargs).call(**kwargs) + + def get_users(self, **kwargs): + """ + Gets all of the users in the system and their information + :param kwargs: + :return: + """ + return GetUsers(settings=self.settings, **kwargs).call(**kwargs) diff --git a/rocketchat/calls/users/__init__.py b/rocketchat/calls/users/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rocketchat/calls/users/get_users.py b/rocketchat/calls/users/get_users.py new file mode 100644 index 0000000..bcc51c2 --- /dev/null +++ b/rocketchat/calls/users/get_users.py @@ -0,0 +1,37 @@ +import logging + + +from rocketchat.calls.base import RocketChatBase + +logger = logging.getLogger(__name__) + + +class GetUsers(RocketChatBase): + endpoint = '/api/v1/users.list' + + def build_endpoint(self): + return self.endpoint + + def post_response(self, result): + users = [] + + try: + _users = result.get('users') + + for user in _users: + user_dict = dict() + user_dict['name'] = user.get('name') + user_dict['emails'] = [email['address'] for email in user.get('emails')] + user_dict['username'] = user.get('username') + user_dict['type'] = user.get('type') + user_dict['status'] = user.get('status') + user_dict['roles'] = user.get('roles') + user_dict['id'] = user.get('_id') + users.append(user_dict) + + except Exception as e: + logger.error('Exception in fetching public rooms {e}'.format( + e=e + ), exc_info=True) + + return users diff --git a/tests/data.py b/tests/data.py index f8ed795..3f3daf7 100644 --- a/tests/data.py +++ b/tests/data.py @@ -3,7 +3,7 @@ '_id': '123456'} ]} -GET_USERS_TEST = { +GET_ROOM_INFO_TEST = { "channel": { "_id": "ByehQjC44FwMeiLbX", "ts": "2016-11-30T21:23:04.737Z", @@ -38,3 +38,55 @@ "active": 'true', "success": 'true' } + +GET_USERS_TEST = { + "users": [ + { + "_id": "nSYqWzZ4GsKTX4dyK", + "createdAt": "2016-12-07T15:47:46.861Z", + "services": { + "password": { + "bcrypt": "..." + }, + "email": { + "verificationTokens": [ + { + "token": "...", + "address": "example@example.com", + "when": "2016-12-07T15:47:46.930Z" + } + ] + }, + "resume": { + "loginTokens": [ + { + "when": "2016-12-07T15:47:47.334Z", + "hashedToken": "..." + } + ] + } + }, + "emails": [ + { + "address": "example@example.com", + "verified": 'true' + } + ], + "type": "user", + "status": "offline", + "active": 'true', + "roles": [ + "user" + ], + "name": "Example User", + "lastLogin": "2016-12-08T00:22:15.167Z", + "statusConnection": "offline", + "utcOffset": 0, + "username": "example" + } + ], + "count": 3, + "offset": 2, + "total": 10, + "success": 'true' +} diff --git a/tests/test_api.py b/tests/test_api.py index 817c37d..66ec9b5 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -5,7 +5,7 @@ from rocketchat.calls.chat.send_message import SendMessage -from .data import PUBLIC_ROOM_TEST, GET_USERS_TEST, GET_ME_TEST +from .data import PUBLIC_ROOM_TEST, GET_ROOM_INFO_TEST, GET_USERS_TEST, GET_ME_TEST class APITestCase(object): @@ -63,17 +63,17 @@ def test_get_public_rooms(self, mock_request, set_auth_headers_mock, set_auth_mo self.assertEqual(pub_rooms[0]['id'], '123456') -class GetUserListTestCase(APITestCase, unittest.TestCase): +class GetRoomInfoTestCase(APITestCase, unittest.TestCase): @mock.patch('rocketchat.calls.base.RocketChatBase.set_auth_token') @mock.patch('rocketchat.calls.base.RocketChatBase.set_auth_headers') @mock.patch('requests.Session.request') - def test_get_user_list(self, mock_request, set_auth_headers_mock, set_auth_mock): + def test_get_room_info(self, mock_request, set_auth_headers_mock, set_auth_mock): set_auth_mock.return_value = None set_auth_headers_mock.return_value = None mock_response = mock.Mock() - mock_response.json.return_value = GET_USERS_TEST + mock_response.json.return_value = GET_ROOM_INFO_TEST mock_request.return_value = mock_response @@ -133,3 +133,24 @@ def test_get_me(self, mock_request, set_auth_headers_mock, set_auth_mock): user_info = self.api.get_my_info() self.assertEqual(user_info['name'], 'Example User') + + +class GetUsersTestCase(APITestCase, unittest.TestCase): + + @mock.patch('rocketchat.calls.base.RocketChatBase.set_auth_token') + @mock.patch('rocketchat.calls.base.RocketChatBase.set_auth_headers') + @mock.patch('requests.Session.request') + def test_get_user_list(self, mock_request, set_auth_headers_mock, set_auth_mock): + set_auth_mock.return_value = None + set_auth_headers_mock.return_value = None + + mock_response = mock.Mock() + mock_response.json.return_value = GET_USERS_TEST + + mock_request.return_value = mock_response + + users = self.api.get_users() + + self.assertEqual(users[0]['username'], 'example') + self.assertEqual(users[0]['name'], 'Example User') + self.assertEqual(users[0]['id'], 'nSYqWzZ4GsKTX4dyK') From 4b04bd8b5b7d1c8977c7299fb821851b726eea07 Mon Sep 17 00:00:00 2001 From: Kirill Shtrykov Date: Tue, 19 Jun 2018 18:21:28 +0300 Subject: [PATCH 3/7] Add get_user_info function --- README.md | 2 ++ rocketchat/api.py | 13 +++++++ rocketchat/calls/users/get_user_info.py | 19 ++++++++++ tests/data.py | 47 +++++++++++++++++++++++++ tests/test_api.py | 21 ++++++++++- 5 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 rocketchat/calls/users/get_user_info.py diff --git a/README.md b/README.md index 979ecca..68c7c1a 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ Initialize the client with a username and password. This user *must* have Admin api.create_public_room('room_name', members=[], readOnly=bool) api.delete_public_room('room_id') api.get_my_info() + api.get_users() + api.get_user_info('user_id') check /rocketchat/calls/api.py for more. diff --git a/rocketchat/api.py b/rocketchat/api.py index 20ed35f..c9c0993 100644 --- a/rocketchat/api.py +++ b/rocketchat/api.py @@ -9,6 +9,7 @@ from rocketchat.calls.channels.delete_public_room import DeletePublicRoom from rocketchat.calls.auth.get_me import GetMe from rocketchat.calls.users.get_users import GetUsers +from rocketchat.calls.users.get_user_info import GetUserInfo from datetime import datetime @@ -140,3 +141,15 @@ def get_users(self, **kwargs): :return: """ return GetUsers(settings=self.settings, **kwargs).call(**kwargs) + + def get_user_info(self, user_id, **kwargs): + """ + Retrieves information about a user, the result is only limited to what the callee has access to view. + :param user_id: + :param kwargs: + :return: + """ + return GetUserInfo(settings=self.settings, **kwargs).call( + user_id=user_id, + **kwargs + ) diff --git a/rocketchat/calls/users/get_user_info.py b/rocketchat/calls/users/get_user_info.py new file mode 100644 index 0000000..d056df1 --- /dev/null +++ b/rocketchat/calls/users/get_user_info.py @@ -0,0 +1,19 @@ +import logging + + +from rocketchat.calls.base import RocketChatBase + +logger = logging.getLogger(__name__) + + +class GetUserInfo(RocketChatBase): + endpoint = '/api/v1/users.info' + + def build_endpoint(self, **kwargs): + return '{endpoint}?userId={room_id}'.format( + endpoint=self.endpoint, + room_id=kwargs.get('user_id') + ) + + def post_response(self, result): + return result diff --git a/tests/data.py b/tests/data.py index 3f3daf7..b7826ab 100644 --- a/tests/data.py +++ b/tests/data.py @@ -90,3 +90,50 @@ "total": 10, "success": 'true' } + +GET_USER_INFO_TEST = { + "user": { + "_id": "nSYqWzZ4GsKTX4dyK", + "createdAt": "2016-12-07T15:47:46.861Z", + "services": { + "password": { + "bcrypt": "..." + }, + "email": { + "verificationTokens": [ + { + "token": "...", + "address": "example@example.com", + "when": "2016-12-07T15:47:46.930Z" + } + ] + }, + "resume": { + "loginTokens": [ + { + "when": "2016-12-07T15:47:47.334Z", + "hashedToken": "..." + } + ] + } + }, + "emails": [ + { + "address": "example@example.com", + "verified": 'true' + } + ], + "type": "user", + "status": "offline", + "active": 'true', + "roles": [ + "user" + ], + "name": "Example User", + "lastLogin": "2016-12-08T00:22:15.167Z", + "statusConnection": "offline", + "utcOffset": 0, + "username": "example" + }, + "success": 'true' +} diff --git a/tests/test_api.py b/tests/test_api.py index 66ec9b5..3b6d548 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -5,7 +5,7 @@ from rocketchat.calls.chat.send_message import SendMessage -from .data import PUBLIC_ROOM_TEST, GET_ROOM_INFO_TEST, GET_USERS_TEST, GET_ME_TEST +from .data import PUBLIC_ROOM_TEST, GET_ROOM_INFO_TEST, GET_USERS_TEST, GET_USER_INFO_TEST, GET_ME_TEST class APITestCase(object): @@ -154,3 +154,22 @@ def test_get_user_list(self, mock_request, set_auth_headers_mock, set_auth_mock) self.assertEqual(users[0]['username'], 'example') self.assertEqual(users[0]['name'], 'Example User') self.assertEqual(users[0]['id'], 'nSYqWzZ4GsKTX4dyK') + + +class GetUserInfoTestCase(APITestCase, unittest.TestCase): + + @mock.patch('rocketchat.calls.base.RocketChatBase.set_auth_token') + @mock.patch('rocketchat.calls.base.RocketChatBase.set_auth_headers') + @mock.patch('requests.Session.request') + def test_get_room_info(self, mock_request, set_auth_headers_mock, set_auth_mock): + set_auth_mock.return_value = None + set_auth_headers_mock.return_value = None + + mock_response = mock.Mock() + mock_response.json.return_value = GET_USER_INFO_TEST + + mock_request.return_value = mock_response + + room_data = self.api.get_user_info(user_id='nSYqWzZ4GsKTX4dyK') + + self.assertEqual(room_data['user']['username'], 'example') From eab6e1ac8b0bc6c97a9aa96f2487d0ceffc8d94a Mon Sep 17 00:00:00 2001 From: Kirill Shtrykov Date: Tue, 19 Jun 2018 19:13:34 +0300 Subject: [PATCH 4/7] Add create/delete user function --- README.md | 4 +- rocketchat/api.py | 36 ++++++++++++++++++ .../calls/channels/delete_public_room.py | 1 - rocketchat/calls/users/create_user.py | 31 +++++++++++++++ rocketchat/calls/users/delete_user.py | 21 ++++++++++ tests/test_api.py | 38 ++++++++++++++++++- 6 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 rocketchat/calls/users/create_user.py create mode 100644 rocketchat/calls/users/delete_user.py diff --git a/README.md b/README.md index 68c7c1a..b3740b4 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,13 @@ Initialize the client with a username and password. This user *must* have Admin api.get_room_info('room_id') api.get_private_room_info('room_id') api.get_room_history('room_id') - api.create_public_room('room_name', members=[], readOnly=bool) + api.create_public_room('room_name', members=[], read_only=False) api.delete_public_room('room_id') api.get_my_info() api.get_users() api.get_user_info('user_id') + api.create_user('email', 'name', 'password', 'username', active=True, roles=['user'], join_default_channels=True, require_password_change=False, send_welcome_email=False, verified=False, customFields=None) + api,delete_user('user_id') check /rocketchat/calls/api.py for more. diff --git a/rocketchat/api.py b/rocketchat/api.py index c9c0993..09cdc65 100644 --- a/rocketchat/api.py +++ b/rocketchat/api.py @@ -10,6 +10,8 @@ from rocketchat.calls.auth.get_me import GetMe from rocketchat.calls.users.get_users import GetUsers from rocketchat.calls.users.get_user_info import GetUserInfo +from rocketchat.calls.users.create_user import CreateUser +from rocketchat.calls.users.delete_user import DeleteUser from datetime import datetime @@ -153,3 +155,37 @@ def get_user_info(self, user_id, **kwargs): user_id=user_id, **kwargs ) + + def create_user(self, email, name, password, username, **kwargs): + """ + Create user + :param email: E-mail + :param name: Full name + :param password: Password + :param username: Username + :param kwargs: + active: + roles: + join_default_channels: + require_password_change: + send_welcome_email: + verified: + custom_fields: + :return: + """ + return CreateUser(settings=self.settings, **kwargs).call( + email=email, + name=name, + password=password, + username=username, + **kwargs + ) + + def delete_user(self, user_id, **kwargs): + """ + Delete user + :param user_id: User ID + :param kwargs: + :return: + """ + return DeleteUser(settings=self.settings, **kwargs).call(user_id=user_id, **kwargs) diff --git a/rocketchat/calls/channels/delete_public_room.py b/rocketchat/calls/channels/delete_public_room.py index a566e45..b12c62a 100644 --- a/rocketchat/calls/channels/delete_public_room.py +++ b/rocketchat/calls/channels/delete_public_room.py @@ -1,7 +1,6 @@ import logging import json - from rocketchat.calls.base import PostMixin, RocketChatBase logger = logging.getLogger(__name__) diff --git a/rocketchat/calls/users/create_user.py b/rocketchat/calls/users/create_user.py new file mode 100644 index 0000000..519b88a --- /dev/null +++ b/rocketchat/calls/users/create_user.py @@ -0,0 +1,31 @@ +import logging +import json + +from rocketchat.calls.base import PostMixin, RocketChatBase + +logger = logging.getLogger(__name__) + + +class CreateUser(PostMixin, RocketChatBase): + endpoint = '/api/v1/users.create' + + def build_endpoint(self, **kwargs): + return self.endpoint + + def build_payload(self, **kwargs): + return json.dumps({ + 'email': kwargs.get('email'), + 'name': kwargs.get('name'), + 'password': kwargs.get('password'), + 'username': kwargs.get('username'), + 'active': kwargs.get('active', True), + 'roles': kwargs.get('roles', ['user']), + 'joinDefaultChannels': kwargs.get('join_default_channels', True), + 'requirePasswordChange': kwargs.get('require_password_change', False), + 'sendWelcomeEmail': kwargs.get('send_welcome_email', False), + 'verified': kwargs.get('verified', False), + 'customFields': kwargs.get('customFields') + }) + + def post_response(self, result): + return result diff --git a/rocketchat/calls/users/delete_user.py b/rocketchat/calls/users/delete_user.py new file mode 100644 index 0000000..b25455b --- /dev/null +++ b/rocketchat/calls/users/delete_user.py @@ -0,0 +1,21 @@ +import logging +import json + +from rocketchat.calls.base import PostMixin, RocketChatBase + +logger = logging.getLogger(__name__) + + +class DeleteUser(PostMixin, RocketChatBase): + endpoint = '/api/v1/users.delete' + + def build_endpoint(self, **kwargs): + return self.endpoint + + def build_payload(self, **kwargs): + return json.dumps({ + 'userId': kwargs.get('user_id') + }) + + def post_response(self, result): + return result diff --git a/tests/test_api.py b/tests/test_api.py index 3b6d548..ff7b849 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -92,7 +92,7 @@ def test_create_public_rooms(self, mock_request, set_auth_headers_mock, set_auth set_auth_headers_mock.return_value = None mock_response = mock.Mock() - mock_response.json.return_value = PUBLIC_ROOM_TEST + mock_response.json.return_value = {} mock_request.return_value = mock_response @@ -109,7 +109,7 @@ def test_create_public_rooms(self, mock_request, set_auth_headers_mock, set_auth set_auth_headers_mock.return_value = None mock_response = mock.Mock() - mock_response.json.return_value = PUBLIC_ROOM_TEST + mock_response.json.return_value = {} mock_request.return_value = mock_response @@ -173,3 +173,37 @@ def test_get_room_info(self, mock_request, set_auth_headers_mock, set_auth_mock) room_data = self.api.get_user_info(user_id='nSYqWzZ4GsKTX4dyK') self.assertEqual(room_data['user']['username'], 'example') + + +class CreateUserTestCase(APITestCase, unittest.TestCase): + + @mock.patch('rocketchat.calls.base.RocketChatBase.set_auth_token') + @mock.patch('rocketchat.calls.base.RocketChatBase.set_auth_headers') + @mock.patch('requests.Session.request') + def test_create_public_rooms(self, mock_request, set_auth_headers_mock, set_auth_mock): + set_auth_mock.return_value = None + set_auth_headers_mock.return_value = None + + mock_response = mock.Mock() + mock_response.json.return_value = {} + + mock_request.return_value = mock_response + + self.api.create_user('example@example.com', 'Example User', 'qwerty', 'example', active=True) + + +class DeleteUserTestCase(APITestCase, unittest.TestCase): + + @mock.patch('rocketchat.calls.base.RocketChatBase.set_auth_token') + @mock.patch('rocketchat.calls.base.RocketChatBase.set_auth_headers') + @mock.patch('requests.Session.request') + def test_create_public_rooms(self, mock_request, set_auth_headers_mock, set_auth_mock): + set_auth_mock.return_value = None + set_auth_headers_mock.return_value = None + + mock_response = mock.Mock() + mock_response.json.return_value = {} + + mock_request.return_value = mock_response + + self.api.delete_user('123456') From 69b2fd5e079619793b1043c19e7868cc51d1d934 Mon Sep 17 00:00:00 2001 From: kirill-shtrykov Date: Tue, 19 Jun 2018 19:16:19 +0300 Subject: [PATCH 5/7] Remove mistake --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b3740b4..e809ff7 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Initialize the client with a username and password. This user *must* have Admin api.get_users() api.get_user_info('user_id') api.create_user('email', 'name', 'password', 'username', active=True, roles=['user'], join_default_channels=True, require_password_change=False, send_welcome_email=False, verified=False, customFields=None) - api,delete_user('user_id') + api.delete_user('user_id') check /rocketchat/calls/api.py for more. From 8162c2bd43f2242fb9137f41245b02b975a8ee13 Mon Sep 17 00:00:00 2001 From: Kirill Shtrykov Date: Tue, 19 Jun 2018 19:53:43 +0300 Subject: [PATCH 6/7] Update pytest version in requriments.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4a2717a..20a3f6d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ requests>=2.0.0,<3.0 -pytest==2.8.7 +pytest>=2.9 pytest-flakes==1.0.1 pytest-sugar pytest-pep8==1.0.6 From 0310940a36d6f586aaa4ca59ad1f6bb96f2c1d8d Mon Sep 17 00:00:00 2001 From: Kirill Shtrykov Date: Tue, 19 Jun 2018 20:28:55 +0300 Subject: [PATCH 7/7] Fix dockstrings to PEP8-check --- rocketchat/api.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rocketchat/api.py b/rocketchat/api.py index 09cdc65..e5c148c 100644 --- a/rocketchat/api.py +++ b/rocketchat/api.py @@ -118,8 +118,10 @@ def create_public_room(self, name, **kwargs): Create room with given name :param name: Room name :param kwargs: - members: The users to add to the channel when it is created. Optional; Ex.: ["rocket.cat"], Default: [] - read_only: Set if the channel is read only or not. Optional; Ex.: True, Default: False + members: The users to add to the channel when it is created. + Optional; Ex.: ["rocket.cat"], Default: [] + read_only: Set if the channel is read only or not. + Optional; Ex.: True, Default: False :return: """ return CreatePublicRoom(settings=self.settings, **kwargs).call(name=name, **kwargs) @@ -146,7 +148,8 @@ def get_users(self, **kwargs): def get_user_info(self, user_id, **kwargs): """ - Retrieves information about a user, the result is only limited to what the callee has access to view. + Retrieves information about a user, + the result is only limited to what the callee has access to view. :param user_id: :param kwargs: :return: