def test_empty_response_repr(): """Tests that the repr output expresses the absence of body and status code correctly.""" resp = Response() no_body_found = re.search("No body available", resp.__repr__()) no_status_code_found = re.search("No HTTP status available", resp.__repr__()) assert no_body_found assert no_status_code_found
def test_empty_body_present_code(): """Tests that the repr output expresses the absence of body and presence of status code correctly.""" resp_with_code = Response(status_code=404) no_body_found = re.search("No body available", resp_with_code.__repr__()) status_code_found = re.search("404", resp_with_code.__repr__()) assert no_body_found assert status_code_found
def test_empty_body_present_code(): """Tests that the repr output expresses the presence of body and presence of status code correctly.""" resp_with_code_and_body = Response(status_code=404, body={"message": "a quick message"}) body_found = re.search("a quick message", resp_with_code_and_body.__repr__()) status_code_found = re.search("404", resp_with_code_and_body.__repr__()) assert body_found assert status_code_found
def delete(self, uid: Union[UUID, str], scope: str = 'id'): """ Delete the element of the collection with ID equal to uid. Parameters ---------- uid: Union[UUID, str] The ID. scope: str The scope of the uid, defaults to Citrine scope ('id') """ path = self._get_path() + "/{}/{}".format(scope, uid) self.session.delete_resource(path) return Response(status_code=200) # delete succeeded
def delete(self, file_link: FileLink): """ Delete the file associated with a given FileLink from the database. Parameters ---------- file_link: FileLink Resource referencing the external file. """ split_url = file_link.url.split('/') assert split_url[-2] == 'versions' and split_url[-4] == 'files', \ "File URL is expected to end with '/files/{{file_id}}/version/{{version id}}', " \ "but FileLink instead has url {}".format(file_link.url) file_id = split_url[-3] data = self.session.delete_resource(self._get_path(file_id)) return Response(body=data)
def delete(self, uid: Union[UUID, str], scope: str = CITRINE_SCOPE, dry_run: bool = False): """ Delete the element of the collection with ID equal to uid. Parameters ---------- uid: Union[UUID, str] The ID. scope: str The scope of the uid, defaults to Citrine scope (CITRINE_SCOPE) dry_run: bool Whether to actually delete the item or run a dry run of the delete operation. Dry run is intended to be used for validation. Default: false """ path = self._get_path() + "/{}/{}".format(scope, uid) params = {'dry_run': dry_run} self.session.delete_resource(path, params=params) return Response(status_code=200) # delete succeeded
def delete(self, uid: Union[UUID, str]) -> Response: """Delete a particular element of the collection.""" url = self._get_path(uid) data = self.session.delete_resource(url) return Response(body=data)