def test_downloading_speed(self): file = ModelFile("test", False) file.downloading_speed = 100 self.assertEqual(100, file.downloading_speed) file.downloading_speed = None self.assertEqual(None, file.downloading_speed) with self.assertRaises(TypeError): file.downloading_speed = "BadValue" with self.assertRaises(ValueError): file.downloading_speed = -100
def test_downloading_speed(self): serialize = SerializeModel() a = ModelFile("a", True) a.downloading_speed = None b = ModelFile("b", False) b.downloading_speed = 0 c = ModelFile("c", True) c.downloading_speed = 100 files = [a, b, c] out = parse_stream(serialize.model(files)) data = json.loads(out["data"]) self.assertEqual(3, len(data)) self.assertEqual(None, data[0]["downloading_speed"]) self.assertEqual(0, data[1]["downloading_speed"]) self.assertEqual(100, data[2]["downloading_speed"])
def __fill_model_file( _model_file: ModelFile, _remote: Optional[SystemFile], _local: Optional[SystemFile], _transfer_state: Optional[LftpJobStatus.TransferState]): # set local and remote sizes if _remote: _model_file.remote_size = _remote.size if _local: _model_file.local_size = _local.size # Note: no longer use lftp's file sizes # they represent remaining size for resumed downloads # set the downloading speed and eta if _transfer_state: _model_file.downloading_speed = _transfer_state.speed _model_file.eta = _transfer_state.eta # set the transferred size (only if file or dir exists on both ends) if _local and _remote: if _model_file.is_dir: # dir transferred size is updated by child files _model_file.transferred_size = 0 else: _model_file.transferred_size = min( _local.size, _remote.size) # also update all parent directories _parent_file = _model_file.parent while _parent_file is not None: _parent_file.transferred_size += _model_file.transferred_size _parent_file = _parent_file.parent # set the is_extractable flag if not _model_file.is_dir and Extract.is_archive_fast( _model_file.name): _model_file.is_extractable = True # Also set the flag for all of its parents _parent_file = _model_file.parent while _parent_file is not None: _parent_file.is_extractable = True _parent_file = _parent_file.parent # set the timestamps if _local: if _local.timestamp_created: _model_file.local_created_timestamp = _local.timestamp_created if _local.timestamp_modified: _model_file.local_modified_timestamp = _local.timestamp_modified if _remote: if _remote.timestamp_created: _model_file.remote_created_timestamp = _remote.timestamp_created if _remote.timestamp_modified: _model_file.remote_modified_timestamp = _remote.timestamp_modified
def test_diff_1(self): model_before = Model() model_after = Model() a = ModelFile("a", False) a.local_size = 100 b = ModelFile("b", False) b.remote_size = 200 c1 = ModelFile("c", False) c1.downloading_speed = 40 c2 = ModelFile("c", False) c2.downloading_speed = 50 d1 = ModelFile("d", False) d1.local_size = 500 d2 = ModelFile("d", False) d2.local_size = 500 d2.update_timestamp = datetime.now() # add a, remove b, update c, no change d (but do a timestamp update) model_before.add_file(b) model_before.add_file(c1) model_before.add_file(d1) model_after.add_file(a) model_after.add_file(c2) model_after.add_file(d2) diffs = ModelDiffUtil.diff_models(model_before, model_after) self.assertEqual(3, len(diffs)) added = [d for d in diffs if d.change == ModelDiff.Change.ADDED] self.assertEqual(1, len(added)) self.assertEqual(ModelDiff(ModelDiff.Change.ADDED, None, a), added[0]) removed = [d for d in diffs if d.change == ModelDiff.Change.REMOVED] self.assertEqual(1, len(removed)) self.assertEqual(ModelDiff(ModelDiff.Change.REMOVED, b, None), removed[0]) updated = [d for d in diffs if d.change == ModelDiff.Change.UPDATED] self.assertEqual(1, len(updated)) self.assertEqual(ModelDiff(ModelDiff.Change.UPDATED, c1, c2), updated[0])