Skip to content

Commit

Permalink
Merge pull request #148 from CartoDB/service-account-endpoint
Browse files Browse the repository at this point in the history
Do token
  • Loading branch information
alrocar authored Sep 24, 2019
2 parents ddbb3af + 81d7588 commit 9ad0488
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
46 changes: 46 additions & 0 deletions carto/do_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""
Module for working with Data Observatory tokens
.. module:: carto.DoToken
:platform: Unix, Windows
:synopsis: Module for working with Data Observatory tokens
.. moduleauthor:: Simon Martin <[email protected]>
"""

from pyrestcli.fields import CharField

from .paginators import CartoPaginator
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 = "access_token"


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 = CartoPaginator

def get(self):
return super(DoTokenManager, self).get('token')
30 changes: 30 additions & 0 deletions tests/test_do_token.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9ad0488

Please sign in to comment.