def test_2_resotre_from_google_drive(self): logging.getLogger("HiveBackupTestCase").debug( "\nRunning test_2_resotre_from_google_drive") google_auth_token = '''{ "token": "ya29.A0AfH6SMBB9WMZvjyxF2n7lfh4NHKaHdjd7ESfJOvAQctNJqydbM6PDlfV2A4oQT_-aINM_n0qmNPuns22a_Ufwp9C1cyzrjINZ4V1l-HAwR7uH8-BxY4QsKRi0gV0T50JyKm8Bmk5uHUGsZQfJfbMoYcCGZFOdAxuvf7Ue14LFgc", "refresh_token": "1//06gWBqRQQMerxCgYIARAAGAYSNwF-L9IrS5H5ETnTrxfgyMk3b9O1K1pclZducb21cqhwc2rmsLVwUHZCjXM0R4sEyAhXlM6xvPo", "token_uri": "https://oauth2.googleapis.com/token", "client_id": "24235223939-guh47dijl0f0idm7h04bd44ulfcodta0.apps.googleusercontent.com", "client_secret": "mqaI40MlghlNkfaFtDBzvpGg", "scopes": ["https://www.googleapis.com/auth/drive"], "expiry": "2020-11-18T04:13:37Z"}''' r, s = self.parse_response( self.test_client.post('/api/v1/backup/restore_from_google_drive', data=google_auth_token, headers=self.auth)) self.assert200(s) self.assertEqual(r["_status"], "OK") drive_name = HiveBackup.gene_did_google_drive_name(self.did) HiveBackup.restore_vault_data(self.did)
def test_3_classify_save_files(self): vault_folder = Path("~/vault/dir") saved_file_list = list() saved_file_list.append(["1234561", "testfile1"]) saved_file_list.append(["1234563", "testfile3"]) saved_file_list.append(["12345611", "f1/testfile_11"]) saved_file_list.append(["12345612x", "f1/testfile_12"]) saved_file_list.append(["12345613", "f1/testfile_13"]) saved_file_list.append(["123456121", "f1/f2/testfile_121"]) saved_file_list.append(["123456122", "f1/f2/testfile_122"]) saved_file_list.append(["123456111x", "f1/f_1/f2/testfile_111"]) saved_file_list.append(["123456112", "f1/f_1/f2/testfile_112"]) saved_file_list.append(["123456114", "f1/f_1/f2/testfile_114"]) local_file_list = list() local_file_list.append(["1234561", "~/vault/dir/testfile1"]) local_file_list.append(["1234562", "~/vault/dir/testfile2"]) local_file_list.append(["1234563", "~/vault/dir/testfile3"]) local_file_list.append(["12345611", "~/vault/dir/f1/testfile_11"]) local_file_list.append(["12345612", "~/vault/dir/f1/testfile_12"]) local_file_list.append(["12345613", "~/vault/dir/f1/testfile_13"]) local_file_list.append(["123456121", "~/vault/dir/f1/f2/testfile_121"]) local_file_list.append(["123456122", "~/vault/dir/f1/f2/testfile_122"]) local_file_list.append( ["123456111", "~/vault/dir/f1/f_1/f2/testfile_111"]) local_file_list.append( ["123456112", "~/vault/dir/f1/f_1/f2/testfile_112"]) local_file_list.append( ["123456113", "~/vault/dir/f1/f_1/f2/testfile_113"]) file_put_list, file_patch_list, file_delete_list = HiveBackup.classify_save_files( saved_file_list, local_file_list, vault_folder) file_put_list_compare = list() file_put_list_compare.append(["~/vault/dir/testfile2", "testfile2"]) file_put_list_compare.append( ["~/vault/dir/f1/f_1/f2/testfile_113", "f1/f_1/f2/testfile_113"]) file_patch_list_compare = list() file_patch_list_compare.append( ["~/vault/dir/f1/testfile_12", "f1/testfile_12"]) file_patch_list_compare.append( ["~/vault/dir/f1/f_1/f2/testfile_111", "f1/f_1/f2/testfile_111"]) file_delete_list_compare = list() file_delete_list_compare.append("f1/f_1/f2/testfile_114") self.assertEquals(file_put_list, file_put_list_compare) self.assertEquals(file_patch_list, file_patch_list_compare) self.assertEquals(file_delete_list, file_delete_list_compare)
def test_2_classify_restore_files_same(self): vault_folder = Path("~/vault/dir") saved_file_list = list() saved_file_list.append(["1234561", "testfile1"]) saved_file_list.append(["1234562", "testfile2"]) saved_file_list.append(["1234563", "testfile3"]) saved_file_list.append(["12345611", "f1/testfile_11"]) saved_file_list.append(["12345612", "f1/testfile_12"]) saved_file_list.append(["12345613", "f1/testfile_13"]) saved_file_list.append(["123456121", "f1/f2/testfile_121"]) saved_file_list.append(["123456122", "f1/f2/testfile_122"]) saved_file_list.append(["123456111", "f1/f_1/f2/testfile_111"]) saved_file_list.append(["123456112", "f1/f_1/f2/testfile_112"]) saved_file_list.append(["123456113", "f1/f_1/f2/testfile_113"]) local_file_list = list() local_file_list.append(["1234561", "~/vault/dir/testfile1"]) local_file_list.append(["1234562", "~/vault/dir/testfile2"]) local_file_list.append(["1234563", "~/vault/dir/testfile3"]) local_file_list.append(["12345611", "~/vault/dir/f1/testfile_11"]) local_file_list.append(["12345612", "~/vault/dir/f1/testfile_12"]) local_file_list.append(["12345613", "~/vault/dir/f1/testfile_13"]) local_file_list.append(["123456121", "~/vault/dir/f1/f2/testfile_121"]) local_file_list.append(["123456122", "~/vault/dir/f1/f2/testfile_122"]) local_file_list.append( ["123456111", "~/vault/dir/f1/f_1/f2/testfile_111"]) local_file_list.append( ["123456112", "~/vault/dir/f1/f_1/f2/testfile_112"]) local_file_list.append( ["123456113", "~/vault/dir/f1/f_1/f2/testfile_113"]) file_get_list, file_patch_list, file_delete_list = HiveBackup.classify_restore_files( saved_file_list, local_file_list, vault_folder) self.assertFalse(file_get_list) self.assertFalse(file_patch_list) self.assertFalse(file_delete_list)
from flask import Blueprint from hive.main.hive_backup import HiveBackup from hive.util.constants import INTER_BACKUP_FTP_START_URL, INTER_BACKUP_FTP_END_URL, INTER_BACKUP_SAVE_URL h_backup = HiveBackup() hive_backup = Blueprint('hive_backup', __name__) def init_app(app, mode): h_backup.init_app(app, mode) app.register_blueprint(hive_backup) @hive_backup.route('/api/v1/backup/save_to_google_drive', methods=['POST']) def save_to_google_drive(): return h_backup.save_to_google_drive() @hive_backup.route('/api/v1/backup/restore_from_google_drive', methods=['POST']) def restore_from_google_drive(): return h_backup.restore_from_google_drive() @hive_backup.route('/api/v1/backup/state', methods=['GET']) def get_sync_state(): return h_backup.get_sync_state() @hive_backup.route('/api/v1/backup/save_to_node', methods=['POST'])