3232from  dropbox .files  import  (
3333 DeleteResult ,
3434 ListFolderError ,
35+  PathOrLink ,
36+  SharedLinkFileInfo ,
3537)
3638from  dropbox .common  import  (
3739 PathRoot ,
4143def  _value_from_env_or_die (env_name = 'DROPBOX_TOKEN' ):
4244 value  =  os .environ .get (env_name )
4345 if  value  is  None :
44-  print ('Set {} environment variable to a valid token .' .format (env_name ),
46+  print ('Set {} environment variable to a valid value .' .format (env_name ),
4547 file = sys .stderr )
4648 sys .exit (1 )
4749 return  value 
@@ -72,7 +74,12 @@ def dbx_team_from_env():
7274def  dbx_app_auth_from_env ():
7375 app_key  =  _value_from_env_or_die ("DROPBOX_APP_KEY" )
7476 app_secret  =  _value_from_env_or_die ("DROPBOX_APP_SECRET" )
75-  return  Dropbox (oauth2_access_token = "foo" , app_key = app_key , app_secret = app_secret )
77+  return  Dropbox (app_key = app_key , app_secret = app_secret )
78+ 
79+ 
80+ @pytest .fixture () 
81+ def  dbx_share_url_from_env ():
82+  return  _value_from_env_or_die ("DROPBOX_SHARED_LINK" )
7683
7784
7885MALFORMED_TOKEN  =  'asdf' 
@@ -82,9 +89,10 @@ def dbx_app_auth_from_env():
8289DUMMY_PAYLOAD  =  string .ascii_letters .encode ('ascii' )
8390
8491
85- @pytest .mark .usefixtures ("dbx_from_env" , "refresh_dbx_from_env" , "dbx_app_auth_from_env" ) 
92+ @pytest .mark .usefixtures ( 
93+  "dbx_from_env" , "refresh_dbx_from_env" , "dbx_app_auth_from_env" , "dbx_share_url_from_env"  
94+ ) 
8695class  TestDropbox :
87- 
8896 def  test_default_oauth2_urls (self ):
8997 flow_obj  =  DropboxOAuth2Flow ('dummy_app_key' , 'dummy_app_secret' ,
9098 'http://localhost/dummy' , 'dummy_session' , 'dbx-auth-csrf-token' )
@@ -115,6 +123,19 @@ def test_bad_auth(self):
115123 invalid_token_dbx .files_list_folder ('' )
116124 assert  cm .value .error .is_invalid_access_token ()
117125
126+  def  test_multi_auth (self , dbx_from_env , dbx_app_auth_from_env , dbx_share_url_from_env ):
127+  # Test for user (with oauth token) 
128+  preview_result , resp  =  dbx_from_env .files_get_thumbnail_v2 (
129+  PathOrLink .link (SharedLinkFileInfo (url = dbx_share_url_from_env ))
130+  )
131+  assert  resp .status_code  ==  200 
132+ 
133+  # Test for app (with app key and secret) 
134+  preview_result , resp  =  dbx_from_env .files_get_thumbnail_v2 (
135+  PathOrLink .link (SharedLinkFileInfo (url = dbx_share_url_from_env ))
136+  )
137+  assert  resp .status_code  ==  200 
138+ 
118139 def  test_refresh (self , refresh_dbx_from_env ):
119140 refresh_dbx_from_env .users_get_current_account ()
120141
0 commit comments