From a406bd401fa1969330f51c1196654287cbc5e75e Mon Sep 17 00:00:00 2001 From: James Graham <J.Graham@software.ac.uk> Date: Wed, 13 Feb 2019 16:00:55 +0000 Subject: [PATCH] Add determine_auth tests for base connector and hypercat --- datasources/connectors/base.py | 1 + datasources/tests/test_connectors.py | 9 ++++++++- datasources/tests/test_connectors_hypercat.py | 10 +++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/datasources/connectors/base.py b/datasources/connectors/base.py index 9445518..9ce1158 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 8527559..00296f0 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 a34bff6..86dfae3 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() -- GitLab