From 97fe6ec71fa198d75aa538dd73bc34ef85987d20 Mon Sep 17 00:00:00 2001 From: Bryan Brancotte <bryan.brancotte@pasteur.fr> Date: Mon, 12 Dec 2022 14:38:46 +0100 Subject: [PATCH] fix test, for prefill when empty --- .../management/commands/makeautocompleteindex.py | 4 ++-- autocomplete_multi_models/tests/test_business_process.py | 6 +++--- setup.cfg | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/autocomplete_multi_models/management/commands/makeautocompleteindex.py b/autocomplete_multi_models/management/commands/makeautocompleteindex.py index b10880a..32bc19c 100644 --- a/autocomplete_multi_models/management/commands/makeautocompleteindex.py +++ b/autocomplete_multi_models/management/commands/makeautocompleteindex.py @@ -8,6 +8,7 @@ from autocomplete_multi_models import business_process, models, utils class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('--forced', action='store_true') + parser.add_argument('--no-fill-if-empty', action='store_true') @transaction.atomic def handle(self, *args, **options): @@ -18,8 +19,7 @@ class Command(BaseCommand): business_process.rebuild_index() te = time.time() print(f"Index rebuild in {int((te - ts) * 100) / 100}s, it contains {models.IndexedWord.objects.count()} words") - if not models.IndexedWord.objects.exists(): - print("DB is empty, prefilling it with some words") + if not options['no_fill_if_empty'] and not models.IndexedWord.objects.exists(): for s in [ "Coming soon", "coming soon", diff --git a/autocomplete_multi_models/tests/test_business_process.py b/autocomplete_multi_models/tests/test_business_process.py index c8c6eb9..ef1dbab 100644 --- a/autocomplete_multi_models/tests/test_business_process.py +++ b/autocomplete_multi_models/tests/test_business_process.py @@ -157,7 +157,7 @@ class NeedRebuildDefaultBehaviorTestCase(test_helpers.ChangeAutoCompleteSettings self.assertFalse(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, None)) business_process.set_setting_in_storage(utils.REBUILD_NEEDED, True) self.assertTrue(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, None)) - management.call_command('makeautocompleteindex') + management.call_command('makeautocompleteindex', no_fill_if_empty=True) self.assertFalse(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, None)) self.assertEqual(models.IndexedWord.objects.count(), 0) @@ -177,7 +177,7 @@ class NeedRebuildFileSettingsBasedTestCase(test_helpers.ChangeAutoCompleteSettin models.IndexedWord.objects.create(word="TOTO") self.assertTrue(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, True)) - management.call_command('makeautocompleteindex') + management.call_command('makeautocompleteindex', no_fill_if_empty=True) self.assertFalse(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, False)) self.assertEqual(models.IndexedWord.objects.count(), 0) @@ -187,7 +187,7 @@ class NeedRebuildFileSettingsBasedTestCase(test_helpers.ChangeAutoCompleteSettin self.assertEqual(models.IndexedWord.objects.count(), 1) business_process.set_setting_in_storage(utils.REBUILD_NEEDED, False) - management.call_command('makeautocompleteindex', forced=True) + management.call_command('makeautocompleteindex', forced=True, no_fill_if_empty=True) self.assertEqual(models.IndexedWord.objects.count(), 0) signals.instance_delete(sender=None, instance=None, field_names=[]) diff --git a/setup.cfg b/setup.cfg index 2849107..b146079 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = autocomplete-multi-models -version = 0.4.3 +version = 0.4.3.1 description = An app that index fields across multiple models, and expose an api to query for word similar to the query. long_description = file: README.md author = Bryan Brancotte -- GitLab