dcicutils 8.7.0.1b3__py3-none-any.whl → 8.7.0.1b5__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
dcicutils/portal_utils.py CHANGED
@@ -202,28 +202,45 @@ class Portal:
202
202
  def vapp(self) -> Optional[TestApp]:
203
203
  return self._vapp
204
204
 
205
- def get(self, url: str, follow: bool = True, **kwargs) -> OptionalResponse:
205
+ def get(self, url: str, follow: bool = True, raise_for_status: bool = False, **kwargs) -> OptionalResponse:
206
+ url = self.url(url)
206
207
  if not self._vapp:
207
- return requests.get(self.url(url), allow_redirects=follow, **self._kwargs(**kwargs))
208
- response = self._vapp.get(self.url(url), **self._kwargs(**kwargs))
209
- if response and response.status_code in [301, 302, 303, 307, 308] and follow:
210
- response = response.follow()
211
- return self._response(response)
208
+ response = requests.get(url, allow_redirects=follow, **self._kwargs(**kwargs))
209
+ else:
210
+ response = self._vapp.get(url, **self._kwargs(**kwargs))
211
+ if response and response.status_code in [301, 302, 303, 307, 308] and follow:
212
+ response = response.follow()
213
+ response = self._response(response)
214
+ if raise_for_status:
215
+ response.raise_for_status()
216
+ return response
212
217
 
213
- def patch(self, url: str, data: Optional[dict] = None, json: Optional[dict] = None, **kwargs) -> OptionalResponse:
218
+ def patch(self, url: str, data: Optional[dict] = None, json: Optional[dict] = None,
219
+ raise_for_status: bool = False, **kwargs) -> OptionalResponse:
220
+ url = self.url(url)
214
221
  if not self._vapp:
215
- return requests.patch(self.url(url), data=data, json=json, **self._kwargs(**kwargs))
216
- return self._response(self._vapp.patch_json(self.url(url), json or data, **self._kwargs(**kwargs)))
222
+ response = requests.patch(url, data=data, json=json, **self._kwargs(**kwargs))
223
+ else:
224
+ response = self._vapp.patch_json(url, json or data, **self._kwargs(**kwargs))
225
+ response = self._response(response)
226
+ if raise_for_status:
227
+ response.raise_for_status()
228
+ return response
217
229
 
218
- def post(self, url: str, data: Optional[dict] = None, json: Optional[dict] = None,
219
- files: Optional[dict] = None, **kwargs) -> OptionalResponse:
230
+ def post(self, url: str, data: Optional[dict] = None, json: Optional[dict] = None, files: Optional[dict] = None,
231
+ raise_for_status: bool = False, **kwargs) -> OptionalResponse:
232
+ url = self.url(url)
220
233
  if not self._vapp:
221
- return requests.post(self.url(url), data=data, json=json, files=files, **self._kwargs(**kwargs))
222
- if files:
223
- response = self._vapp.post(self.url(url), json or data, upload_files=files, **self._kwargs(**kwargs))
234
+ response = requests.post(url, data=data, json=json, files=files, **self._kwargs(**kwargs))
224
235
  else:
225
- response = self._vapp.post_json(self.url(url), json or data, upload_files=files, **self._kwargs(**kwargs))
226
- return self._response(response)
236
+ if files:
237
+ response = self._vapp.post(url, json or data, upload_files=files, **self._kwargs(**kwargs))
238
+ else:
239
+ response = self._vapp.post_json(url, json or data, upload_files=files, **self._kwargs(**kwargs))
240
+ response = self._response(response)
241
+ if raise_for_status:
242
+ response.raise_for_status()
243
+ return response
227
244
 
228
245
  def get_metadata(self, object_id: str) -> Optional[dict]:
229
246
  return get_metadata(obj_id=object_id, vapp=self._vapp, key=self._key)
@@ -257,11 +274,28 @@ class Portal:
257
274
  def schema_name(name: str) -> str:
258
275
  return to_camel_case(name if not name.endswith(".json") else name[:-5]) if isinstance(name, str) else ""
259
276
 
277
+ def is_schema_type(self, value: dict, schema_type: str) -> bool:
278
+ """
279
+ Returns True iff the given object isa type of the given schema type.
280
+ """
281
+ if isinstance(value, dict) and (value_types := value.get("@type")):
282
+ if isinstance(value_types, str):
283
+ return self.is_specified_schema(value_types, schema_type)
284
+ elif isinstance(value_types, list):
285
+ for value_type in value_types:
286
+ if self.is_specified_schema(value_type, schema_type):
287
+ return True
288
+ return False
289
+
260
290
  def is_specified_schema(self, schema_name: str, schema_type: str) -> bool:
261
291
  """
262
292
  Returns True iff the given schema name isa type of the given schema type name,
263
293
  i.e. has an ancestor which is of type that given type.
264
294
  """
295
+ schema_name = self.schema_name(schema_name)
296
+ schema_type = self.schema_name(schema_type)
297
+ if schema_name == schema_type:
298
+ return True
265
299
  if super_type_map := self.get_schemas_super_type_map():
266
300
  if super_type := super_type_map.get(schema_type):
267
301
  return self.schema_name(schema_name) in super_type
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dcicutils
3
- Version: 8.7.0.1b3
3
+ Version: 8.7.0.1b5
4
4
  Summary: Utility package for interacting with the 4DN Data Portal and other 4DN resources
5
5
  Home-page: https://github.com/4dn-dcic/utils
6
6
  License: MIT
@@ -43,7 +43,7 @@ dcicutils/log_utils.py,sha256=7pWMc6vyrorUZQf-V-M3YC6zrPgNhuV_fzm9xqTPph0,10883
43
43
  dcicutils/misc_utils.py,sha256=bMRWWxdbhuF3PKdCZEH-H4U1ecgT3Nag3EL92D9XGoY,100973
44
44
  dcicutils/obfuscation_utils.py,sha256=fo2jOmDRC6xWpYX49u80bVNisqRRoPskFNX3ymFAmjw,5963
45
45
  dcicutils/opensearch_utils.py,sha256=V2exmFYW8Xl2_pGFixF4I2Cc549Opwe4PhFi5twC0M8,1017
46
- dcicutils/portal_utils.py,sha256=zC63pKle9l3E0c8lOfERpoEbfbm1ZOBEKT7Lk-y4f3E,21769
46
+ dcicutils/portal_utils.py,sha256=0fZ-PMB-oUDroUkMdoZ55xLEpfDz9a94jOZXrK3A0n8,23069
47
47
  dcicutils/project_utils.py,sha256=qPdCaFmWUVBJw4rw342iUytwdQC0P-XKpK4mhyIulMM,31250
48
48
  dcicutils/qa_checkers.py,sha256=cdXjeL0jCDFDLT8VR8Px78aS10hwNISOO5G_Zv2TZ6M,20534
49
49
  dcicutils/qa_utils.py,sha256=TT0SiJWiuxYvbsIyhK9VO4uV_suxhB6CpuC4qPacCzQ,160208
@@ -64,8 +64,8 @@ dcicutils/trace_utils.py,sha256=g8kwV4ebEy5kXW6oOrEAUsurBcCROvwtZqz9fczsGRE,1769
64
64
  dcicutils/validation_utils.py,sha256=cMZIU2cY98FYtzK52z5WUYck7urH6JcqOuz9jkXpqzg,14797
65
65
  dcicutils/variant_utils.py,sha256=2H9azNx3xAj-MySg-uZ2SFqbWs4kZvf61JnK6b-h4Qw,4343
66
66
  dcicutils/zip_utils.py,sha256=rnjNv_k6L9jT2SjDSgVXp4BEJYLtz9XN6Cl2Fy-tqnM,2027
67
- dcicutils-8.7.0.1b3.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
68
- dcicutils-8.7.0.1b3.dist-info/METADATA,sha256=dPoOwNN77Bp6tSt9vxBi1qQiHq0SnzZXPePSAhyEKTk,3314
69
- dcicutils-8.7.0.1b3.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
70
- dcicutils-8.7.0.1b3.dist-info/entry_points.txt,sha256=8wbw5csMIgBXhkwfgsgJeuFcoUc0WsucUxmOyml2aoA,209
71
- dcicutils-8.7.0.1b3.dist-info/RECORD,,
67
+ dcicutils-8.7.0.1b5.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
68
+ dcicutils-8.7.0.1b5.dist-info/METADATA,sha256=Dz4-8ARIZnllxNziTwz3y_Jnd-kdoRb2diBJhRh2bUE,3314
69
+ dcicutils-8.7.0.1b5.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
70
+ dcicutils-8.7.0.1b5.dist-info/entry_points.txt,sha256=8wbw5csMIgBXhkwfgsgJeuFcoUc0WsucUxmOyml2aoA,209
71
+ dcicutils-8.7.0.1b5.dist-info/RECORD,,