def setUp(self): self.temp_config_dir, self.temp_repo_dir, self.drive_config, self.repo = get_sample_repo( ) self.root_folder_item = onedrivesdk.Item( json.loads(get_resource('data/folder_item.json', pkg_name='tests'))) self.root_subfolder_item = onedrivesdk.Item( json.loads( get_resource('data/subfolder_item.json', pkg_name='tests'))) self.root_child_item = onedrivesdk.Item( json.loads( get_resource('data/folder_child_item.json', pkg_name='tests'))) self.image_item = onedrivesdk.Item( json.loads(get_resource('data/image_item.json', pkg_name='tests'))) self._add_all_items()
def test_remote_dir_matches_record(self): item = onedrivesdk.Item( json.loads(get_resource('data/folder_item.json', pkg_name='tests'))) self.repo.update_item(item, '', size_local=0) record = self.repo.get_item_by_path(item.name, '') merge_dir.MergeDirectoryTask._remote_dir_matches_record(item, record)
def setUp(self): self.schema = json.loads( get_resource('data/sample_config_schema.json', pkg_name='tests')) self.config_dict = { k: v['@default_value'] for k, v in self.schema.items() } self.config_guard = GuardedDict(self.config_dict, self.schema)
def __init__(self, lang_resources, locale_str='en_US'): """ :param [str] lang_resources: List of language resource files to load. Example: ['od_pref', 'configurator'] to load lang/od_pref :param str locale_str: Locale to load. """ self.string_resources = dict() for lang in lang_resources: try: t = get_resource('lang/%s.%s.json' % (lang, locale_str), pkg_name='onedrive_client') except FileNotFoundError: t = get_resource('lang/%s.%s.json' % (lang, self.DEFAULT_LOCALE), pkg_name='onedrive_client') data = json.loads(t) self.string_resources.update(data)
def _setup_list_drive_mock(self, mock): all_drives = json.loads( get_resource('data/list_drives.json', pkg_name='tests')) mock.register_uri('GET', 'https://api.onedrive.com/v1.0/drives', [{ 'status_code': 200, 'json': { 'value': all_drives['value'][0:-1] } }, { 'status_code': 200, 'json': { 'value': all_drives['value'][-1:] } }]) mock.post('https://login.live.com/oauth20_token.srf', json=json.loads( get_resource('data/session_response.json', pkg_name='tests')))
def get_sample_authenticator(): auth = od_auth.OneDriveAuthenticator() session_params = json.loads( get_resource('data/session_response.json', pkg_name='tests')) session_params['token_type'] = 'code' session_params['client_id'] = auth.APP_CLIENT_ID session_params['scope_string'] = session_params['scope'] session_params['redirect_uri'] = auth.APP_REDIRECT_URL session_params['auth_server_url'] = 'https://localhost/auth' del session_params['scope'] auth.client.auth_provider._session = od_api_session.OneDriveAPISession( **session_params) auth.refresh_session = lambda x: None return auth
def test_execution(self): self.worker.start() notification_data = json.loads(get_resource('data/webhook_notification.json', pkg_name='tests')) subscription = onedrivesdk.Subscription() subscription.id = notification_data['subscriptionId'] self.worker.add_subscription(subscription, self.repo) # Send a notification. self.worker.queue_input(json.dumps({'value': [notification_data]}).encode('utf-8')) # Duplicate notifications should be ignored. self.worker.queue_input(json.dumps(notification_data).encode('utf-8')) # Unknown subscriptions should be ignored. notification_data['subscriptionId'] = '233' self.worker.queue_input(json.dumps(notification_data).encode('utf-8')) self.assertTrue(self.callback_called_sem.acquire(timeout=3)) self.assertFalse(self.callback_called_sem.acquire(timeout=1)) self.assertEqual([self.repo], self.callback_repos) self.assertEqual(1, self.callback_count)
def _call_authenticate_account(self, mock, code, args): profile = json.loads( get_resource('data/me_profile_response.json', pkg_name='tests')) def callback_auth(request, context): self.assertIn('code=' + code, request.text) context.status_code = 200 return json.loads( get_resource('data/session_response.json', pkg_name='tests')) def callback_profile(request, context): context.status_code = 200 return profile mock.post(re.compile('//login\.live\.com\.*'), json=callback_auth) mock.get('https://apis.live.net/v5.0/me', json=callback_profile) try: od_pref.authenticate_account(args=args) except SystemExit as e: if e.code == 0: pass context = od_pref.load_context() self.assertIsNotNone(context.get_account(profile['id']))
def setUp(self): self.data = json.loads( get_resource('data/webhook_notification.json', 'tests'))
def setUp(self): super().setUp() self.webhook_worker = od_webhook.WebhookWorkerThread( 'https://localhost', callback_func=None) self.data = json.loads( get_resource('data/subscription_response.json', pkg_name='tests'))
def test_config_schema(self): curr_config_schema = json.loads( get_resource('data/config_schema.json', pkg_name='onedrive_client')) SchemaValidator(curr_config_schema).validate()
import click import keyring import tabulate from onedrive_client import __version__ from onedrive_client import mkdir, get_resource, od_i18n, od_auth from onedrive_client.od_models import pretty_api, drive_config, account_profile from onedrive_client.od_api_session import OneDriveAPISession, get_keyring_key from onedrive_client.od_models.dict_guard import GuardedDict, exceptions as guard_errors from onedrive_client.od_context import load_context, save_context from onedrive_client.od_repo import get_drive_db_path context = load_context() translator = od_i18n.Translator(('od_pref', ), locale_str=str(locale.getlocale()[0])) config_schema = json.loads(get_resource('data/config_schema.json', pkg_name='onedrive_client')) config_guard = GuardedDict(config_dict=context.config, config_schema_dict=config_schema) def error(s): click.secho(s, fg='red') def warning(s): click.secho(s, fg='yellow') def success(s): click.secho(s, fg='green')
def setUp(self): self.rules = get_resource('data/ignore_list.txt', pkg_name='tests').splitlines() self.filter = od_models.path_filter.PathFilter(self.rules)
def callback_auth(request, context): self.assertIn('code=' + code, request.text) context.status_code = 200 return json.loads( get_resource('data/session_response.json', pkg_name='tests'))
def _copy_default_config_file(self, resource_filename, target_filename): with open(self.config_dir + '/' + target_filename, 'w') as f: f.write(get_resource('data/' + resource_filename))
def get_sample_drive_config(): drive_dict = json.loads( get_resource('data/drive_config_item.json', 'tests')) drive_dict['ignorefile_path'] = os.path.join( os.path.dirname(sys.modules['tests'].__file__), 'data/ignore_list.txt') return drive_dict, od_models.drive_config.LocalDriveConfig(**drive_dict)
def get_sample_drive(): drive_response = json.loads( get_resource('data/drive_response.json', 'tests')) return onedrivesdk.Drive(drive_response)
def setUp(self): self.data = json.loads( get_resource('data/me_profile_business_response.json', pkg_name='tests')) self.account = od_models.account_profile.OneDriveAccount( self.data).get_account()
def test_quota_short_str(self): quota = onedrivesdk.Quota( json.loads(get_resource('data/quota_response.json', 'tests'))) self.assertIsInstance(od_pref.quota_short_str(quota), str)