From 32e20649969a7f063d7aae016bddc0f9b8346dd5 Mon Sep 17 00:00:00 2001 From: singhpranjali Date: Thu, 25 Aug 2022 15:17:11 +0200 Subject: [PATCH] Fixed JSON deserialization (#43) --- marketplace/app/v0/base.py | 11 +++--- marketplace/app/v0/object_storage.py | 24 ++++++------- marketplace/app/v0/transformation.py | 52 +++++++++++----------------- 3 files changed, 34 insertions(+), 53 deletions(-) diff --git a/marketplace/app/v0/base.py b/marketplace/app/v0/base.py index 5dbdec1..253ac07 100644 --- a/marketplace/app/v0/base.py +++ b/marketplace/app/v0/base.py @@ -1,4 +1,3 @@ -import json from typing import Optional from urllib.parse import urljoin @@ -37,10 +36,8 @@ def global_search( self, q: str, limit: int = 100, offset: int = 0 ) -> GlobalSearchResponse: return GlobalSearchResponse.parse_obj( - json.loads( - self._client.get( - self._proxy_path("globalSearch"), - params={"q": q, "limit": limit, "offset": offset}, - ) - ) + self._client.get( + self._proxy_path("globalSearch"), + params={"q": q, "limit": limit, "offset": offset}, + ).json() ) diff --git a/marketplace/app/v0/object_storage.py b/marketplace/app/v0/object_storage.py index 0377195..e86c4ec 100644 --- a/marketplace/app/v0/object_storage.py +++ b/marketplace/app/v0/object_storage.py @@ -93,14 +93,12 @@ def create_dataset( if dataset_name: params.update({"dataset_name": dataset_name}) return object_storage.DatasetCreateResponse.parse_obj( - json.loads( - self._client.put( - self._proxy_path("createDataset"), - params=params, - headers=_encode_metadata(metadata), - data=file.file, - ) - ) + self._client.put( + self._proxy_path("createDataset"), + params=params, + headers=_encode_metadata(metadata), + data=file.file, + ).json() ) @check_capability_availability @@ -202,10 +200,8 @@ def get_semantic_mapping( self, semantic_mapping_id: str ) -> object_storage.SemanticMappingModel: return object_storage.SemanticMappingModel.parse_obj( - json.loads( - self._client.get( - self._proxy_path("getSemanticMapping"), - params={"semantic_mapping_id": semantic_mapping_id}, - ) - ) + self._client.get( + self._proxy_path("getSemanticMapping"), + params={"semantic_mapping_id": semantic_mapping_id}, + ).json() ) diff --git a/marketplace/app/v0/transformation.py b/marketplace/app/v0/transformation.py index 9087b89..9c57287 100644 --- a/marketplace/app/v0/transformation.py +++ b/marketplace/app/v0/transformation.py @@ -1,5 +1,3 @@ -import json - import marketplace_standard_app_api.models.transformation as transformation from ..utils import check_capability_availability @@ -12,12 +10,10 @@ def get_transformation_list( self, limit: int = 100, offset: int = 0 ) -> transformation.TransformationListResponse: return transformation.TransformationListResponse.parse_obj( - json.loads( - self._client.get( - self._proxy_path("getTransformationList"), - params={"limit": limit, "offset": offset}, - ) - ) + self._client.get( + self._proxy_path("getTransformationList"), + params={"limit": limit, "offset": offset}, + ).json() ) @check_capability_availability @@ -25,11 +21,9 @@ def new_transformation( self, new_transformation: transformation.NewTransformationModel ) -> transformation.TransformationCreateResponse: return transformation.TransformationCreateResponse.parse_obj( - json.loads( - self._client.post( - self._proxy_path("newTransformation"), json=new_transformation - ) - ) + self._client.post( + self._proxy_path("newTransformation"), json=new_transformation + ).json() ) @check_capability_availability @@ -37,12 +31,10 @@ def get_transformation( self, transformation_id: transformation.TransformationId ) -> transformation.TransformationModel: return transformation.TransformationModel.parse_obj( - json.loads( - self._client.get( - self._proxy_path("getTransformation"), - params={"transformation_id": transformation_id}, - ) - ) + self._client.get( + self._proxy_path("getTransformation"), + params={"transformation_id": transformation_id}, + ).json() ) @check_capability_availability @@ -59,13 +51,11 @@ def _update_transformation( update: transformation.TransformationUpdateModel, ) -> transformation.TransformationUpdateResponse: return transformation.TransformationUpdateResponse.parse_obj( - json.loads( - self._client.patch( - self._proxy_path("updateTransformation"), - params={"transformation_id": transformation_id}, - json=update, - ) - ) + self._client.patch( + self._proxy_path("updateTransformation"), + params={"transformation_id": transformation_id}, + json=update, + ).json() ) def start_transformation( @@ -107,10 +97,8 @@ def get_transformation_state( self, transformation_id: transformation.TransformationId ) -> transformation.TransformationState: return transformation.TransformationStateResponse.parse_obj( - json.loads( - self._client.get( - self._proxy_path("getTransformationState"), - params={"transformation_id": transformation_id}, - ) - ) + self._client.get( + self._proxy_path("getTransformationState"), + params={"transformation_id": transformation_id}, + ).json() ).state