Skip to content

Commit 76536ae

Browse files
committed
Update tox testing advice.
1 parent 2c3950b commit 76536ae

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

README.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,28 @@ To ease the transition to the new API and SDK, you can still use the old
5858
simultaneously. Support for the old client will be dropped once the new SDK is
5959
at functional parity.
6060

61-
Running tests
62-
-------------
61+
Testing
62+
-------
6363

6464
We use the `tox <https://tox.readthedocs.org/>`_ package to run tests in Python
6565
2 and 3. To install, use :code:`pip install tox`. Once installed, run `tox` from the
6666
root directory. You'll need to specify a working Dropbox OAuth2 token:
6767

6868
.. code-block:: bash
6969
70-
$ DROPBOX_TOKEN=YOUR_TOKEN tox
70+
$ DROPBOX_TOKEN=YOUR_TOKEN tox -- -k "'not test_team'"
71+
72+
Note that we skip ``test_team`` which requires a team token with `Member File Access
73+
<https://www.dropbox.com/developers/documentation/http/teams#teams-member-file-access>`_.
74+
To test this functionality, specify a ``DROPBOX_TEAM_TOKEN`` environment
75+
variable.
76+
77+
.. code-block:: bash
78+
79+
$ DROPBOX_TOKEN=... DROPBOX_TEAM_TOKEN=... tox
80+
81+
If you only want to test the API v2 client, use:
82+
83+
.. code-block:: bash
7184
85+
$ DROPBOX_TOKEN=... DROPBOX_TEAM_TOKEN=... tox -- -k TestDropbox

test/test_dropbox.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@
2727
file=sys.stderr)
2828
sys.exit(1)
2929

30-
# Get team token from environment variable.
31-
# This team needs to have sufficient permission to get team information
32-
# and assume user identities.
33-
team_oauth2_token = os.environ.get('DROPBOX_TEAM_TOKEN')
34-
if team_oauth2_token is None:
35-
print('Set DROPBOX_TEAM_TOKEN environment variable to a valid token.',
36-
file=sys.stderr)
37-
sys.exit(1)
30+
31+
def require_team_token(f):
32+
def inner(*args, **kwargs):
33+
# Get team token from environment variable.
34+
# This team needs to have sufficient permission to get team information
35+
# and assume user identities.
36+
team_oauth2_token = os.environ.get('DROPBOX_TEAM_TOKEN')
37+
if team_oauth2_token is None:
38+
print('Set DROPBOX_TEAM_TOKEN environment variable to a valid token.',
39+
file=sys.stderr)
40+
sys.exit(1)
41+
return f(team_oauth2_token, *args, **kwargs)
42+
return inner
43+
3844

3945
MALFORMED_TOKEN = 'asdf'
4046
INVALID_TOKEN = 'z' * 62
@@ -44,7 +50,6 @@ class TestDropbox(unittest.TestCase):
4450

4551
def setUp(self):
4652
self.dbx = Dropbox(oauth2_token)
47-
self.dbxt = DropboxTeam(team_oauth2_token)
4853

4954
def test_bad_auth(self):
5055
# Test malformed token
@@ -85,12 +90,14 @@ def test_upload_download(self):
8590
# Cleanup folder
8691
self.dbx.files_delete('/Test/%s' % timestamp)
8792

88-
def test_team(self):
89-
self.dbxt.team_groups_list()
90-
r = self.dbxt.team_members_list()
93+
@require_team_token
94+
def test_team(self, token):
95+
dbxt = DropboxTeam(token)
96+
dbxt.team_groups_list()
97+
r = dbxt.team_members_list()
9198
if r.members:
9299
# Only test assuming a member if there is a member
93-
self.dbxt.as_user(r.members[0].profile.team_member_id).files_list_folder('')
100+
dbxt.as_user(r.members[0].profile.team_member_id).files_list_folder('')
94101

95102

96103
from io import BytesIO

0 commit comments

Comments
 (0)