-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from CartoDB/service-account-endpoint
Do token
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |