Пример #1
0
def b2_file(name, mod_times, size=10):
    """
    Makes a File object for a b2 file, with one FileVersion for
    each modification time given in mod_times.

    Positive modification times are uploads, and negative modification
    times are hides.  It's a hack, but it works.

        b2_file('a.txt', [300, -200, 100])

    Is the same as:

        File(
            'a.txt',
            [
               FileVersion('id_a_300', 'a.txt', 300, 'upload'),
               FileVersion('id_a_200', 'a.txt', 200, 'hide'),
               FileVersion('id_a_100', 'a.txt', 100, 'upload')
            ]
        )
    """
    versions = [
        FileVersion('id_%s_%d' % (name[0], abs(mod_time)), 'folder/' + name,
                    abs(mod_time), 'upload' if 0 < mod_time else 'hide', size)
        for mod_time in mod_times
    ]  # yapf disable
    return File(name, versions)
Пример #2
0
def local_file(name, mod_times, size=10):
    """
    Makes a File object for a b2 file, with one FileVersion for
    each modification time given in mod_times.
    """
    versions = [
        FileVersion('/dir/%s' % (name,), name, mod_time, 'upload', size) for mod_time in mod_times
    ]
    return File(name, versions)
Пример #3
0
 def check_one_answer(self, has_source, id_relative_date_action_list,
                      expected_actions):
     source_file = File('a', []) if has_source else None
     dest_file_versions = [
         FileVersion(id_, 'a',
                     self.today + relative_date * self.one_day_millis,
                     action, 100)
         for (id_, relative_date, action) in id_relative_date_action_list
     ]
     dest_file = File('a', dest_file_versions)
     bucket = MagicMock()
     api = MagicMock()
     api.get_bucket_by_name.return_value = bucket
     dest_folder = B2Folder('bucket-1', 'folder', api)
     actual_actions = list(
         make_b2_keep_days_actions(source_file, dest_file, dest_folder,
                                   dest_folder, self.keep_days, self.today))
     actual_action_strs = [str(a) for a in actual_actions]
     self.assertEqual(expected_actions, actual_action_strs)
Пример #4
0
 def test_two(self):
     file_a1 = File("a.txt", [FileVersion("a", "a", 100, "upload", 10)])
     file_a2 = File("b.txt", [FileVersion("b", "b", 100, "upload", 10)])
     file_a3 = File("d.txt", [FileVersion("c", "c", 100, "upload", 10)])
     file_a4 = File("f.txt", [FileVersion("f", "f", 100, "upload", 10)])
     file_b1 = File("b.txt", [FileVersion("b", "b", 200, "upload", 10)])
     file_b2 = File("e.txt", [FileVersion("e", "e", 200, "upload", 10)])
     folder_a = FakeFolder('b2', [file_a1, file_a2, file_a3, file_a4])
     folder_b = FakeFolder('b2', [file_b1, file_b2])
     self.assertEqual([(file_a1, None), (file_a2, file_b1), (file_a3, None),
                       (None, file_b2), (file_a4, None)],
                      list(zip_folders(folder_a, folder_b, self.reporter)))
Пример #5
0
 def test_one_empty(self):
     file_a1 = File("a.txt", [FileVersion("a", "a", 100, "upload", 10)])
     folder_a = FakeFolder('b2', [file_a1])
     folder_b = FakeFolder('b2', [])
     self.assertEqual([(file_a1, None)],
                      list(zip_folders(folder_a, folder_b, self.reporter)))