fixing some of the hash functions

pull/10/head
Langenfeld 2021-11-12 14:21:54 +01:00
rodzic 690816f3d5
commit 16f01d0e0a
2 zmienionych plików z 27 dodań i 6 usunięć

Wyświetl plik

@ -234,10 +234,10 @@ class Branch(GiteaApiObject):
def __eq__(self, other):
if not isinstance(other, Branch): return False
return self.repo == other.repo and self.name == other.name
return self.commit == other.commit and self.name == other.name
def __hash__(self):
return hash(self.repo) ^ hash(self.name)
return hash(self.commit) ^ hash(self.name)
fields_to_parsers = {
"commit": lambda gitea, c: Commit.parse_response(gitea, c)
@ -263,6 +263,7 @@ class Repository(GiteaApiObject):
REPO_TRANSFER = "/repos/{owner}/{repo}/transfer"
REPO_CONTENTS = "/repos/{owner}/{repo}/contents"
REPO_CONTENT = """/repos/{owner}/{repo}/contents/{filepath}"""
REPO_MILESTONES = """/repos/{owner}/{repo}/milestones"""
def __init__(self, gitea):
super(Repository, self).__init__(gitea)
@ -384,6 +385,13 @@ class Repository(GiteaApiObject):
)
return Issue.parse_response(self.gitea, result)
def create_milestone(self, title: str, description: str, due_date: str = None, state:str = "open") -> "Milestone":
url = Repository.REPO_MILESTONES.format(owner=self.owner.username, repo=self.name)
data= {"title": title, "description": description, "state": state}
if due_date: data["due_date"] = due_date
result = self.gitea.requests_post(url, data=data)
return Milestone.parse_response(self.gitea, result)
def create_gitea_hook(self, hook_url: str, events: List[str]):
url = f"/repos/{self.owner.username}/{self.name}/hooks"
data = {
@ -476,10 +484,10 @@ class Milestone(GiteaApiObject):
def __eq__(self, other):
if not isinstance(other, Milestone): return False
return self.repo == other.repo and self.id == other.id
return self.gitea == other.gitea and self.id == other.id
def __hash__(self):
return hash(self.repo) ^ hash(self.id)
return hash(self.gitea) ^ hash(self.id)
fields_to_parsers = {
"closed_at": lambda gitea, t: Util.convert_time(t),
@ -541,10 +549,10 @@ class Commit(GiteaApiObject):
def __eq__(self, other):
if not isinstance(other, Commit): return False
return self.repo == other.repo and self.ref == other.ref
return self.sha == other.sha
def __hash__(self):
return hash(self.repo) ^ hash(self.ref)
return hash(self.sha)
@classmethod
def request(cls, gitea, owner, repo):

Wyświetl plik

@ -193,6 +193,19 @@ def test_create_issue(instance):
assert issue.title == "TestIssue"
assert issue.body == "Body text with this issue"
def test_hashing(instance):
#just call the hash function of each object to see if something bad happens
org = Organization.request(instance, test_org)
team = org.get_team(test_team)
user = instance.get_user_by_name(test_user)
#TODO test for milestones (Todo: add milestone adding)
repo = org.get_repositories()[0]
milestone = repo.create_milestone("mystone", "this is only a teststone")
issue = repo.get_issues()[0]
branch = repo.get_branches()[0]
commit = repo.get_commits()[0]
assert len(set([org, team, user, repo, issue, branch, commit, milestone]))
def test_team_get_org(instance):
org = Organization.request(instance, test_org)
user = instance.get_user_by_name(test_user)