File tree Expand file tree Collapse file tree 2 files changed +76
-0
lines changed Expand file tree Collapse file tree 2 files changed +76
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ Module for working with Data Observatory tokens
3+
4+ .. module:: carto.DoToken
5+ :platform: Unix, Windows
6+ :synopsis: Module for working with Data Observatory tokens
7+
8+ .. moduleauthor:: Simon Martin <[email protected] > 9+
10+ """
11+
12+ from pyrestcli .fields import CharField
13+
14+ from .paginators import CartoPaginator
15+ from .resources import WarnResource , Manager
16+
17+
18+ API_VERSION = "v4"
19+ API_ENDPOINT = "api/{api_version}/do/token"
20+
21+
22+ class DoToken (WarnResource ):
23+ """
24+ Represents a Data Observatory token in CARTO.
25+
26+ .. warning:: Non-public API. It may change with no previous notice
27+ """
28+ access_token = CharField ()
29+
30+ class Meta :
31+ collection_endpoint = API_ENDPOINT .format (api_version = API_VERSION )
32+ name_field = "access_token"
33+
34+
35+ class DoTokenManager (Manager ):
36+ """
37+ Manager for the DoToken class.
38+
39+ .. warning:: Non-public API. It may change with no previous notice
40+ """
41+ resource_class = DoToken
42+ json_collection_attribute = None
43+ paginator_class = CartoPaginator
44+
45+ def get (self ):
46+ return super (DoTokenManager , self ).get ('token' )
Original file line number Diff line number Diff line change 1+ import os
2+ import pytest
3+
4+ from carto .do_token import DoTokenManager
5+
6+
7+ @pytest .fixture (scope = "module" )
8+ def do_token_manager (api_key_auth_client ):
9+ """
10+ Returns a do token manager that can be reused in tests
11+ :param api_key_auth_client: Fixture that provides a valid
12+ APIKeyAuthClient object
13+ :return: DoTokenManager instance
14+ """
15+ return DoTokenManager (api_key_auth_client )
16+
17+
18+ @pytest .mark .skipif ("TRAVIS" in os .environ and os .environ ["TRAVIS" ] == "true" ,
19+ reason = "Integration tests not executed in Travis" )
20+ def test_get_token (do_token_manager ):
21+ """
22+ Get all the datasets from the API
23+ :param do_token_manager: Fixture that provides a do token manager to work with
24+ """
25+ token = do_token_manager .get ()
26+
27+ assert token is not None
28+ assert token .access_token is not None
29+ assert isinstance (token .access_token , str )
30+ assert len (token .access_token ) > 0
You can’t perform that action at this time.
0 commit comments