示例#1
0
 def test_assemble_drive_error(self):
     d = {}
     drive = drives.DriveObject(self.drive_root, get_data('drive.json'),
                                DriveConfig.default_config())
     rows = [('did', 'aid', 'at', drive.dump() + '.'),
             (drive.drive_id, self.personal_account.profile.user_id,
              self.personal_account.TYPE, drive.dump() + '.')]
     for r in rows:
         self.drives_store.assemble_drive_record(r, d)
         self.assertEqual(0, len(d), str(r))
示例#2
0
 def test_assemble_drive_error(self):
     d = {}
     drive = drives.DriveObject(self.drive_root, get_data('drive.json'), DriveConfig.default_config())
     rows = [
         ('did', 'aid', 'at', drive.dump() + '.'),
         (drive.drive_id, self.personal_account.profile.user_id, self.personal_account.TYPE, drive.dump() + '.')
     ]
     for r in rows:
         self.drives_store.assemble_drive_record(r, d)
         self.assertEqual(0, len(d), str(r))
示例#3
0
 def test_get_all_drives(self):
     drive_conf = dict(DriveConfig.DEFAULT_VALUES)
     drive_conf['local_root'] = '/tmp'
     drive = drives.DriveObject(self.drive_root, get_data('drive.json'),
                                DriveConfig(drive_conf))
     self.drives_store.add_record(drive)
     for k, drive_value in self.drives_store.get_all_drives().items():
         drive_id, account_id, account_type = k
         self.assertEqual(drive_id, drive_value.drive_id)
         self.assertEqual(drive.drive_id, drive_value.drive_id)
         self.assertEqual(drive.config.local_root,
                          drive_value.config.local_root)
示例#4
0
class UserConfig:
    """
    Global settings for a user.
    """

    DEFAULT_CONFIG = {
        'num_consumers': 4,
        'deep_sync_interval_seconds': 300,
        'http_retry_after_seconds': 30,
        'default_drive_config': DriveConfig.default_config(),
        'proxies': dict()
    }

    def __init__(self, data):
        """
        :param dict[str, int | str | onedrived.common.drive_config.DriveConfig] data: Previously dumped user config
        data.
        """
        for k in self.DEFAULT_CONFIG:
            if k not in data:
                data[k] = self.DEFAULT_CONFIG[k]
        self.num_consumers = data['num_consumers']
        self.deep_sync_interval_seconds = data['deep_sync_interval_seconds']
        self.http_retry_after_seconds = data['http_retry_after_seconds']
        self.default_drive_config = data['default_drive_config']
        self.proxies = data['proxies']

    def take_effect(self):
        DriveConfig.set_default_config(self.default_drive_config)

    def dump(self):
        if self.proxies is not None:
            if len(self.proxies) == 0 or self.proxies['https'] == '':
                self.proxies = None
        data = {
            'num_consumers': self.num_consumers,
            'deep_sync_interval_seconds': self.deep_sync_interval_seconds,
            'http_retry_after_seconds': self.http_retry_after_seconds,
            'default_drive_config':
            self.default_drive_config.dump(exact_dump=True),
            'proxies': self.proxies
        }
        return json.dumps(data)

    @classmethod
    def load(cls, s):
        data = json.loads(s)
        data['default_drive_config'] = DriveConfig.load(
            data['default_drive_config'])
        return UserConfig(data)
示例#5
0
 def load(cls, s):
     data = json.loads(s)
     data['default_drive_config'] = DriveConfig.load(
         data['default_drive_config'])
     return UserConfig(data)
示例#6
0
 def take_effect(self):
     DriveConfig.set_default_config(self.default_drive_config)
示例#7
0
 def load(cls, s):
     data = json.loads(s)
     data['default_drive_config'] = DriveConfig.load(data['default_drive_config'])
     return UserConfig(data)
示例#8
0
 def take_effect(self):
     DriveConfig.set_default_config(self.default_drive_config)
示例#9
0
 def setUp(self):
     self.data = {
         'http_retry_after_seconds': 40,
         'default_drive_config': DriveConfig(get_data('drive_config.json'))
     }
     self.user_conf = user_config.UserConfig(self.data)