- Notifications
You must be signed in to change notification settings - Fork675
feat(users): add follow/unfollow API#1333
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletionsdocs/gl_objects/users.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -67,6 +67,11 @@ Activate/Deactivate a user:: | ||
| user.activate() | ||
| user.deactivate() | ||
| Follow/Unfollow a user:: | ||
| user.follow() | ||
| user.unfollow() | ||
| Set the avatar image for a user:: | ||
| # the avatar image can be passed as data (content of the file) or as a file | ||
| @@ -84,6 +89,15 @@ Delete an external identity by provider name:: | ||
| user.identityproviders.delete('oauth2_generic') | ||
| Get the followers of a user | ||
| user.followers_users.list() | ||
| Get the followings of a user | ||
| user.following_users.list() | ||
max-wittig marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| User custom attributes | ||
| ====================== | ||
8 changes: 8 additions & 0 deletionsgitlab/exceptions.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletionsgitlab/tests/objects/test_users.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -108,6 +108,72 @@ def resp_delete_user_identity(no_content): | ||
| yield rsps | ||
| @pytest.fixture | ||
| def resp_follow_unfollow(): | ||
| user = { | ||
| "id": 1, | ||
| "username": "john_smith", | ||
| "name": "John Smith", | ||
| "state": "active", | ||
| "avatar_url": "http://localhost:3000/uploads/user/avatar/1/cd8.jpeg", | ||
| "web_url": "http://localhost:3000/john_smith", | ||
| } | ||
| with responses.RequestsMock() as rsps: | ||
| rsps.add( | ||
| method=responses.POST, | ||
| url="http://localhost/api/v4/users/1/follow", | ||
| json=user, | ||
| content_type="application/json", | ||
| status=201, | ||
| ) | ||
| rsps.add( | ||
| method=responses.POST, | ||
| url="http://localhost/api/v4/users/1/unfollow", | ||
| json=user, | ||
| content_type="application/json", | ||
| status=201, | ||
| ) | ||
| yield rsps | ||
| @pytest.fixture | ||
| def resp_followers_following(): | ||
| content = [ | ||
| { | ||
| "id": 2, | ||
| "name": "Lennie Donnelly", | ||
| "username": "evette.kilback", | ||
| "state": "active", | ||
| "avatar_url": "https://www.gravatar.com/avatar/7955171a55ac4997ed81e5976287890a?s=80&d=identicon", | ||
| "web_url": "http://127.0.0.1:3000/evette.kilback", | ||
| }, | ||
| { | ||
| "id": 4, | ||
| "name": "Serena Bradtke", | ||
| "username": "cammy", | ||
| "state": "active", | ||
| "avatar_url": "https://www.gravatar.com/avatar/a2daad869a7b60d3090b7b9bef4baf57?s=80&d=identicon", | ||
| "web_url": "http://127.0.0.1:3000/cammy", | ||
| }, | ||
| ] | ||
| with responses.RequestsMock() as rsps: | ||
| rsps.add( | ||
| method=responses.GET, | ||
| url="http://localhost/api/v4/users/1/followers", | ||
| json=content, | ||
| content_type="application/json", | ||
| status=200, | ||
| ) | ||
| rsps.add( | ||
| method=responses.GET, | ||
| url="http://localhost/api/v4/users/1/following", | ||
| json=content, | ||
| content_type="application/json", | ||
| status=200, | ||
| ) | ||
| yield rsps | ||
| def test_get_user(gl, resp_get_user): | ||
| user = gl.users.get(1) | ||
| assert isinstance(user, User) | ||
| @@ -135,3 +201,17 @@ def test_user_activate_deactivate(user, resp_activate): | ||
| def test_delete_user_identity(user, resp_delete_user_identity): | ||
| user.identityproviders.delete("test_provider") | ||
| def test_user_follow_unfollow(user, resp_follow_unfollow): | ||
| user.follow() | ||
max-wittig marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| user.unfollow() | ||
| def test_list_followers(user, resp_followers_following): | ||
| followers = user.followers_users.list() | ||
| followings = user.following_users.list() | ||
| assert isinstance(followers[0], User) | ||
| assert followers[0].id == 2 | ||
| assert isinstance(followings[0], User) | ||
| assert followings[1].id == 4 | ||
50 changes: 50 additions & 0 deletionsgitlab/v4/objects/users.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.