Skip to content
Snippets Groups Projects
Commit 97fe6ec7 authored by Bryan BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

fix test, for prefill when empty

parent 06cd9580
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ from autocomplete_multi_models import business_process, models, utils ...@@ -8,6 +8,7 @@ from autocomplete_multi_models import business_process, models, utils
class Command(BaseCommand): class Command(BaseCommand):
def add_arguments(self, parser): def add_arguments(self, parser):
parser.add_argument('--forced', action='store_true') parser.add_argument('--forced', action='store_true')
parser.add_argument('--no-fill-if-empty', action='store_true')
@transaction.atomic @transaction.atomic
def handle(self, *args, **options): def handle(self, *args, **options):
...@@ -18,8 +19,7 @@ class Command(BaseCommand): ...@@ -18,8 +19,7 @@ class Command(BaseCommand):
business_process.rebuild_index() business_process.rebuild_index()
te = time.time() te = time.time()
print(f"Index rebuild in {int((te - ts) * 100) / 100}s, it contains {models.IndexedWord.objects.count()} words") print(f"Index rebuild in {int((te - ts) * 100) / 100}s, it contains {models.IndexedWord.objects.count()} words")
if not models.IndexedWord.objects.exists(): if not options['no_fill_if_empty'] and not models.IndexedWord.objects.exists():
print("DB is empty, prefilling it with some words")
for s in [ for s in [
"Coming soon", "Coming soon",
"coming soon", "coming soon",
......
...@@ -157,7 +157,7 @@ class NeedRebuildDefaultBehaviorTestCase(test_helpers.ChangeAutoCompleteSettings ...@@ -157,7 +157,7 @@ class NeedRebuildDefaultBehaviorTestCase(test_helpers.ChangeAutoCompleteSettings
self.assertFalse(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, None)) self.assertFalse(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, None))
business_process.set_setting_in_storage(utils.REBUILD_NEEDED, True) business_process.set_setting_in_storage(utils.REBUILD_NEEDED, True)
self.assertTrue(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, None)) 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.assertFalse(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, None))
self.assertEqual(models.IndexedWord.objects.count(), 0) self.assertEqual(models.IndexedWord.objects.count(), 0)
...@@ -177,7 +177,7 @@ class NeedRebuildFileSettingsBasedTestCase(test_helpers.ChangeAutoCompleteSettin ...@@ -177,7 +177,7 @@ class NeedRebuildFileSettingsBasedTestCase(test_helpers.ChangeAutoCompleteSettin
models.IndexedWord.objects.create(word="TOTO") models.IndexedWord.objects.create(word="TOTO")
self.assertTrue(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, True)) 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.assertFalse(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, False))
self.assertEqual(models.IndexedWord.objects.count(), 0) self.assertEqual(models.IndexedWord.objects.count(), 0)
...@@ -187,7 +187,7 @@ class NeedRebuildFileSettingsBasedTestCase(test_helpers.ChangeAutoCompleteSettin ...@@ -187,7 +187,7 @@ class NeedRebuildFileSettingsBasedTestCase(test_helpers.ChangeAutoCompleteSettin
self.assertEqual(models.IndexedWord.objects.count(), 1) self.assertEqual(models.IndexedWord.objects.count(), 1)
business_process.set_setting_in_storage(utils.REBUILD_NEEDED, False) 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) self.assertEqual(models.IndexedWord.objects.count(), 0)
signals.instance_delete(sender=None, instance=None, field_names=[]) signals.instance_delete(sender=None, instance=None, field_names=[])
......
[metadata] [metadata]
name = autocomplete-multi-models 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. 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 long_description = file: README.md
author = Bryan Brancotte author = Bryan Brancotte
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment