(testing) rudimentary uploading of files (see #16)

pull/20/head
Langenfeld 2023-01-24 18:10:03 +01:00
rodzic 756759facc
commit 32c8d03f34
2 zmienionych plików z 22 dodań i 0 usunięć

Wyświetl plik

@ -535,6 +535,13 @@ class Repository(ApiObject):
else:
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):
self.gitea.requests_delete(
Repository.REPO_DELETE % (self.owner.username, self.name)

Wyświetl plik

@ -147,6 +147,21 @@ def test_list_files_and_content(instance):
assert len(readme_content) > 0
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):
org = Organization.request(instance, test_org)
repo = org.get_repository(test_repo)