-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
keys API #212
keys API #212
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still need to review substance of PR, but if you could correct same set of stylistic nits as pointed out in #210, that'd be fantastic. Also signoff please. Thanks!
matrix_client/api.py
Outdated
|
||
def key_changes(self, from_token, to_token): | ||
"""Gets a list of users who have updated their device identity keys | ||
since a previous sync token. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be a single line summary.
921ff67
to
fd2c43a
Compare
Addressed stylistic issues and added tests. |
@Zil0 could you rebase on master please to make review easier? |
done :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than that, LGTM. Thanks!
matrix_client/api.py
Outdated
@@ -836,3 +836,76 @@ def delete_devices(self, auth_body, devices): | |||
"devices": devices | |||
} | |||
return self._send("POST", "/delete_devices", content=content) | |||
|
|||
def upload_keys(self, device_keys={}, one_time_keys={}): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kwargs shouldn't have mutable objects as their default argument. We do this elsewhere in the sdk, and it's wrong. What effectively happens is that the same dictionary (which is mutable) gets reused each time this method is called and could potentially be non-empty in the future.
matrix_client/api.py
Outdated
Said device must be the one used when logging in. | ||
|
||
Args: | ||
device_keys (dict): Optional. Identity keys for the device. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should give info about the format of this arg in the docstring. Same for below.
matrix_client/api.py
Outdated
content["one_time_keys"] = one_time_keys | ||
return self._send("POST", "/keys/upload", content=content) | ||
|
||
def query_user_keys(self, user_id): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a higher level method that I don't think belongs in this class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, same for claim_key then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assumed it was
matrix_client/api.py
Outdated
"""Query HS for public keys by user and optionally device. | ||
|
||
Args: | ||
user_devices (dict): The devices whose keys to download. Should be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please format these for rst as seen in other method docstrings where args need multi-line explanations.
matrix_client/api.py
Outdated
""" | ||
return self.query_keys({user_id: []}) | ||
|
||
def query_keys(self, user_devices, timeout=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where's the token
parameter for this method? https://matrix.org/speculator/spec/HEAD/client_server/unstable.html#post-matrix-client-r0-keys-query
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I wasn't looking at unstable :)
matrix_client/api.py
Outdated
"""Gets a list of users who have updated their device identity keys. | ||
|
||
Args: | ||
from_token (str): The desired start point of the list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please explicitly state that this should be taken from next_batch
field of a sync response.
|
||
@responses.activate | ||
@pytest.mark.parametrize("args", [ | ||
{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really entirely understand pytest. Where is this empty dict going? upload_keys
only takes two arguments, not three.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.pytest.org/en/latest/parametrize.html
The test is called 3 times, one with {}
which stands for no argument, then with device_keys
set, then with one_time_keys
. Not sure why I didn't do a fourth test with both set. Then we call the API method with the arguments found in args
.
If this is too confusing for what it is, I can go back to copy-pasting, which won't make much difference seeing the rest of the file :)
Making the changes but before I forget again: |
along with some helpers
fixed :) |
LGTM. Thanks! |
Follows #209 and is based on the work of @pik at pik@f855cb8.
This can already be looked at, I tagged it WIP because I didn't add tests yet.