Skip to content

Commit 51b8d3a

Browse files
karandeep-joharKarandeep Johar
andauthored
Make with_path_root() update existing headers rather than overwrite them (#206)
Co-authored-by: Karandeep Johar <kjohar@dropbox.com>
1 parent 29b7c6d commit 51b8d3a

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

dropbox/dropbox.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
HTTP_STATUS_INVALID_PATH_ROOT = 422
5454
TOKEN_EXPIRATION_BUFFER = 300
5555

56+
SELECT_ADMIN_HEADER = 'Dropbox-API-Select-Admin'
57+
58+
SELECT_USER_HEADER = 'Dropbox-API-Select-User'
59+
5660
class RouteResult(object):
5761
"""The successful result of a call to a route."""
5862

@@ -652,10 +656,11 @@ def with_path_root(self, path_root):
652656
if not isinstance(path_root, PathRoot):
653657
raise ValueError("path_root must be an instance of PathRoot")
654658

659+
new_headers = self._headers.copy() if self._headers else {}
660+
new_headers[PATH_ROOT_HEADER] = stone_serializers.json_encode(PathRoot_validator, path_root)
661+
655662
return self.clone(
656-
headers={
657-
PATH_ROOT_HEADER: stone_serializers.json_encode(PathRoot_validator, path_root)
658-
}
663+
headers=new_headers
659664
)
660665

661666
class Dropbox(_DropboxTransport, DropboxBase):
@@ -682,7 +687,7 @@ def as_admin(self, team_member_id):
682687
of this admin of the team.
683688
:rtype: Dropbox
684689
"""
685-
return self._get_dropbox_client_with_select_header('Dropbox-API-Select-Admin',
690+
return self._get_dropbox_client_with_select_header(SELECT_ADMIN_HEADER,
686691
team_member_id)
687692

688693
def as_user(self, team_member_id):
@@ -695,7 +700,7 @@ def as_user(self, team_member_id):
695700
of this member of the team.
696701
:rtype: Dropbox
697702
"""
698-
return self._get_dropbox_client_with_select_header('Dropbox-API-Select-User',
703+
return self._get_dropbox_client_with_select_header(SELECT_USER_HEADER,
699704
team_member_id)
700705

701706
def _get_dropbox_client_with_select_header(self, select_header_name, team_member_id):

test/test_dropbox.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
session,
2525
stone_serializers,
2626
)
27-
from dropbox.dropbox import PATH_ROOT_HEADER
27+
from dropbox.dropbox import PATH_ROOT_HEADER, SELECT_USER_HEADER
2828
from dropbox.exceptions import (
2929
ApiError,
3030
AuthError,
@@ -239,7 +239,15 @@ def test_team(self, dbxt):
239239
@dbx_team_from_env
240240
def test_as_user(self, dbxt):
241241
dbx_as_user = dbxt.as_user('1')
242-
self.assertIsInstance(dbx_as_user, Dropbox)
242+
path_root = PathRoot.root("123")
243+
244+
dbx_new = dbx_as_user.with_path_root(path_root)
245+
246+
self.assertIsInstance(dbx_new, Dropbox)
247+
self.assertEqual(dbx_new._headers.get(SELECT_USER_HEADER), '1')
248+
249+
expected = stone_serializers.json_encode(PathRoot_validator, path_root)
250+
self.assertEqual(dbx_new._headers.get(PATH_ROOT_HEADER), expected)
243251

244252
@dbx_team_from_env
245253
def test_as_admin(self, dbxt):

0 commit comments

Comments
 (0)