Example #1
0
 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')))
Example #2
0
 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()
Example #3
0
 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)
Example #4
0
 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)
Example #5
0
 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')))
Example #6
0
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
Example #7
0
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
Example #8
0
 def test_list_drives(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')))
     try:
         od_pref.list_drives(args=())
     except SystemExit as e:
         if e.code == 0:
             pass
Example #9
0
 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)
Example #10
0
 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']))
Example #11
0
    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']))
Example #12
0
 def setUp(self):
     self.rules = get_resource('data/ignore_list.txt',
                               pkg_name='tests').splitlines()
     self.filter = od_models.path_filter.PathFilter(self.rules)
Example #13
0
 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()
Example #14
0
 def setUp(self):
     self.data = json.loads(
         get_resource('data/webhook_notification.json', 'tests'))
Example #15
0
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)
Example #16
0
def get_sample_drive():
    drive_response = json.loads(
        get_resource('data/drive_response.json', 'tests'))
    return onedrivesdk.Drive(drive_response)
Example #17
0
 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'))
Example #18
0
 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'))
Example #19
0
 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)
Example #20
0
 def test_config_schema(self):
     curr_config_schema = json.loads(
         get_resource('data/config_schema.json', pkg_name='onedrived'))
     SchemaValidator(curr_config_schema).validate()
Example #21
0
 def setUp(self):
     self.data = json.loads(get_resource('data/me_profile_response.json', pkg_name='tests'))
     self.account = od_models.account_profile.OneDriveAccountProfile(self.data)
Example #22
0
 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)
Example #23
0
 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)
Example #24
0
 def setUp(self):
     self.data = json.loads(get_resource('data/webhook_notification.json', 'tests'))
Example #25
0
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)
Example #26
0
 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'))
Example #27
0
 def setUp(self):
     self.rules = get_resource('data/ignore_list.txt', pkg_name='tests').splitlines()
     self.filter = od_models.path_filter.PathFilter(self.rules)
Example #28
0
 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'))
Example #29
0
def get_sample_drive():
    drive_response = json.loads(get_resource('data/drive_response.json', 'tests'))
    return onedrivesdk.Drive(drive_response)
Example #30
0
 def test_config_schema(self):
     curr_config_schema = json.loads(get_resource('data/config_schema.json', pkg_name='onedrived'))
     SchemaValidator(curr_config_schema).validate()
Example #31
0
 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)