diff --git a/allspice/allspice.py b/allspice/allspice.py index ddaadb1..76d0a5a 100644 --- a/allspice/allspice.py +++ b/allspice/allspice.py @@ -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) diff --git a/allspice/apiobject.py b/allspice/apiobject.py index 6f257bc..fdefdbf 100644 --- a/allspice/apiobject.py +++ b/allspice/apiobject.py @@ -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", diff --git a/allspice/utils/netlist_generation.py b/allspice/utils/netlist_generation.py index 2e5a9d3..8ca013c 100644 --- a/allspice/utils/netlist_generation.py +++ b/allspice/utils/netlist_generation.py @@ -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 diff --git a/tests/test_api.py b/tests/test_api.py index 79b0038..7b2a7e1 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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)