From b10be1f8b730b480a9994bbfb4b34b774f4555ef Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 21 Apr 2020 20:45:37 +0000 Subject: [PATCH] refactor: Early-exit in update_test_databases_if_required. Just make each conditional run what it needs to run. The simplicity that this provides will be more apparent soon. --- zerver/lib/test_fixtures.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/zerver/lib/test_fixtures.py b/zerver/lib/test_fixtures.py index 376e31b57e..915b908c8f 100644 --- a/zerver/lib/test_fixtures.py +++ b/zerver/lib/test_fixtures.py @@ -224,13 +224,19 @@ def update_test_databases_if_required(use_force: bool=False, """ generate_fixtures_command = ['tools/setup/generate-fixtures'] test_template_db_status = TEST_DATABASE.template_status() + if use_force or test_template_db_status == 'needs_rebuild': generate_fixtures_command.append('--force') - elif test_template_db_status == 'run_migrations': - TEST_DATABASE.run_db_migrations() - elif not rebuild_test_database: + subprocess.check_call(generate_fixtures_command) return - subprocess.check_call(generate_fixtures_command) + + if test_template_db_status == 'run_migrations': + TEST_DATABASE.run_db_migrations() + subprocess.check_call(generate_fixtures_command) + return + + if rebuild_test_database: + subprocess.check_call(generate_fixtures_command) def get_migration_status(**options: Any) -> str: verbosity = options.get('verbosity', 1)