test_fixtures: Refactor to have template_database_status API.

In this commit we are essentially just refactoring the function
is_template_database_current to be called template_database_status
and adjusting the return values accordingly.
This is essentially a preparatory commit for the upcoming commits
which will essentially enable us to not throw away entire DB and
rebuild from scratch if only running migrations could do the job.
This commit is contained in:
Aditya Bansal
2018-06-06 03:46:27 +05:30
committed by Tim Abbott
parent 53237d39aa
commit f7c11d1747
4 changed files with 25 additions and 19 deletions

View File

@@ -107,14 +107,15 @@ def check_setting_hash(setting_name: str, status_dir: str) -> bool:
return _check_hash(source_hash_file, target_content)
def is_template_database_current(
def template_database_status(
database_name: str='zulip_test_template',
migration_status: Optional[str]=None,
settings: str='zproject.test_settings',
status_dir: Optional[str]=None,
check_files: Optional[List[str]]=None,
check_settings: Optional[List[str]]=None) -> bool:
# Using str type for check_files because re.split doesn't accept unicode
check_settings: Optional[List[str]]=None) -> str:
# This function returns a status string specifying the type of
# state the template db is in and thus the kind of action required.
if check_files is None:
check_files = [
'zilencer/management/commands/populate_db.py',
@@ -144,6 +145,7 @@ def is_template_database_current(
for setting_name in check_settings])
hash_status = files_hash_status and settings_hash_status
return are_migrations_the_same(migration_status, settings=settings) and hash_status
if are_migrations_the_same(migration_status, settings=settings) and hash_status:
return 'current'
return False
return 'needs_rebuild'