def test_fresh_sync(self, local_client, s3_client): utils.set_local_contents(local_client, 'foo', timestamp=1000) utils.set_local_contents(local_client, 'bar', timestamp=2000) utils.set_s3_contents(s3_client, 'baz', timestamp=3000, data='what is up?') worker = sync.SyncWorker(local_client, s3_client) worker.sync() clients = [local_client, s3_client] assert_local_keys(clients, ['foo', 'bar', 'baz']) assert_remote_timestamp(clients, 'foo', 1000) assert_remote_timestamp(clients, 'bar', 2000) assert_remote_timestamp(clients, 'baz', 3000) assert_existence(clients, ['foo', 'bar', 'baz'], True) assert_contents(clients, 'baz', b'what is up?') utils.delete_local(local_client, 'foo') utils.set_local_contents(local_client, 'test', timestamp=5000) utils.set_s3_contents(s3_client, 'hello', timestamp=6000) utils.set_s3_contents(s3_client, 'baz', timestamp=8000, data='just syncing some stuff') worker.sync() assert_existence(clients, ['foo'], False) assert_local_keys(clients, ['test', 'bar', 'baz', 'hello']) assert_remote_timestamp(clients, 'bar', 2000) assert_remote_timestamp(clients, 'foo', 1000) assert_remote_timestamp(clients, 'test', 5000) assert_remote_timestamp(clients, 'hello', 6000) assert_remote_timestamp(clients, 'baz', 8000) assert_contents(clients, 'baz', b'just syncing some stuff') worker.sync()
def test_previously_deleted_now_created(self, local_client, s3_client): utils.set_s3_index(s3_client, { 'foo': { 'local_timestamp': None, 'remote_timestamp': 4000, } }) utils.set_local_index(local_client, { 'foo': { 'local_timstamp': None, 'remote_timestamp': 4000, } }) utils.set_local_contents(local_client, 'foo', timestamp=7000) # Will create previously deleted file worker = sync.SyncWorker(local_client, s3_client) worker.sync() clients = [local_client, s3_client] assert_local_keys(clients, ['foo']) assert_remote_timestamp(clients, 'foo', 7000) # delete the file again and check that it is successful utils.delete_local(local_client, 'foo') worker.sync() assert_local_keys(clients, []) assert_remote_timestamp(clients, 'foo', 7000)
def test_local_with_s3(self, local_client, s3_client): utils.set_s3_contents(s3_client, 'colors/cream', 9999, '#ddeeff') utils.set_local_contents(local_client, 'colors/red', 5000, '#ff0000') utils.set_local_contents(local_client, 'colors/green', 3000, '#00ff00') utils.set_local_contents(local_client, 'colors/blue', 2000, '#0000ff') worker = sync.SyncWorker(local_client, s3_client) worker.sync() clients = [local_client, s3_client] expected_keys = [ 'colors/red', 'colors/green', 'colors/blue', 'colors/cream' ] assert_local_keys(clients, expected_keys) assert_contents(clients, 'colors/red', b'#ff0000') assert_contents(clients, 'colors/green', b'#00ff00') assert_contents(clients, 'colors/blue', b'#0000ff') assert_contents(clients, 'colors/cream', b'#ddeeff') assert_remote_timestamp(clients, 'colors/red', 5000) assert_remote_timestamp(clients, 'colors/green', 3000) assert_remote_timestamp(clients, 'colors/blue', 2000) assert_remote_timestamp(clients, 'colors/cream', 9999) utils.delete_local(local_client, 'colors/red') worker.sync() expected_keys = ['colors/green', 'colors/blue', 'colors/cream'] assert_local_keys(clients, expected_keys)
def test_local_with_s3(self, local_client, s3_client): utils.set_s3_contents(s3_client, "colors/cream", 9999, "#ddeeff") utils.set_local_contents(local_client, "colors/red", 5000, "#ff0000") utils.set_local_contents(local_client, "colors/green", 3000, "#00ff00") utils.set_local_contents(local_client, "colors/blue", 2000, "#0000ff") worker = sync.SyncWorker(local_client, s3_client) worker.sync() clients = [local_client, s3_client] expected_keys = [ "colors/red", "colors/green", "colors/blue", "colors/cream" ] assert_local_keys(clients, expected_keys) assert_contents(clients, "colors/red", b"#ff0000") assert_contents(clients, "colors/green", b"#00ff00") assert_contents(clients, "colors/blue", b"#0000ff") assert_contents(clients, "colors/cream", b"#ddeeff") assert_remote_timestamp(clients, "colors/red", 5000) assert_remote_timestamp(clients, "colors/green", 3000) assert_remote_timestamp(clients, "colors/blue", 2000) assert_remote_timestamp(clients, "colors/cream", 9999) utils.delete_local(local_client, "colors/red") worker.sync() expected_keys = ["colors/green", "colors/blue", "colors/cream"] assert_local_keys(clients, expected_keys)
def test_three_way_sync(self, local_client, s3_client, local_client_2): utils.set_local_contents(local_client, 'foo', timestamp=1000) utils.set_s3_contents(s3_client, 'bar', timestamp=2000, data='red') utils.set_local_contents(local_client_2, 'baz', timestamp=3000) worker_1 = sync.SyncWorker(local_client, s3_client) worker_2 = sync.SyncWorker(local_client_2, s3_client) worker_3 = sync.SyncWorker(local_client, local_client_2) worker_1.sync() worker_2.sync() worker_3.sync() clients = [local_client, s3_client, local_client_2] assert_local_keys(clients, ['foo', 'bar', 'baz']) assert_contents(clients, 'bar', b'red') assert_remote_timestamp(clients, 'foo', 1000) assert_remote_timestamp(clients, 'bar', 2000) assert_remote_timestamp(clients, 'baz', 3000) utils.set_s3_contents(s3_client, 'bar', timestamp=8000, data='green') worker_1.sync() worker_2.sync() worker_3.sync() assert_local_keys(clients, ['foo', 'bar', 'baz']) assert_contents(clients, 'bar', b'green') assert_remote_timestamp(clients, 'foo', 1000) assert_remote_timestamp(clients, 'bar', 8000) assert_remote_timestamp(clients, 'baz', 3000) utils.delete_local(local_client_2, 'foo') worker_1.sync() worker_2.sync() worker_3.sync() assert_existence(clients, ['foo'], False) assert_local_keys(clients, ['bar', 'baz']) assert_remote_timestamp(clients, 'foo', 1000) worker_1.sync() worker_2.sync() worker_3.sync()
def test_three_way_sync(self, local_client, s3_client, local_client_2): utils.set_local_contents(local_client, "foo", timestamp=1000) utils.set_s3_contents(s3_client, "bar", timestamp=2000, data="red") utils.set_local_contents(local_client_2, "baz", timestamp=3000) worker_1 = sync.SyncWorker(local_client, s3_client) worker_2 = sync.SyncWorker(local_client_2, s3_client) worker_3 = sync.SyncWorker(local_client, local_client_2) worker_1.sync() worker_2.sync() worker_3.sync() clients = [local_client, s3_client, local_client_2] assert_local_keys(clients, ["foo", "bar", "baz"]) assert_contents(clients, "bar", b"red") assert_remote_timestamp(clients, "foo", 1000) assert_remote_timestamp(clients, "bar", 2000) assert_remote_timestamp(clients, "baz", 3000) utils.set_s3_contents(s3_client, "bar", timestamp=8000, data="green") worker_1.sync() worker_2.sync() worker_3.sync() assert_local_keys(clients, ["foo", "bar", "baz"]) assert_contents(clients, "bar", b"green") assert_remote_timestamp(clients, "foo", 1000) assert_remote_timestamp(clients, "bar", 8000) assert_remote_timestamp(clients, "baz", 3000) utils.delete_local(local_client_2, "foo") worker_1.sync() worker_2.sync() worker_3.sync() assert_existence(clients, ["foo"], False) assert_local_keys(clients, ["bar", "baz"]) assert_remote_timestamp(clients, "foo", 1000) worker_1.sync() worker_2.sync() worker_3.sync()
def test_fresh_sync(self, local_client, s3_client): utils.set_local_contents(local_client, "foo", timestamp=1000) utils.set_local_contents(local_client, "bar", timestamp=2000) utils.set_s3_contents(s3_client, "baz", timestamp=3000, data="what is up?") worker = sync.SyncWorker(local_client, s3_client) worker.sync() clients = [local_client, s3_client] assert_local_keys(clients, ["foo", "bar", "baz"]) assert_remote_timestamp(clients, "foo", 1000) assert_remote_timestamp(clients, "bar", 2000) assert_remote_timestamp(clients, "baz", 3000) assert_existence(clients, ["foo", "bar", "baz"], True) assert_contents(clients, "baz", b"what is up?") utils.delete_local(local_client, "foo") utils.set_local_contents(local_client, "test", timestamp=5000) utils.set_s3_contents(s3_client, "hello", timestamp=6000) utils.set_s3_contents(s3_client, "baz", timestamp=8000, data="just syncing some stuff") worker.sync() assert_existence(clients, ["foo"], False) assert_local_keys(clients, ["test", "bar", "baz", "hello"]) assert_remote_timestamp(clients, "bar", 2000) assert_remote_timestamp(clients, "foo", 1000) assert_remote_timestamp(clients, "test", 5000) assert_remote_timestamp(clients, "hello", 6000) assert_remote_timestamp(clients, "baz", 8000) assert_contents(clients, "baz", b"just syncing some stuff") worker.sync()