diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..6a7695c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "pip" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e8fb137..1f587ca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,14 +14,14 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ '2.7', '3.6', '3.7', '3.8', '3.9' ] + python-version: [ '2.7', '3.8', '3.9', '3.10' ] steps: - name: Checkout uses: actions/checkout@v2.3.4 - name: Start rocket.chat server uses: isbang/compose-action@v0.1.1 with: - compose-file: docker-compose-test-server.yml + compose-file: docker-compose.yml - name: Set up Python uses: actions/setup-python@v2 with: @@ -35,7 +35,7 @@ jobs: 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 + run: until curl --silent http://localhost:3000/api/info/; do sleep 15; echo "waiting for Rocket.Chat server to start"; done; - name: Run tests run: pytest tests rocketchat_API -x --cov-report xml --cov=./ - name: Upload code coverage diff --git a/README.md b/README.md index d3795b7..2b989d8 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,9 @@ Most of the API methods are already implemented. If you are interested in a spec ### Tests We are actively testing :) -Tests run on a Rocket.Chat Docker container so install Docker and docker-compose. To start test server do `docker-compose -f docker-compose-test-server.yml up` and to take test server down `docker-compose -f docker-compose-test-server.yml down` +Tests run on a Rocket.Chat Docker container so install Docker and docker-compose. +1. To start test server do `docker-compose up` and to take test server down `docker-compose down` +2. To run the tests run `pytest` ### Contributing You can contribute by doing Pull Requests. (It may take a while to merge your code but if it's good it will be merged). Please, try to implement tests for all your code and use a PEP8 compliant code style. diff --git a/docker-compose-test-server.yml b/docker-compose.yml similarity index 94% rename from docker-compose-test-server.yml rename to docker-compose.yml index bd041a6..c708420 100644 --- a/docker-compose-test-server.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: environment: - PORT=3000 - ROOT_URL=http://localhost:3000 - - MONGO_URL=mongodb://mongo:27017/rocketchat + - MONGO_URL=mongodb://mongo:27017/rocketchat?directConnection=true - MONGO_OPLOG_URL=mongodb://mongo:27017/local - OVERWRITE_SETTING_API_Enable_Rate_Limiter=false - OVERWRITE_SETTING_Accounts_TwoFactorAuthentication_Enforce_Password_Fallback=false diff --git a/requirements.txt b/requirements.txt index 9d84d35..d15ce5a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -requests==2.25.1 +requests==2.28.1 diff --git a/rocketchat_API/APISections/base.py b/rocketchat_API/APISections/base.py index e9fab22..95a3750 100644 --- a/rocketchat_API/APISections/base.py +++ b/rocketchat_API/APISections/base.py @@ -86,6 +86,7 @@ def call_api_post(self, method, files=None, use_json=None, **kwargs): # Some methods use pass (users.register) and others password (users.create) if "password" in reduced_args and method != "users.create": reduced_args["pass"] = reduced_args["password"] + del reduced_args["password"] if use_json is None: # see https://requests.readthedocs.io/en/master/user/quickstart/#more-complicated-post-requests # > The json parameter is ignored if either data or files is passed. diff --git a/rocketchat_API/APISections/im.py b/rocketchat_API/APISections/im.py index 23ce35d..46a9c29 100644 --- a/rocketchat_API/APISections/im.py +++ b/rocketchat_API/APISections/im.py @@ -33,17 +33,17 @@ def im_close(self, room_id, **kwargs): """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): + def im_members(self, room_id): """Retrieves members of a direct message.""" - return self.call_api_get("im.members", roomId=room_id, args=kwargs) + return self.call_api_get("im.members", roomId=room_id) - def im_messages(self, room_id=None, username=None, **kwargs): + def im_messages(self, room_id=None, username=None): """Retrieves direct messages from the server by username""" if room_id: - return self.call_api_get("im.messages", roomId=room_id, args=kwargs) + return self.call_api_get("im.messages", roomId=room_id) if username: - return self.call_api_get("im.messages", username=username, args=kwargs) + return self.call_api_get("im.messages", username=username) raise RocketMissingParamException("roomId or username required") @@ -65,10 +65,8 @@ def im_files(self, room_id=None, user_name=None, **kwargs): return self.call_api_get("im.files", username=user_name, kwargs=kwargs) raise RocketMissingParamException("roomId or username required") - def im_counters(self, room_id=None, user_name=None, **kwargs): + def im_counters(self, room_id, user_name=None): """Gets counters of direct messages.""" - if room_id: - return self.call_api_get("im.counters", roomId=room_id, kwargs=kwargs) if user_name: - return self.call_api_get("im.counters", username=user_name, kwargs=kwargs) - raise RocketMissingParamException("roomId or username required") + return self.call_api_get("im.counters", roomId=room_id, username=user_name) + return self.call_api_get("im.counters", roomId=room_id) diff --git a/rocketchat_API/APISections/rooms.py b/rocketchat_API/APISections/rooms.py index 27218ca..3301b85 100644 --- a/rocketchat_API/APISections/rooms.py +++ b/rocketchat_API/APISections/rooms.py @@ -58,9 +58,11 @@ def rooms_admin_rooms(self, **kwargs): return self.call_api_get("rooms.adminRooms", kwargs=kwargs) def rooms_create_discussion(self, prid, t_name, **kwargs): - """Creates a new discussion for room. It requires at least one of the following permissions: - start-discussion OR start-discussion-other-user, AND must be with the following setting enabled: - Discussion_enabled.""" + """ + Creates a new discussion for room. It requires at least one of the + following permissions: start-discussion OR start-discussion-other-user, + AND must be with the following setting enabled: Discussion_enabled. + """ return self.call_api_post( "rooms.createDiscussion", prid=prid, t_name=t_name, kwargs=kwargs ) diff --git a/tests/test_ims.py b/tests/test_ims.py index dd3616b..9d928d4 100644 --- a/tests/test_ims.py +++ b/tests/test_ims.py @@ -143,9 +143,7 @@ def test_im_counters(logged_rocket, recipient_user): assert im_counters.get("success") im_counters = logged_rocket.im_counters( - user_name=logged_rocket.me().json().get("_id") + room_id=im_create.get("room").get("_id"), + user_name=logged_rocket.me().json().get("_id"), ).json() assert im_counters.get("success") - - with pytest.raises(RocketMissingParamException): - logged_rocket.im_counters() diff --git a/tests/test_rooms.py b/tests/test_rooms.py index 22d378b..9b7c5b1 100644 --- a/tests/test_rooms.py +++ b/tests/test_rooms.py @@ -4,8 +4,6 @@ def test_rooms_upload(logged_rocket): - # ToDo: Find a better way to test that this endpoint actually works fine (when using json and not data fails - # silently) rooms_upload = logged_rocket.rooms_upload( "GENERAL", file="tests/assets/avatar.png", description="hey there" ).json() diff --git a/tests/test_settings.py b/tests/test_settings.py index 6aaea9d..c6dcf80 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -1,5 +1,7 @@ import time +import pytest + def test_settings(logged_rocket): settings = logged_rocket.settings().json() @@ -19,6 +21,9 @@ def test_settings_public(rocket): assert "settings" in settings_public +@pytest.mark.skip( + reason="Broken in 5.0 https://github.com/jadolg/rocketchat_API/issues/168" +) def test_settings_oauth(logged_rocket): # refresh is not done with any API call ever, so we need to call it manually here response = logged_rocket.call_api_post( diff --git a/tests/test_video_conferences.py b/tests/test_video_conferences.py index 0b301e7..dd7d0bd 100644 --- a/tests/test_video_conferences.py +++ b/tests/test_video_conferences.py @@ -1,3 +1,9 @@ +import pytest + + +@pytest.mark.skip( + reason="Broken in 5.0. https://github.com/RocketChat/Rocket.Chat/issues/26520" +) def test_update_jitsi_timeout(logged_rocket): update_jitsi_timeout = logged_rocket.update_jitsi_timeout(room_id="GENERAL").json() assert update_jitsi_timeout.get("success")