Skip to content

Conversation

@Zil0
Copy link
Contributor

@Zil0 Zil0 commented May 16, 2018

Not sure if I should squash pik's commit and my fixes.
Tests felt really repetitive to write, I wonder if there isn't some way to refactor them (maybe using some pytest magic). edit: just saw that there have already been discussions on this and that pik had started working on the issue, I should see if I can take the time to look into this.

@Zil0 Zil0 mentioned this pull request May 19, 2018
@non-Jedi
Copy link
Collaborator

In general, tests that are relatively "non-magical" are better even if they aren't very DRY in my opinion. Then again, responses already feels pretty magical. I'm pretty ambivalent other than generally feeling that we need to make sure we don't abstract too far away from what we're actually doing in the test code.

@pik 's stuff testing explicitly against the spec I'm definitely planning on looking at eventually, but I don't think we should replace manually written tests with that unless we set something up where we explicitly declare each method of MatrixHttpApi to correspond to something from the spec. Hm. Might already do that; need to look at it again.

Copy link
Collaborator

@non-Jedi non-Jedi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than nits, LGTM. Thanks!


def update_device_info(self, device_id, display_name):
"""Update the display name of a device.
Args:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include a blank line after every first line summary of a docstring.


def delete_device(self, auth_body, device_id):
"""Deletes the given device, and invalidates any access token associated with it.
Requires Auth.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably explicitly say that it uses the "User-Interactive Authentication API." Lots of endpoints require auth, but very few use the user-interactive flow. Also should be separated from the "Args" block by an empty line I believe.

@responses.activate
def test_delete_device(self):
delete_device_url = "http://example.com/_matrix/client/r0/devices/QBUAZIFURK"
responses.add(responses.DELETE, delete_device_url, body='{}')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test that things behave as expected when receiving 401 responses since that's part of the user-interactive auth api?

@non-Jedi
Copy link
Collaborator

Oh, and signoff please. :)

@Zil0
Copy link
Contributor Author

Zil0 commented May 21, 2018

Should be good now.
Signed-off-by: Valentin Deniaud <valentin.deniaud@inpt.fr>


def delete_device(self, auth_body, device_id):
"""Deletes the given device, and invalidates any access token associated with it.
Requires User-Interactive Authentication API.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed this the first time through. Please try to follow PEP 257 conventions for multi-line docstrings. In this case, that means a single summary line separated by a blank new line from a more detailed description. Something like:

"""Deletes the given device and invalidates any associated access tokens.

NOTE: This endpoint uses the User-Interactive Authentication API.

Args:
    auth_body (dict): Authentication params.
    device_id (str): The device ID of the device to delete.
"""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed. I mostly know PEP8 through flake8 and tend to miss those kind of things.

@non-Jedi non-Jedi merged commit 048eaba into matrix-org:master May 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants