def bootstrap_PCS(args, app_info_path, user_credentials_path): from pcs_api.providers import (dropbox, googledrive) from pcs_api.credentials.app_info_file_repo \ import AppInfoFileRepository from pcs_api.credentials.user_creds_file_repo \ import UserCredentialsFileRepository from pcs_api.storage import StorageFacade from pcs_api.oauth.oauth2_bootstrap import OAuth2BootStrapper apps_repo = AppInfoFileRepository(app_info_path) user_credentials_repo = UserCredentialsFileRepository( user_credentials_path) storage = StorageFacade.for_provider(args.pcs) \ .app_info_repository(apps_repo, args.app_name) \ .user_credentials_repository(user_credentials_repo) \ .for_bootstrap() \ .build() bootstrapper = OAuth2BootStrapper(storage) bootstrapper.do_code_workflow()
def pytest_generate_tests(metafunc): """Generate test parameters according to command line options.""" if 'storage' in metafunc.fixturenames: if metafunc.config.option.providers == 'all': providers_names = StorageFacade.get_registered_providers() else: providers_names = metafunc.config.option.providers.split(',') # Instantiate one storage for each provider, if possible: storages = [] if apps_repo: logger.info("Using providers names = %r", providers_names) for provider_name in providers_names: storage = StorageFacade.for_provider(provider_name) \ .app_info_repository(apps_repo, None) \ .user_credentials_repository(user_credentials_repo, None) \ .build() storages.append(storage) else: # Missing apps_repo, etc. Functional tests can not run logger.warn("No provider can be instantiated") metafunc.parametrize("storage", storages)
) cli_args = parser.parse_args() # Here we use basic file repositories : apps_repo = AppInfoFileRepository("../../repositories/app_info_data.txt") user_credentials_repo = UserCredentialsFileRepository( "../../repositories/user_credentials_data.txt") import logging import httplib debug = True if debug: httplib.HTTPConnection.debuglevel = 1 logging.basicConfig(level=logging.DEBUG) requests_log = logging.getLogger("requests.packages.urllib3") requests_log.setLevel(logging.DEBUG) requests_log.propagate = True # Check it is really an oauth app : app_info = apps_repo.get(cli_args.provider_name, cli_args.app_name) if not app_info.is_oauth(): raise ValueError('This application does not use OAuth : %s' % app_info) # Instantiate storage : storage = StorageFacade.for_provider(cli_args.provider_name) \ .app_info_repository(apps_repo, cli_args.app_name) \ .user_credentials_repository(user_credentials_repo) \ .for_bootstrap() \ .build() bootstrapper = OAuth2BootStrapper(storage) bootstrapper.do_code_workflow()
apps_repo_pathname = "%s/app_info_data.txt" % file_repositories_folder if not os.path.exists(apps_repo_pathname): print('Not found any application information repository file: ', apps_repo_pathname) print('Refer to documentation and class AppInfoFileRepository to setup pcs_api for a quick test') exit(1) apps_repo = AppInfoFileRepository(apps_repo_pathname) user_creds_pathname = "%s/user_credentials_data.txt" % file_repositories_folder if not os.path.exists(user_creds_pathname): print('Not found any users credentials repository file: ', user_creds_pathname) print('Refer to documentation and class UserCredentialsFileRepository to setup pcs_api for a quick test') exit(1) user_credentials_repo = UserCredentialsFileRepository(user_creds_pathname) storage = StorageFacade.for_provider(cli_args.provider_name) \ .app_info_repository(apps_repo, cli_args.app_name) \ .user_credentials_repository(user_credentials_repo, cli_args.user_id) \ .build() print("user_id = ", storage.get_user_id()) print("quota = ", storage.get_quota()) # Recursively list all regular files (blobs in folders) : folders_to_process = [CPath('/')] largest_blob = None while folders_to_process: f = folders_to_process.pop() # list folder : print("\nContent of %s :" % f) content = storage.list_folder(f) blobs = [f for f in content.values() if f.is_blob()] folders = [f for f in content.values() if f.is_folder()]