User object is now able to list teams its a member of

pull/7/head
Langenfeld 2021-10-05 14:06:48 +02:00
rodzic 2445905d8f
commit a4daea6f4a
2 zmienionych plików z 17 dodań i 2 usunięć

Wyświetl plik

@ -165,6 +165,12 @@ class User(GiteaApiObject):
results = self.gitea.requests_get(url) results = self.gitea.requests_get(url)
return [Organization.parse_response(self.gitea, result) for result in results] return [Organization.parse_response(self.gitea, result) for result in results]
def get_teams(self) -> List['Team']:
""" Get all Organizations this user is a member of."""
url = f"/user/teams"
results = self.gitea.requests_get(url, sudo=self)
return [Team.parse_response(self.gitea, result) for result in results]
def __request_emails(self): def __request_emails(self):
result = self.gitea.requests_get(User.USER_MAIL % self.login) result = self.gitea.requests_get(User.USER_MAIL % self.login)
# report if the adress changed by this # report if the adress changed by this
@ -635,7 +641,9 @@ class Gitea:
return json.loads(result.text) return json.loads(result.text)
return {} return {}
def requests_get(self, endpoint, params={}, requests=None): def requests_get(self, endpoint, params={}, requests=None, sudo=None):
if sudo:
params["sudo"] = sudo.username
if not requests: if not requests:
request = self.requests.get( request = self.requests.get(
self.__get_url(endpoint), headers=self.headers, params=params self.__get_url(endpoint), headers=self.headers, params=params

Wyświetl plik

@ -54,7 +54,7 @@ def test_fail_get_non_existent_repo(instance):
def test_create_user(instance): def test_create_user(instance):
email = test_user + "@example.org" email = test_user + "@example.org"
user = instance.create_user(test_user, email, "abcdefg1.23AB") user = instance.create_user(test_user, email, "abcdefg1.23AB", send_notify=False)
assert user.username == test_user assert user.username == test_user
assert user.login == test_user assert user.login == test_user
assert email in user.emails assert email in user.emails
@ -147,6 +147,13 @@ def test_create_team(instance):
assert team.description == "descr" assert team.description == "descr"
assert team.organization == org assert team.organization == org
def test_user_teams(instance):
org = Organization.request(instance, test_org)
team = org.get_team(test_team)
user = instance.get_user_by_name(test_user)
team.add_user(user)
teams = user.get_teams()
assert team in teams
def test_create_issue(instance): def test_create_issue(instance):
org = Organization.request(instance, test_org) org = Organization.request(instance, test_org)