Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jadolg authored Aug 9, 2022
2 parents 1afa8d1 + 65ce2b0 commit 2f33caf
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 25 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-test-server.yml → docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
requests==2.25.1
requests==2.28.1
1 change: 1 addition & 0 deletions rocketchat_API/APISections/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 8 additions & 10 deletions rocketchat_API/APISections/im.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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)
8 changes: 5 additions & 3 deletions rocketchat_API/APISections/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
6 changes: 2 additions & 4 deletions tests/test_ims.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 0 additions & 2 deletions tests/test_rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import time

import pytest


def test_settings(logged_rocket):
settings = logged_rocket.settings().json()
Expand All @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions tests/test_video_conferences.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 2f33caf

Please sign in to comment.