summaryrefslogtreecommitdiff
path: root/gitlab/tests/objects/test_users.py
diff options
context:
space:
mode:
authorMax Wittig <max.wittig@siemens.com>2021-02-25 21:51:13 +0100
committerMax Wittig <max.wittig@siemens.com>2021-02-27 16:33:05 +0100
commite456869d98a1b7d07e6f878a0d6a9719c1b10fd4 (patch)
treea21654e7d05a6c668c0214837ba561e070fbbf5f /gitlab/tests/objects/test_users.py
parente06c51bcf29492dbc7ef838c35f6ef86a79af261 (diff)
downloadgitlab-feat/user-follow-api.tar.gz
feat(users): add follow/unfollow APIfeat/user-follow-api
Diffstat (limited to 'gitlab/tests/objects/test_users.py')
-rw-r--r--gitlab/tests/objects/test_users.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/gitlab/tests/objects/test_users.py b/gitlab/tests/objects/test_users.py
index f84e877..e46a315 100644
--- a/gitlab/tests/objects/test_users.py
+++ b/gitlab/tests/objects/test_users.py
@@ -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()
+ 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