Skip to content

Commit

Permalink
Added Portal.is_specified_type to portal_utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Jan 4, 2024
1 parent 8525315 commit 10a421d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
49 changes: 33 additions & 16 deletions dcicutils/portal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,28 +202,45 @@ def app(self) -> Optional[str]:
def vapp(self) -> Optional[TestApp]:
return self._vapp

def get(self, url: str, follow: bool = True, **kwargs) -> OptionalResponse:
def get(self, url: str, follow: bool = True, raise_for_status: bool = False, **kwargs) -> OptionalResponse:
url = self.url(url)
if not self._vapp:
return requests.get(self.url(url), allow_redirects=follow, **self._kwargs(**kwargs))
response = self._vapp.get(self.url(url), **self._kwargs(**kwargs))
if response and response.status_code in [301, 302, 303, 307, 308] and follow:
response = response.follow()
return self._response(response)
response = requests.get(url, allow_redirects=follow, **self._kwargs(**kwargs))
else:
response = self._vapp.get(url, **self._kwargs(**kwargs))
if response and response.status_code in [301, 302, 303, 307, 308] and follow:
response = response.follow()
response = self._response(response)
if raise_for_status:
response.raise_for_status()
return response

def patch(self, url: str, data: Optional[dict] = None, json: Optional[dict] = None, **kwargs) -> OptionalResponse:
def patch(self, url: str, data: Optional[dict] = None, json: Optional[dict] = None,
raise_for_status: bool = False, **kwargs) -> OptionalResponse:
url = self.url(url)
if not self._vapp:
return requests.patch(self.url(url), data=data, json=json, **self._kwargs(**kwargs))
return self._response(self._vapp.patch_json(self.url(url), json or data, **self._kwargs(**kwargs)))
response = requests.patch(url, data=data, json=json, **self._kwargs(**kwargs))
else:
response = self._vapp.patch_json(url, json or data, **self._kwargs(**kwargs))
response = self._response(response)
if raise_for_status:
response.raise_for_status()
return response

def post(self, url: str, data: Optional[dict] = None, json: Optional[dict] = None,
files: Optional[dict] = None, **kwargs) -> OptionalResponse:
def post(self, url: str, data: Optional[dict] = None, json: Optional[dict] = None, files: Optional[dict] = None,
raise_for_status: bool = False, **kwargs) -> OptionalResponse:
url = self.url(url)
if not self._vapp:
return requests.post(self.url(url), data=data, json=json, files=files, **self._kwargs(**kwargs))
if files:
response = self._vapp.post(self.url(url), json or data, upload_files=files, **self._kwargs(**kwargs))
response = requests.post(url, data=data, json=json, files=files, **self._kwargs(**kwargs))
else:
response = self._vapp.post_json(self.url(url), json or data, upload_files=files, **self._kwargs(**kwargs))
return self._response(response)
if files:
response = self._vapp.post(url, json or data, upload_files=files, **self._kwargs(**kwargs))
else:
response = self._vapp.post_json(url, json or data, upload_files=files, **self._kwargs(**kwargs))
response = self._response(response)
if raise_for_status:
response.raise_for_status()
return response

def get_metadata(self, object_id: str) -> Optional[dict]:
return get_metadata(obj_id=object_id, vapp=self._vapp, key=self._key)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicutils"
version = "8.7.0.1b4" # TODO: To become 8.7.1
version = "8.7.0.1b5" # TODO: To become 8.7.1
description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
authors = ["4DN-DCIC Team <support@4dnucleome.org>"]
license = "MIT"
Expand Down

0 comments on commit 10a421d

Please sign in to comment.