diff --git a/datasources/connectors/base.py b/datasources/connectors/base.py index 944551817f6257b39fae544298b781833e3c53d5..9ce115877702be2cacf0ee82f654472a61718e6a 100644 --- a/datasources/connectors/base.py +++ b/datasources/connectors/base.py @@ -100,6 +100,7 @@ class BaseDataConnector(metaclass=plugin.Plugin): def request_count(self): return self._request_counter.count() + # TODO make normal method @staticmethod def determine_auth_method(url: str, api_key: str) -> AuthMethod: """ diff --git a/datasources/tests/test_connectors.py b/datasources/tests/test_connectors.py index 8527559159265b2990a24ed6ad2120a6b88a9110..00296f0dfcb401edd16d66fa107b6e3654e44dda 100644 --- a/datasources/tests/test_connectors.py +++ b/datasources/tests/test_connectors.py @@ -1,6 +1,6 @@ from django.test import TestCase -from datasources.connectors.base import BaseDataConnector +from datasources.connectors.base import AuthMethod, BaseDataConnector class ConnectorPluginTest(TestCase): @@ -86,6 +86,13 @@ class ConnectorIoTUKTest(TestCase): self.assertIn('data', result) self.assertGreater(len(result['data']), 0) + def test_determine_auth(self): + connection = self._get_connection() + + auth_method = connection.determine_auth_method(connection.location, connection.api_key) + + self.assertEqual(AuthMethod.NONE, auth_method) + class ConnectorRestApiTest(TestCase): url = 'https://api.iotuk.org.uk/' diff --git a/datasources/tests/test_connectors_hypercat.py b/datasources/tests/test_connectors_hypercat.py index a34bff6a05a8caaa7aeb4464f9f0cea4132332c7..86dfae35ffbe7c194aeff1b93426587df8bae117 100644 --- a/datasources/tests/test_connectors_hypercat.py +++ b/datasources/tests/test_connectors_hypercat.py @@ -4,7 +4,7 @@ import typing from django.test import TestCase from requests.auth import HTTPBasicAuth -from datasources.connectors.base import BaseDataConnector, HttpHeaderAuth +from datasources.connectors.base import AuthMethod, BaseDataConnector, HttpHeaderAuth def _get_item_by_key_value(collection: typing.Iterable[typing.Mapping], @@ -181,6 +181,7 @@ class ConnectorHyperCatTest(TestCase): class ConnectorHyperCatCiscoTest(TestCase): + # TODO find working dataset url = 'https://api.cityverve.org.uk/v1/cat' subcatalogue = 'https://api.cityverve.org.uk/v1/cat/polling-station' dataset = 'https://api.cityverve.org.uk/v1/entity/polling-station/5' @@ -212,6 +213,13 @@ class ConnectorHyperCatCiscoTest(TestCase): self.assertTrue(connection.is_catalogue) + def test_determine_auth(self): + connection = self._get_connection() + + auth_method = connection.determine_auth_method(connection.location, connection.api_key) + + self.assertEqual(AuthMethod.HEADER, auth_method) + def test_plugin_get_catalogue_metadata(self): connection = self._get_connection()