def test_team(self, token): dbxt = DropboxTeam(token) dbxt.team_groups_list() r = dbxt.team_members_list() if r.members: # Only test assuming a member if there is a member dbxt.as_user(r.members[0].profile.team_member_id).files_list_folder('')
class TestDropbox(unittest.TestCase): def setUp(self): self.dbx = Dropbox(oauth2_token) self.dbxt = DropboxTeam(team_oauth2_token) def test_bad_auth(self): # Test malformed token malformed_token_dbx = Dropbox(MALFORMED_TOKEN) with self.assertRaises(BadInputError) as cm: malformed_token_dbx.files_list_folder('') self.assertIn('token is malformed', cm.exception.message) # Test reasonable-looking invalid token invalid_token_dbx = Dropbox(INVALID_TOKEN) with self.assertRaises(AuthError) as cm: invalid_token_dbx.files_list_folder('') self.assertEqual(cm.exception.error['error']['.tag'], 'invalid_access_token') def test_rpc(self): self.dbx.files_list_folder('') # Test API error random_folder_path = '/' + \ ''.join(random.sample(string.ascii_letters, 15)) with self.assertRaises(ApiError) as cm: self.dbx.files_list_folder(random_folder_path) self.assertIsInstance(cm.exception.error, ListFolderError) def test_upload_download(self): # Upload file timestamp = str(datetime.datetime.utcnow()) random_filename = ''.join(random.sample(string.ascii_letters, 15)) random_path = '/Test/%s/%s' % (timestamp, random_filename) test_contents = string.ascii_letters self.dbx.files_upload(test_contents, random_path) # Download file metadata, resp = self.dbx.files_download(random_path) self.assertEqual(string.ascii_letters, resp.text) # Cleanup folder self.dbx.files_delete('/Test/%s' % timestamp) def test_team(self): self.dbxt.team_groups_list() r = self.dbxt.team_members_list() if r.members: # Only test assuming a member if there is a member self.dbxt.as_user(r.members[0].profile.team_member_id).files_list_folder('')
class TestDropbox(unittest.TestCase): def setUp(self): self.dbx = Dropbox(oauth2_token) self.dbxt = DropboxTeam(team_oauth2_token) def test_bad_auth(self): # Test malformed token malformed_token_dbx = Dropbox(MALFORMED_TOKEN) with self.assertRaises(BadInputError) as cm: malformed_token_dbx.files_list_folder('') self.assertIn('token is malformed', cm.exception.message) # Test reasonable-looking invalid token invalid_token_dbx = Dropbox(INVALID_TOKEN) with self.assertRaises(AuthError) as cm: invalid_token_dbx.files_list_folder('') self.assertEqual(cm.exception.error['error']['.tag'], 'invalid_access_token') def test_rpc(self): self.dbx.files_list_folder('') # Test API error random_folder_path = '/' + \ ''.join(random.sample(string.ascii_letters, 15)) with self.assertRaises(ApiError) as cm: self.dbx.files_list_folder(random_folder_path) self.assertIsInstance(cm.exception.error, ListFolderError) def test_upload_download(self): # Upload file timestamp = str(datetime.datetime.utcnow()) random_filename = ''.join(random.sample(string.ascii_letters, 15)) random_path = '/Test/%s/%s' % (timestamp, random_filename) test_contents = string.ascii_letters self.dbx.files_upload(test_contents, random_path) # Download file metadata, resp = self.dbx.files_download(random_path) self.assertEqual(string.ascii_letters, resp.text) # Cleanup folder self.dbx.files_delete('/Test/%s' % timestamp) def test_team(self): self.dbxt.team_groups_list() r = self.dbxt.team_members_list() if r.members: # Only test assuming a member if there is a member self.dbxt.as_user( r.members[0].profile.team_member_id).files_list_folder('')