chore: add in some tests for backup

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
Akhil Narang 2023-11-09 18:21:56 +05:30
parent 7f433b84af
commit 9bf818eb4a
No known key found for this signature in database
GPG key ID: 9DCC61E211BF645F

View file

@ -547,6 +547,42 @@ class TestBackups(BaseTestCommands):
self.assertIn("successfully completed", self.stdout)
self.assertNotEqual(before_backup["database"], after_backup["database"])
@skipIf(
not (frappe.conf.db_type == "mariadb"),
"Only for MariaDB",
)
def test_backup_extract_restore(self):
"""Restore a backup after extracting"""
self.execute("bench --site {site} backup")
self.assertEqual(self.returncode, 0)
backup = fetch_latest_backups()
self.execute(f"gunzip {backup['database']}")
self.assertEqual(self.returncode, 0)
backup_sql = backup["database"].replace(".gz", "")
assert os.path.isfile(backup_sql)
self.execute(
"bench --site {site} restore {backup_sql}",
{
"backup_sql": backup_sql,
},
)
self.assertEqual(self.returncode, 0)
@skipIf(
not (frappe.conf.db_type == "mariadb"),
"Only for MariaDB",
)
def test_old_backup_restore(self):
"""Restore a backup after extracting"""
self.execute("bench --site {site} backup --old-backup-metadata")
self.assertEqual(self.returncode, 0)
backup = fetch_latest_backups()
self.execute(
"bench --site {site} restore {database}",
backup,
)
self.assertEqual(self.returncode, 0)
def test_backup_fails_with_exit_code(self):
"""Provide incorrect options to check if exit code is 1"""
odb = BackupGenerator(