kopia lustrzana https://github.com/Langenfeld/py-gitea
(testing) rudimentary uploading of files (see #16)
rodzic
756759facc
commit
32c8d03f34
|
@ -535,6 +535,13 @@ class Repository(ApiObject):
|
||||||
else:
|
else:
|
||||||
return [Content.parse_response(self.gitea, f) for f in self.gitea.requests_get(url, data)]
|
return [Content.parse_response(self.gitea, f) for f in self.gitea.requests_get(url, data)]
|
||||||
|
|
||||||
|
def put_file_content(self, file_path: str, data: "data" = dict):
|
||||||
|
"""https://try.gitea.io/api/swagger#/repository/repoCreateFile"""
|
||||||
|
url = f"/repos/{self.owner.username}/{self.name}/contents/{file_path}"
|
||||||
|
if "content" not in data:
|
||||||
|
raise Exception("No Data to upload is supplied. Please give 'content' Field with data")
|
||||||
|
return self.gitea.requests_post(url, data)
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
self.gitea.requests_delete(
|
self.gitea.requests_delete(
|
||||||
Repository.REPO_DELETE % (self.owner.username, self.name)
|
Repository.REPO_DELETE % (self.owner.username, self.name)
|
||||||
|
|
|
@ -147,6 +147,21 @@ def test_list_files_and_content(instance):
|
||||||
assert len(readme_content) > 0
|
assert len(readme_content) > 0
|
||||||
assert "descr" in str(base64.b64decode(readme_content))
|
assert "descr" in str(base64.b64decode(readme_content))
|
||||||
|
|
||||||
|
def test_put_files_and_content(instance):
|
||||||
|
TESTFILE_CONENTE = "TestStringFileContent"
|
||||||
|
TESTFILE_CONENTE_B64 = base64.b64encode(bytes(TESTFILE_CONENTE, 'utf-8'))
|
||||||
|
org = Organization.request(instance, test_org)
|
||||||
|
repo = org.get_repository(test_repo)
|
||||||
|
repo.put_file_content("testfile.md",
|
||||||
|
{"content": TESTFILE_CONENTE_B64.decode("ascii")})
|
||||||
|
# test if putting was successful
|
||||||
|
content = repo.get_git_content()
|
||||||
|
readmes = [c for c in content if c.name == "testfile.md"]
|
||||||
|
assert len(readmes) > 0
|
||||||
|
readme_content = repo.get_file_content(readmes[0])
|
||||||
|
assert len(readme_content) > 0
|
||||||
|
assert TESTFILE_CONENTE in str(base64.b64decode(readme_content))
|
||||||
|
|
||||||
def test_create_branch(instance):
|
def test_create_branch(instance):
|
||||||
org = Organization.request(instance, test_org)
|
org = Organization.request(instance, test_org)
|
||||||
repo = org.get_repository(test_repo)
|
repo = org.get_repository(test_repo)
|
||||||
|
|
Ładowanie…
Reference in New Issue