From fa3d15767dd1910383f8f6db448cbe7da81d4905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Mart=C3=ADn?= Date: Fri, 20 Sep 2019 16:55:46 +0200 Subject: [PATCH 1/3] initial model and manager --- carto/do_token.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 carto/do_token.py diff --git a/carto/do_token.py b/carto/do_token.py new file mode 100644 index 0000000..c164893 --- /dev/null +++ b/carto/do_token.py @@ -0,0 +1,42 @@ +""" +Module for working with Data Observatory tokens + +.. module:: carto.DoToken + :platform: Unix, Windows + :synopsis: Module for working with Data Observatory tokens + +.. moduleauthor:: Simon Martin + +""" + +from pyrestcli.fields import CharField + +from .resources import WarnResource, Manager + + +API_VERSION = "v4" +API_ENDPOINT = "api/{api_version}/do/token" + + +class DoToken(WarnResource): + """ + Represents a Data Observatory token in CARTO. + + .. warning:: Non-public API. It may change with no previous notice + """ + access_token = CharField() + + class Meta: + collection_endpoint = API_ENDPOINT.format(api_version=API_VERSION) + name_field = None + + +class DoTokenManager(Manager): + """ + Manager for the DoToken class. + + .. warning:: Non-public API. It may change with no previous notice + """ + resource_class = DoToken + json_collection_attribute = None + paginator_class = None \ No newline at end of file From e0c094c31ed0124a98889fe349c85cce7e8e6cea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Mart=C3=ADn?= Date: Tue, 24 Sep 2019 14:55:31 +0200 Subject: [PATCH 2/3] get method --- carto/do_token.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/carto/do_token.py b/carto/do_token.py index c164893..6a74538 100644 --- a/carto/do_token.py +++ b/carto/do_token.py @@ -11,6 +11,7 @@ from pyrestcli.fields import CharField +from .paginators import CartoPaginator from .resources import WarnResource, Manager @@ -28,7 +29,7 @@ class DoToken(WarnResource): class Meta: collection_endpoint = API_ENDPOINT.format(api_version=API_VERSION) - name_field = None + name_field = "access_token" class DoTokenManager(Manager): @@ -39,4 +40,7 @@ class DoTokenManager(Manager): """ resource_class = DoToken json_collection_attribute = None - paginator_class = None \ No newline at end of file + paginator_class = CartoPaginator + + def get(self): + return super(DoTokenManager, self).get('token') From 81d7588a3a79c5962d99dea6764a2c1675ce9665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Mart=C3=ADn?= Date: Tue, 24 Sep 2019 16:11:17 +0200 Subject: [PATCH 3/3] test token method --- tests/test_do_token.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/test_do_token.py diff --git a/tests/test_do_token.py b/tests/test_do_token.py new file mode 100644 index 0000000..bdd5590 --- /dev/null +++ b/tests/test_do_token.py @@ -0,0 +1,30 @@ +import os +import pytest + +from carto.do_token import DoTokenManager + + +@pytest.fixture(scope="module") +def do_token_manager(api_key_auth_client): + """ + Returns a do token manager that can be reused in tests + :param api_key_auth_client: Fixture that provides a valid + APIKeyAuthClient object + :return: DoTokenManager instance + """ + return DoTokenManager(api_key_auth_client) + + +@pytest.mark.skipif("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", + reason="Integration tests not executed in Travis") +def test_get_token(do_token_manager): + """ + Get all the datasets from the API + :param do_token_manager: Fixture that provides a do token manager to work with + """ + token = do_token_manager.get() + + assert token is not None + assert token.access_token is not None + assert isinstance(token.access_token, str) + assert len(token.access_token) > 0