kopia lustrzana https://github.com/Langenfeld/py-gitea
fixed exidental overwriting of nested api objects by adding the writable properties
rodzic
f4ca29bfc8
commit
a14fda209f
|
@ -18,7 +18,7 @@ class Organization(ApiObject):
|
||||||
ORG_HEATMAP = """/users/%s/heatmap""" # <username>
|
ORG_HEATMAP = """/users/%s/heatmap""" # <username>
|
||||||
|
|
||||||
def __init__(self, gitea):
|
def __init__(self, gitea):
|
||||||
super(Organization, self).__init__(gitea)
|
super().__init__(gitea)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if not isinstance(other, Organization): return False
|
if not isinstance(other, Organization): return False
|
||||||
|
@ -122,7 +122,7 @@ class User(ApiObject):
|
||||||
USER_HEATMAP = """/users/%s/heatmap""" # <username>
|
USER_HEATMAP = """/users/%s/heatmap""" # <username>
|
||||||
|
|
||||||
def __init__(self, gitea):
|
def __init__(self, gitea):
|
||||||
super(User, self).__init__(gitea)
|
super().__init__(gitea)
|
||||||
self._emails = []
|
self._emails = []
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
|
@ -222,7 +222,7 @@ class User(ApiObject):
|
||||||
class Branch(ReadonlyApiObject):
|
class Branch(ReadonlyApiObject):
|
||||||
|
|
||||||
def __init__(self, gitea):
|
def __init__(self, gitea):
|
||||||
super(Branch, self).__init__(gitea)
|
super().__init__(gitea)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if not isinstance(other, Branch):
|
if not isinstance(other, Branch):
|
||||||
|
@ -258,7 +258,7 @@ class Repository(ApiObject):
|
||||||
REPO_MILESTONES = """/repos/{owner}/{repo}/milestones"""
|
REPO_MILESTONES = """/repos/{owner}/{repo}/milestones"""
|
||||||
|
|
||||||
def __init__(self, gitea):
|
def __init__(self, gitea):
|
||||||
super(Repository, self).__init__(gitea)
|
super().__init__(gitea)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if not isinstance(other, Repository): return False
|
if not isinstance(other, Repository): return False
|
||||||
|
@ -469,7 +469,7 @@ class Milestone(ApiObject):
|
||||||
API_OBJECT = """/repos/{owner}/{repo}/milestones/{number}""" # <owner, repo>
|
API_OBJECT = """/repos/{owner}/{repo}/milestones/{number}""" # <owner, repo>
|
||||||
|
|
||||||
def __init__(self, gitea):
|
def __init__(self, gitea):
|
||||||
super(Milestone, self).__init__(gitea)
|
super().__init__(gitea)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if not isinstance(other, Milestone): return False
|
if not isinstance(other, Milestone): return False
|
||||||
|
@ -508,7 +508,7 @@ class Milestone(ApiObject):
|
||||||
class Comment(ApiObject):
|
class Comment(ApiObject):
|
||||||
|
|
||||||
def __init__(self, gitea):
|
def __init__(self, gitea):
|
||||||
super(Comment, self).__init__(gitea)
|
super().__init__(gitea)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if not isinstance(other, Comment): return False
|
if not isinstance(other, Comment): return False
|
||||||
|
@ -525,8 +525,9 @@ class Comment(ApiObject):
|
||||||
|
|
||||||
|
|
||||||
class Commit(ReadonlyApiObject):
|
class Commit(ReadonlyApiObject):
|
||||||
|
|
||||||
def __init__(self, gitea):
|
def __init__(self, gitea):
|
||||||
super(Commit, self).__init__(gitea)
|
super().__init__(gitea)
|
||||||
|
|
||||||
_fields_to_parsers = {
|
_fields_to_parsers = {
|
||||||
# NOTE: api may return None for commiters that are no gitea users
|
# NOTE: api may return None for commiters that are no gitea users
|
||||||
|
@ -560,7 +561,7 @@ class Issue(ApiObject):
|
||||||
CLOSED = "closed"
|
CLOSED = "closed"
|
||||||
|
|
||||||
def __init__(self, gitea):
|
def __init__(self, gitea):
|
||||||
super(Issue, self).__init__(gitea)
|
super().__init__(gitea)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if not isinstance(other, Issue): return False
|
if not isinstance(other, Issue): return False
|
||||||
|
@ -660,7 +661,7 @@ class Team(ApiObject):
|
||||||
GET_REPOS = """/teams/%s/repos""" # <id>
|
GET_REPOS = """/teams/%s/repos""" # <id>
|
||||||
|
|
||||||
def __init__(self, gitea):
|
def __init__(self, gitea):
|
||||||
super(Team, self).__init__(gitea)
|
super().__init__(gitea)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if not isinstance(other, Team): return False
|
if not isinstance(other, Team): return False
|
||||||
|
@ -708,7 +709,7 @@ class Content(ReadonlyApiObject):
|
||||||
FILE = "file"
|
FILE = "file"
|
||||||
|
|
||||||
def __init__(self, gitea):
|
def __init__(self, gitea):
|
||||||
super(Content, self).__init__(gitea)
|
super().__init__(gitea)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if not isinstance(other, Team): return False
|
if not isinstance(other, Team): return False
|
||||||
|
|
|
@ -21,7 +21,7 @@ class ReadonlyApiObject:
|
||||||
_fields_to_parsers = {}
|
_fields_to_parsers = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def request(cls, gitea, id):
|
def request(cls, gitea):
|
||||||
if hasattr("API_OBJECT", cls):
|
if hasattr("API_OBJECT", cls):
|
||||||
return cls._request(gitea)
|
return cls._request(gitea)
|
||||||
else:
|
else:
|
||||||
|
@ -47,6 +47,7 @@ class ReadonlyApiObject:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _initialize(cls, gitea, api_object, result):
|
def _initialize(cls, gitea, api_object, result):
|
||||||
|
x = 1
|
||||||
for name, value in result.items():
|
for name, value in result.items():
|
||||||
if name in cls._fields_to_parsers and value is not None:
|
if name in cls._fields_to_parsers and value is not None:
|
||||||
parse_func = cls._fields_to_parsers[name]
|
parse_func = cls._fields_to_parsers[name]
|
||||||
|
@ -60,10 +61,10 @@ class ReadonlyApiObject:
|
||||||
@classmethod
|
@classmethod
|
||||||
def _add_read_property(cls, name, value, api_object):
|
def _add_read_property(cls, name, value, api_object):
|
||||||
if not hasattr(api_object, name):
|
if not hasattr(api_object, name):
|
||||||
|
setattr(api_object, "_" + name, value)
|
||||||
prop = property(
|
prop = property(
|
||||||
(lambda name: lambda self: self._get_var(name))(name))
|
(lambda name: lambda self: self._get_var(name))(name))
|
||||||
setattr(cls, name, prop)
|
setattr(cls, name, prop)
|
||||||
setattr(api_object, "_" + name, value)
|
|
||||||
else:
|
else:
|
||||||
raise AttributeError(f"Attribute {name} already exists on api object.")
|
raise AttributeError(f"Attribute {name} already exists on api object.")
|
||||||
|
|
||||||
|
@ -98,21 +99,17 @@ class ApiObject(ReadonlyApiObject):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _initialize(cls, gitea, api_object, result):
|
def _initialize(cls, gitea, api_object, result):
|
||||||
super()._initialize(gitea, api_object, result)
|
super()._initialize(gitea, api_object, result)
|
||||||
for name, value in result.items():
|
|
||||||
if name in cls._patchable_fields:
|
|
||||||
cls._add_write_property(name, value, api_object)
|
|
||||||
# add all patchable fields missing in the request to be writable
|
|
||||||
for name in cls._patchable_fields:
|
for name in cls._patchable_fields:
|
||||||
if not hasattr(api_object, name):
|
|
||||||
cls._add_write_property(name, None, api_object)
|
cls._add_write_property(name, None, api_object)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _add_write_property(cls, name, value, api_object):
|
def _add_write_property(cls, name, value, api_object):
|
||||||
|
if not hasattr(api_object, "_" + name):
|
||||||
|
setattr(api_object, "_" + name, value)
|
||||||
prop = property(
|
prop = property(
|
||||||
(lambda name: lambda self: self._get_var(name))(name),
|
(lambda name: lambda self: self._get_var(name))(name),
|
||||||
(lambda name: lambda self, v: self.__set_var(name, v))(name))
|
(lambda name: lambda self, v: self.__set_var(name, v))(name))
|
||||||
setattr(cls, name, prop)
|
setattr(cls, name, prop)
|
||||||
setattr(api_object, "_" + name, value)
|
|
||||||
|
|
||||||
def __set_var(self, name, i):
|
def __set_var(self, name, i):
|
||||||
if self.deleted:
|
if self.deleted:
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -5,7 +5,7 @@ with open('README.md') as readme_file:
|
||||||
|
|
||||||
setup_args = dict(
|
setup_args = dict(
|
||||||
name='py-gitea',
|
name='py-gitea',
|
||||||
version='0.1.9',
|
version='0.1.10',
|
||||||
description='A python wrapper for the Gitea API',
|
description='A python wrapper for the Gitea API',
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
long_description=README,
|
long_description=README,
|
||||||
|
|
|
@ -230,9 +230,12 @@ def test_change_issue(instance):
|
||||||
issue2.milestone = milestone
|
issue2.milestone = milestone
|
||||||
issue2.commit()
|
issue2.commit()
|
||||||
del issue2
|
del issue2
|
||||||
|
issue3 = Issue.request(instance, org.username, repo.name, number)
|
||||||
|
assert issue3.milestone is not None
|
||||||
|
assert issue3.milestone.description == "this is only a teststone2"
|
||||||
issues = repo.get_issues()
|
issues = repo.get_issues()
|
||||||
#assert len([issue for issue in issues
|
assert len([issue for issue in issues
|
||||||
# if issue.milestone is not None and issue.milestone.title == ms_title]) > 0
|
if issue.milestone is not None and issue.milestone.title == ms_title]) > 0
|
||||||
|
|
||||||
def test_team_get_org(instance):
|
def test_team_get_org(instance):
|
||||||
org = Organization.request(instance, test_org)
|
org = Organization.request(instance, test_org)
|
||||||
|
|
Ładowanie…
Reference in New Issue