|
@@ -63,15 +63,15 @@ def clean(value): |
|
|
return value |
|
|
return value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def exists_in_backup(doctypes, file): |
|
|
|
|
|
"""Checks if the list of doctypes exist in the database.sql.gz file supplied |
|
|
|
|
|
|
|
|
def missing_in_backup(doctypes, file): |
|
|
|
|
|
"""Returns list of missing doctypes in the backup. |
|
|
|
|
|
|
|
|
Args: |
|
|
Args: |
|
|
doctypes (list): List of DocTypes to be checked |
|
|
doctypes (list): List of DocTypes to be checked |
|
|
file (str): Path of the database file |
|
|
file (str): Path of the database file |
|
|
|
|
|
|
|
|
Returns: |
|
|
Returns: |
|
|
bool: True if all tables exist |
|
|
|
|
|
|
|
|
doctypes(list): doctypes that are missing in backup |
|
|
""" |
|
|
""" |
|
|
predicate = ( |
|
|
predicate = ( |
|
|
'COPY public."tab{}"' |
|
|
'COPY public."tab{}"' |
|
@@ -79,8 +79,24 @@ def exists_in_backup(doctypes, file): |
|
|
else "CREATE TABLE `tab{}`" |
|
|
else "CREATE TABLE `tab{}`" |
|
|
) |
|
|
) |
|
|
with gzip.open(file, "rb") as f: |
|
|
with gzip.open(file, "rb") as f: |
|
|
content = f.read().decode("utf8") |
|
|
|
|
|
return all(predicate.format(doctype).lower() in content.lower() for doctype in doctypes) |
|
|
|
|
|
|
|
|
content = f.read().decode("utf8").lower() |
|
|
|
|
|
|
|
|
|
|
|
return [doctype for doctype in doctypes |
|
|
|
|
|
if predicate.format(doctype).lower() not in content] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def exists_in_backup(doctypes, file): |
|
|
|
|
|
"""Checks if the list of doctypes exist in the database.sql.gz file supplied |
|
|
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
|
|
doctypes (list): List of DocTypes to be checked |
|
|
|
|
|
file (str): Path of the database file |
|
|
|
|
|
|
|
|
|
|
|
Returns: |
|
|
|
|
|
bool: True if all tables exist |
|
|
|
|
|
""" |
|
|
|
|
|
missing_doctypes = missing_in_backup(doctypes, file) |
|
|
|
|
|
return len(missing_doctypes) == 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseTestCommands(unittest.TestCase): |
|
|
class BaseTestCommands(unittest.TestCase): |
|
@@ -222,7 +238,7 @@ class TestCommands(BaseTestCommands): |
|
|
self.execute("bench --site {site} backup --verbose") |
|
|
self.execute("bench --site {site} backup --verbose") |
|
|
self.assertEqual(self.returncode, 0) |
|
|
self.assertEqual(self.returncode, 0) |
|
|
database = fetch_latest_backups(partial=True)["database"] |
|
|
database = fetch_latest_backups(partial=True)["database"] |
|
|
self.assertTrue(exists_in_backup(backup["includes"]["includes"], database)) |
|
|
|
|
|
|
|
|
self.assertEqual([], missing_in_backup(backup["includes"]["includes"], database)) |
|
|
|
|
|
|
|
|
# test 8: take a backup with frappe.conf.backup.excludes |
|
|
# test 8: take a backup with frappe.conf.backup.excludes |
|
|
self.execute( |
|
|
self.execute( |
|
@@ -233,7 +249,7 @@ class TestCommands(BaseTestCommands): |
|
|
self.assertEqual(self.returncode, 0) |
|
|
self.assertEqual(self.returncode, 0) |
|
|
database = fetch_latest_backups(partial=True)["database"] |
|
|
database = fetch_latest_backups(partial=True)["database"] |
|
|
self.assertFalse(exists_in_backup(backup["excludes"]["excludes"], database)) |
|
|
self.assertFalse(exists_in_backup(backup["excludes"]["excludes"], database)) |
|
|
self.assertTrue(exists_in_backup(backup["includes"]["includes"], database)) |
|
|
|
|
|
|
|
|
self.assertEqual([], missing_in_backup(backup["includes"]["includes"], database)) |
|
|
|
|
|
|
|
|
# test 9: take a backup with --include (with frappe.conf.excludes still set) |
|
|
# test 9: take a backup with --include (with frappe.conf.excludes still set) |
|
|
self.execute( |
|
|
self.execute( |
|
@@ -242,7 +258,7 @@ class TestCommands(BaseTestCommands): |
|
|
) |
|
|
) |
|
|
self.assertEqual(self.returncode, 0) |
|
|
self.assertEqual(self.returncode, 0) |
|
|
database = fetch_latest_backups(partial=True)["database"] |
|
|
database = fetch_latest_backups(partial=True)["database"] |
|
|
self.assertTrue(exists_in_backup(backup["includes"]["includes"], database)) |
|
|
|
|
|
|
|
|
self.assertEqual([], missing_in_backup(backup["includes"]["includes"], database)) |
|
|
|
|
|
|
|
|
# test 10: take a backup with --exclude |
|
|
# test 10: take a backup with --exclude |
|
|
self.execute( |
|
|
self.execute( |
|
@@ -257,7 +273,7 @@ class TestCommands(BaseTestCommands): |
|
|
self.execute("bench --site {site} backup --ignore-backup-conf") |
|
|
self.execute("bench --site {site} backup --ignore-backup-conf") |
|
|
self.assertEqual(self.returncode, 0) |
|
|
self.assertEqual(self.returncode, 0) |
|
|
database = fetch_latest_backups()["database"] |
|
|
database = fetch_latest_backups()["database"] |
|
|
self.assertTrue(exists_in_backup(backup["excludes"]["excludes"], database)) |
|
|
|
|
|
|
|
|
self.assertEqual([], missing_in_backup(backup["excludes"]["excludes"], database)) |
|
|
|
|
|
|
|
|
def test_restore(self): |
|
|
def test_restore(self): |
|
|
# step 0: create a site to run the test on |
|
|
# step 0: create a site to run the test on |
|
|