Skip to content

Commit

Permalink
Merge pull request #56 from AllSpiceIO/kd/enable_delete_data
Browse files Browse the repository at this point in the history
Add delete_file routine
  • Loading branch information
kdumontnu authored Oct 27, 2023
2 parents 1f9eff5 + 3134256 commit 787afb8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
7 changes: 4 additions & 3 deletions allspice/allspice.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ def requests_put(self, endpoint: str, data: Optional[dict] = None):
self.logger.error(message)
raise Exception(message)

def requests_delete(self, endpoint: str):
request = self.requests.delete(self.__get_url(endpoint), headers=self.headers)
if request.status_code not in [204]:
def requests_delete(self, endpoint: str, data: Optional[dict] = None):
request = self.requests.delete(self.__get_url(
endpoint), headers=self.headers, data=json.dumps(data))
if request.status_code not in [200, 204]:
message = f"Received status code: {request.status_code} ({request.url})"
self.logger.error(message)
raise Exception(message)
Expand Down
8 changes: 8 additions & 0 deletions allspice/apiobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,14 @@ def change_file(self, file_path: str, file_sha: str, content: str, data: Optiona
data.update({"sha": file_sha, "content": content})
return self.allspice_client.requests_put(url, data)

def delete_file(self, file_path: str, file_sha: str, data: Optional[dict] = None):
"""https://hub.allspice.io/api/swagger#/repository/repoDeleteFile"""
if not data:
data = {}
url = f"/repos/{self.owner.username}/{self.name}/contents/{file_path}"
data.update({"sha": file_sha})
return self.allspice_client.requests_delete(url, data)

def get_archive(
self,
ref: Ref = "main",
Expand Down
2 changes: 1 addition & 1 deletion allspice/utils/netlist_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _extract_all_pcb_components(
try:
net = pin["net_name"]
except KeyError:
logger.warn(
logger.warning(
f"Unconnected pad: {designator} in component {component['designator']}.")
continue

Expand Down
14 changes: 14 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,20 @@ def test_change_file(instance):
assert TESTFILE_CONENTE in str(base64.b64decode(readme_content))


def test_delete_file(instance):
org = Organization.request(instance, test_org)
repo = org.get_repository(test_repo)
# figure out the sha of the file to change
content = repo.get_git_content()
readmes = [c for c in content if c.name == "testfile.md"]
# delete
repo.delete_file("testfile.md", readmes[0].sha)
# test if deletion was successful
content = repo.get_git_content()
readmes = [c for c in content if c.name == "testfile.md"]
assert len(readmes) == 0


def test_create_branch(instance):
org = Organization.request(instance, test_org)
repo = org.get_repository(test_repo)
Expand Down

0 comments on commit 787afb8

Please sign in to comment.