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

Add determine_auth tests for base connector and hypercat

parent dac77740
No related branches found
No related tags found
No related merge requests found
...@@ -100,6 +100,7 @@ class BaseDataConnector(metaclass=plugin.Plugin): ...@@ -100,6 +100,7 @@ class BaseDataConnector(metaclass=plugin.Plugin):
def request_count(self): def request_count(self):
return self._request_counter.count() return self._request_counter.count()
# TODO make normal method
@staticmethod @staticmethod
def determine_auth_method(url: str, api_key: str) -> AuthMethod: def determine_auth_method(url: str, api_key: str) -> AuthMethod:
""" """
......
from django.test import TestCase from django.test import TestCase
from datasources.connectors.base import BaseDataConnector from datasources.connectors.base import AuthMethod, BaseDataConnector
class ConnectorPluginTest(TestCase): class ConnectorPluginTest(TestCase):
...@@ -86,6 +86,13 @@ class ConnectorIoTUKTest(TestCase): ...@@ -86,6 +86,13 @@ class ConnectorIoTUKTest(TestCase):
self.assertIn('data', result) self.assertIn('data', result)
self.assertGreater(len(result['data']), 0) 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): class ConnectorRestApiTest(TestCase):
url = 'https://api.iotuk.org.uk/' url = 'https://api.iotuk.org.uk/'
......
...@@ -4,7 +4,7 @@ import typing ...@@ -4,7 +4,7 @@ import typing
from django.test import TestCase from django.test import TestCase
from requests.auth import HTTPBasicAuth 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], def _get_item_by_key_value(collection: typing.Iterable[typing.Mapping],
...@@ -181,6 +181,7 @@ class ConnectorHyperCatTest(TestCase): ...@@ -181,6 +181,7 @@ class ConnectorHyperCatTest(TestCase):
class ConnectorHyperCatCiscoTest(TestCase): class ConnectorHyperCatCiscoTest(TestCase):
# TODO find working dataset
url = 'https://api.cityverve.org.uk/v1/cat' url = 'https://api.cityverve.org.uk/v1/cat'
subcatalogue = 'https://api.cityverve.org.uk/v1/cat/polling-station' subcatalogue = 'https://api.cityverve.org.uk/v1/cat/polling-station'
dataset = 'https://api.cityverve.org.uk/v1/entity/polling-station/5' dataset = 'https://api.cityverve.org.uk/v1/entity/polling-station/5'
...@@ -212,6 +213,13 @@ class ConnectorHyperCatCiscoTest(TestCase): ...@@ -212,6 +213,13 @@ class ConnectorHyperCatCiscoTest(TestCase):
self.assertTrue(connection.is_catalogue) 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): def test_plugin_get_catalogue_metadata(self):
connection = self._get_connection() connection = self._get_connection()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment