Commit 7db667be authored by Ritika Kaushal's avatar Ritika Kaushal
Browse files

changes for flake8

parent a2c7d8f6
Pipeline #108245 failed with stages
in 2 minutes and 20 seconds
...@@ -18,15 +18,13 @@ class TestOsduClient: ...@@ -18,15 +18,13 @@ class TestOsduClient:
_expected_ids_str = [{"id": "321"}, {"id": "432"}, {"id": "543"}] _expected_ids_str = [{"id": "321"}, {"id": "432"}, {"id": "543"}]
_access_token = "token" _access_token = "token"
_data_partition_id = "AnId" _data_partition_id = "AnId"
_serviceName= "wellbore" _serviceName = "wellbore"
mockConfig = Mock(spec=Configuration) mockConfig = Mock(spec=Configuration)
mockConfig.data_partition_id= "AnId" mockConfig.data_partition_id = "AnId"
mockConfig.wellbore_service_path_prefix=None mockConfig.wellbore_service_path_prefix = None
mockConfig.search_service_path_prefix=None mockConfig.search_service_path_prefix = None
mockConfig.base_url = "http://test.bp.com" mockConfig.base_url = "http://test.bp.com"
def match_and_mock_post(self, request: any): def match_and_mock_post(self, request: any):
if request.method != "POST": if request.method != "POST":
return httpx.Response(500, text="Not a post request") return httpx.Response(500, text="Not a post request")
...@@ -81,10 +79,8 @@ class TestOsduClient: ...@@ -81,10 +79,8 @@ class TestOsduClient:
base_url = "http://test.bp.com" base_url = "http://test.bp.com"
record = Record({"kind": "kind", "acl": {}, "legal": "legal", "data": {}}) record = Record({"kind": "kind", "acl": {}, "legal": "legal", "data": {}})
respx_mock.post(f"{base_url}/api/os-wellbore-ddms/ddms/v3/wellbores").mock(side_effect=self.match_and_mock_post) respx_mock.post(f"{base_url}/api/os-wellbore-ddms/ddms/v3/wellbores").mock(side_effect=self.match_and_mock_post)
client = OsduClient(self.mockConfig, self._access_token) client = OsduClient(self.mockConfig, self._access_token)
# Act # Act
...@@ -329,4 +325,4 @@ class TestOsduClient: ...@@ -329,4 +325,4 @@ class TestOsduClient:
# Act # Act
result = client.get_base_url(self._serviceName) result = client.get_base_url(self._serviceName)
assert result == base_url assert result == base_url
\ No newline at end of file
...@@ -40,8 +40,8 @@ class OsduClient: ...@@ -40,8 +40,8 @@ class OsduClient:
self._data_partition_id = config.data_partition_id self._data_partition_id = config.data_partition_id
self._wellbore_service_path_prefix = config.wellbore_service_path_prefix self._wellbore_service_path_prefix = config.wellbore_service_path_prefix
self._search_service_path_prefix = config.search_service_path_prefix self._search_service_path_prefix = config.search_service_path_prefix
self._wellbore_service="wellbore" self._wellbore_service = "wellbore"
self._search_service="search" self._search_service = "search"
def _create_headers(self) -> Dict[str, str]: def _create_headers(self) -> Dict[str, str]:
""" """
...@@ -63,7 +63,8 @@ class OsduClient: ...@@ -63,7 +63,8 @@ class OsduClient:
:return: the id of the new well bore :return: the id of the new well bore
:rtype: str :rtype: str
""" """
return self._post_data_with_id_response(f'{self.get_base_url(self._wellbore_service)}/api/os-wellbore-ddms/ddms/v3/wellbores', record) url = f'{self.get_base_url(self._wellbore_service)}/api/os-wellbore-ddms/ddms/v3/wellbores'
return self._post_data_with_id_response(url, record)
def post_welllog(self, record: Union[Record, WellLogRecord]) -> List[any]: def post_welllog(self, record: Union[Record, WellLogRecord]) -> List[any]:
""" """
...@@ -75,7 +76,8 @@ class OsduClient: ...@@ -75,7 +76,8 @@ class OsduClient:
:return: The ID of the created/updated well log :return: The ID of the created/updated well log
:rtype: List[any] :rtype: List[any]
""" """
return self._post_data_with_id_response(f'{self.get_base_url(self._wellbore_service)}/api/os-wellbore-ddms/ddms/v3/welllogs', record) url = f'{self.get_base_url(self._wellbore_service)}/api/os-wellbore-ddms/ddms/v3/welllogs'
return self._post_data_with_id_response(url, record)
def get_wellbore_record(self, wellbore_id: str) -> Record: def get_wellbore_record(self, wellbore_id: str) -> Record:
""" """
...@@ -130,8 +132,9 @@ class OsduClient: ...@@ -130,8 +132,9 @@ class OsduClient:
if curves is not None and len(curves) > 0: if curves is not None and len(curves) > 0:
curves_query = f"&curves={','.join(curves)}" curves_query = f"&curves={','.join(curves)}"
url = self.get_base_url(self._wellbore_service)
get_welllog_data_url = f'{self.get_base_url(self._wellbore_service)}/api/os-wellbore-ddms/ddms/v3/welllogs/{welllog_id}/data?describe=false{curves_query}' get_welllog_data_url = f'{url}/api/os-wellbore-ddms/ddms/v3/welllogs/{welllog_id}/data?describe=false{curves_query}'
try: try:
res = self._send_request("GET", get_welllog_data_url, None, None) res = self._send_request("GET", get_welllog_data_url, None, None)
...@@ -203,9 +206,12 @@ class OsduClient: ...@@ -203,9 +206,12 @@ class OsduClient:
return res return res
def get_base_url( self,service_name: str) -> str: def get_base_url( self,service_name: str) -> str:
if service_name == self._wellbore_service and self._wellbore_service_path_prefix is not None and len(self._wellbore_service_path_prefix) > 0: wellbore_path_prefix = self._wellbore_service_path_prefix
return f"{self._base_url}/{self._wellbore_service_path_prefix}" search_path_prefix = self._search_service_path_prefix
elif service_name == self._search_service and self._search_service_path_prefix is not None and len(self._search_service_path_prefix) > 0:
return f"{self._base_url}/{self._search_service_path_prefix}" if service_name == self._wellbore_service and wellbore_path_prefix is not None and len(wellbore_path_prefix) > 0:
return f"{self._base_url}/{wellbore_path_prefix}"
elif service_name == self._search_service and search_path_prefix is not None and len(search_path_prefix) > 0:
return f"{self._base_url}/{search_path_prefix}"
else: else:
return self._base_url return self._base_url
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment