diff --git a/gitea/gitea.py b/gitea/gitea.py index fc6635a..39dfc59 100644 --- a/gitea/gitea.py +++ b/gitea/gitea.py @@ -23,18 +23,21 @@ class GiteaApiObject: def __init__(self, gitea, id: int): self.id = id self.gitea = gitea - self.deleted = False #set if .delete was called, so that an exception is risen + self.deleted = False # set if .delete was called, so that an exception is risen def __eq__(self, other): return other.id == self.id if isinstance(other, type(self)) else False + def __str__(self): + return "GiteaAPIObject (%s) id: %s"%(type(self),self.id) + def __hash__(self): return self.id fields_to_parsers = {} @classmethod - def get(cls, gitea, id): + def request(cls, gitea, id): """Use for ginving a nice e.g. 'request(gita, orgname, repo, ticket)'. All args are put into an args tuple for passing around""" return cls._request(gitea, {"id":id}) @@ -95,7 +98,7 @@ class Organization(GiteaApiObject): super(Organization, self).__init__(gitea, id=id) @classmethod - def get(cls, gitea, name): + def request(cls, gitea, name): return cls._request(gitea, {"name": name}) # oldstuff @@ -123,7 +126,14 @@ class Organization(GiteaApiObject): results = self.gitea.requests_get( Organization.ORG_TEAMS_REQUEST % self.username ) - return [Team.parse_request(self, result) for result in results] + return [Team.parse_request(self.gitea, result) for result in results] + + def get_team_by_name(self, name): + teams = self.get_teams() + for team in teams: + if team.name == name: + return team + raise NotFoundException() def get_members(self): """ Get all members of this Organization @@ -179,7 +189,7 @@ class User(GiteaApiObject): super(User, self).__init__(gitea, id=id) @classmethod - def get(cls, gitea, name): + def request(cls, gitea, name): return cls._request(gitea, {"name": name}) @@ -260,7 +270,7 @@ class Repository(GiteaApiObject): } @classmethod - def get(cls, gitea, owner, name): + def request(cls, gitea, owner, name): return cls._request(gitea, {"owner": owner, "name": name}) def get_branches(self): @@ -357,7 +367,7 @@ class Milestone(GiteaApiObject): } @classmethod - def get(cls, gitea, owner, repo, number): + def request(cls, gitea, owner, repo, number): return cls._request(gitea, {"owner":owner, "repo":repo, "number":number}) def full_print(self): @@ -384,7 +394,7 @@ class Issue(GiteaApiObject): } @classmethod - def get(cls, gitea, owner, repo, number): + def request(cls, gitea, owner, repo, number): api_object = cls._request(gitea, {"owner":owner, "repo":repo, "number":number}) return api_object @@ -417,7 +427,7 @@ class Branch(GiteaApiObject): super(Branch, self).__init__(gitea, id=id) @classmethod - def get(cls, gitea, owner, repo, ref): + def request(cls, gitea, owner, repo, ref): return cls._request(gitea, {"owner":owner, "repo":repo, "ref":ref}) @@ -438,7 +448,7 @@ class Team(GiteaApiObject): } @classmethod - def get(cls, gitea, id): + def request(cls, gitea, id): return cls._request(gitea, {"id":id}) def add(self, toAdd): diff --git a/test_api.py b/test_api.py index 3ee90fe..d1eee66 100644 --- a/test_api.py +++ b/test_api.py @@ -36,15 +36,15 @@ def test_gitea_version(): def test_fail_get_non_existent_user(): with pytest.raises(NotFoundException) as e: - User.get(gitea, test_user) + User.request(gitea, test_user) def test_fail_get_non_existent_org(): with pytest.raises(NotFoundException) as e: - Organization.get(gitea, test_org) + Organization.request(gitea, test_org) def test_fail_get_non_existent_repo(): with pytest.raises(NotFoundException) as e: - Repository.get(gitea, test_user, test_repo) + Repository.request(gitea, test_user, test_repo) def test_create_user(): email = test_user + "@example.org" @@ -66,7 +66,7 @@ def test_create_org(): assert not org.full_name def test_create_repo_userowned(): - org = User.get(gitea, test_user) + org = User.request(gitea, test_user) repo = gitea.create_repo(org, test_repo, "user owned repo") assert repo.description == "user owned repo" assert repo.owner == org @@ -74,7 +74,7 @@ def test_create_repo_userowned(): assert not repo.private def test_create_repo_orgowned(): - org = Organization.get(gitea, test_org) + org = Organization.request(gitea, test_org) repo = gitea.create_repo(org, test_repo, "descr") assert repo.description == "descr" assert repo.owner == org @@ -82,41 +82,41 @@ def test_create_repo_orgowned(): assert not repo.private def test_create_team(): - org = Organization.get(gitea, "AlreadyPresentOrg") + org = Organization.request(gitea, "AlreadyPresentOrg") team = gitea.create_team(org, test_team, "descr") assert team.name == test_team assert team.description == "descr" assert team.organization == org def test_delete_repo_userowned(): - org = User.get(gitea, test_user) - repo = Repository.get(gitea, org.username, test_repo) + org = User.request(gitea, test_user) + repo = Repository.request(gitea, org.username, test_repo) repo.delete() with pytest.raises(NotFoundException) as e: - Repository.get(gitea, test_user, test_repo) + Repository.request(gitea, test_user, test_repo) def test_delete_repo_orgowned(): - org = Organization.get(gitea, test_org) - repo = Repository.get(gitea, org.username, test_repo) + org = Organization.request(gitea, test_org) + repo = Repository.request(gitea, org.username, test_repo) repo.delete() with pytest.raises(NotFoundException) as e: - Repository.get(gitea, test_user, test_repo) + Repository.request(gitea, test_user, test_repo) def test_delete_team(): - org = Organization.get(gitea, "AlreadyPresentOrg") - team = Team.get(org, test_team) + org = Organization.request(gitea, "AlreadyPresentOrg") + team = Team.request(org, test_team) team.delete() with pytest.raises(NotFoundException) as e: - Team.get(org, test_team) + Team.request(org, test_team) def test_delete_org(): - org = Organization.get(gitea, test_org) + org = Organization.request(gitea, test_org) org.delete() with pytest.raises(NotFoundException) as e: - Organization.get(gitea, test_org) + Organization.request(gitea, test_org) def test_delete_user(): - user = User.get(gitea, test_user) + user = User.request(gitea, test_user) user.delete() with pytest.raises(NotFoundException) as e: - User.get(gitea, test_user) \ No newline at end of file + User.request(gitea, test_user) \ No newline at end of file