Skip to content

Commit a7cfc25

Browse files
committed
Add users.current endpoint to v2 api.
1 parent b25809a commit a7cfc25

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

plotly/api/v2/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from __future__ import absolute_import
22

3-
from plotly.api.v2 import files, folders, grids, images, plot_schema, plots
3+
from plotly.api.v2 import (files, folders, grids, images, plot_schema, plots,
4+
users)

plotly/api/v2/users.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Interface to Plotly's /v2/files endpoints."""
2+
from __future__ import absolute_import
3+
4+
from plotly.api.v2.utils import build_url, request
5+
6+
RESOURCE = 'users'
7+
8+
9+
def current():
10+
"""
11+
Retrieve information on the logged-in user from Plotly.
12+
13+
:returns: (requests.Response) Returns response directly from requests.
14+
15+
"""
16+
url = build_url(RESOURCE, route='current')
17+
return request('get', url)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from __future__ import absolute_import
2+
3+
from plotly.api.v2 import users
4+
from plotly.tests.test_core.test_api import PlotlyApiTestCase
5+
6+
7+
class UsersTest(PlotlyApiTestCase):
8+
9+
def setUp(self):
10+
super(UsersTest, self).setUp()
11+
12+
# Mock the actual api call, we don't want to do network tests here.
13+
self.request_mock = self.mock('plotly.api.v2.utils.requests.request')
14+
self.request_mock.return_value = self.get_response()
15+
16+
# Mock the validation function since we can test that elsewhere.
17+
self.mock('plotly.api.v2.utils.validate_response')
18+
19+
def test_current(self):
20+
users.current()
21+
self.request_mock.assert_called_once()
22+
args, kwargs = self.request_mock.call_args
23+
method, url = args
24+
self.assertEqual(method, 'get')
25+
self.assertEqual(
26+
url, '{}/v2/users/current'.format(self.plotly_api_domain)
27+
)
28+
self.assertNotIn('params', kwargs)

0 commit comments

Comments
 (0)