Skip to content
Snippets Groups Projects
Commit b597c2fa authored by James Graham's avatar James Graham
Browse files

Remove duplicated code from HyperCat connector get_metadata

parent d04e08e2
Branches
No related tags found
No related merge requests found
import copy
import typing
import requests
......@@ -31,22 +30,23 @@ class HyperCat(DataConnectorContainsDatasets, DataConnectorHasMetadata, BaseData
def get_metadata(self,
dataset: typing.Optional[str] = None,
query_params: typing.Optional[typing.Mapping[str, str]] = None):
response = self._response
if query_params is None:
query_params = {}
if dataset is None:
if dataset is not None:
# Copy so we can update without side effect
query_params = dict(query_params)
query_params['href'] = dataset
# Use cached response if we have one
response = self._response
if response is None:
response = self._get_response(query_params)
if dataset is None:
metadata = response['catalogue-metadata']
else:
query_params = copy.copy(query_params).update({
'href': dataset
})
if response is None:
response = self._get_response(query_params)
dataset_item = self._get_item_by_key_value(
response['items'],
'href',
......
......@@ -93,14 +93,9 @@ class ConnectorHyperCatTest(TestCase):
connection = self.plugin(self.url)
self.assertEqual(connection.location, self.url)
def test_plugin_get_metadata_query(self):
def test_plugin_get_dataset_metadata(self):
connection = self.plugin(self.url)
result = connection.get_metadata(
dataset=self.dataset,
query_params={
'href': self.dataset
}
)
result = connection.get_metadata(dataset=self.dataset)
for property in [
'urn:X-bt:rels:feedTitle',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment