From 48c46cbbfd406fbc402b864f0ca72c92466d3084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Kolbu?= Date: Fri, 27 Jan 2023 11:14:28 +0100 Subject: [PATCH 1/3] (feat) Team: extend patchable fields and add commit and fix request --- gitea/apiobject.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/gitea/apiobject.py b/gitea/apiobject.py index 2c64327..059504b 100644 --- a/gitea/apiobject.py +++ b/gitea/apiobject.py @@ -766,11 +766,25 @@ class Team(ApiObject): "organization": lambda gitea, o: Organization.parse_response(gitea, o) } + _patchable_fields = { + "can_create_org_repo", + "description", + "includes_all_repositories", + "name", + "permission", + "units", + "units_map", + } + @classmethod - def request(cls, gitea: 'Gitea', organization: str, team: str): + def request(cls, gitea: "Gitea", id: int): return cls._request(gitea, {"id": id}) - _patchable_fields = {"description", "name", "permission", "units"} + def commit(self): + values = self.get_dirty_fields() + args = {"id": self.id} + self.gitea.requests_patch(self.API_OBJECT.format(**args), data=values) + self.dirty_fields = {} def add_user(self, user: User): """https://try.gitea.io/api/swagger#/organization/orgAddTeamMember""" From 8407f47d31d2bbbcddd53decea7a7a5547a8e738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Kolbu?= Date: Fri, 27 Jan 2023 11:15:42 +0100 Subject: [PATCH 2/3] (testing) Test patching of Team object and its new request method --- tests/test_api.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_api.py b/tests/test_api.py index a06fbe7..860e9db 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -196,6 +196,30 @@ def test_create_team(instance): assert team.description == "descr" assert team.organization == org +def test_patch_team(instance): + fields = { + "can_create_org_repo": True, + "description": "patched description", + "includes_all_repositories": True, + "name": "newname", + "permission": "write", + } + org = Organization.request(instance, test_org) + team = instance.create_team(org, test_team[:1], "descr") + for field, value in fields.items(): + setattr(team, field, value) + team.commit() + team = Team.request(instance, team.id) + for field, value in fields.items(): + assert getattr(team, field) == value + + +def test_request_team(instance): + org = Organization.request(instance, test_org) + team = org.get_team(test_team) + team2 = Team.request(instance, team.id) + assert team.name == team2.name + def test_create_milestone(instance): org = Organization.request(instance, test_org) repo = org.get_repository(test_repo) From 045566984b013e9fc92aa0a950bf4b2bfd505fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Kolbu?= Date: Fri, 27 Jan 2023 11:16:23 +0100 Subject: [PATCH 3/3] (testing) Fix typo in string --- tests/test_api_longtests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_api_longtests.py b/tests/test_api_longtests.py index 8fcd9db..d8a0c4b 100644 --- a/tests/test_api_longtests.py +++ b/tests/test_api_longtests.py @@ -43,6 +43,6 @@ def test_list_issue(instance): org = Organization.request(instance, test_org) repo = instance.create_repo(org, test_repo, "Testing a huge number of Issues and how they are listed") for x in range(0, 100): - Issue.create_issue(instance, repo, "TestIssue" + str(x), "We will be to many to be listed on one page") + Issue.create_issue(instance, repo, "TestIssue" + str(x), "We will be too many to be listed on one page") issues = repo.get_issues() - assert len(issues) > 98 \ No newline at end of file + assert len(issues) > 98