diff --git a/src/watson/backends.py b/src/watson/backends.py index c9c1222..1eea76c 100644 --- a/src/watson/backends.py +++ b/src/watson/backends.py @@ -34,6 +34,8 @@ class SearchBackend(object): """Executes the SQL needed to uninstall django-watson.""" pass + requires_installation = False + supports_ranking = False def do_search(self, engine_slug, queryset, search_text): @@ -136,6 +138,8 @@ class PostgresSearchBackend(SearchBackend): DROP FUNCTION watson_searchentry_trigger_handler(); """) + + requires_installation = True supports_ranking = True @@ -236,6 +240,8 @@ class MySQLSearchBackend(SearchBackend): cursor.execute("DROP INDEX watson_searchentry_description ON watson_searchentry") cursor.execute("DROP INDEX watson_searchentry_content ON watson_searchentry") + requires_installation = True + supports_ranking = True def do_search(self, engine_slug, queryset, search_text): diff --git a/src/watson/management/commands/installwatson.py b/src/watson/management/commands/installwatson.py index c6c2b87..1540a3b 100644 --- a/src/watson/management/commands/installwatson.py +++ b/src/watson/management/commands/installwatson.py @@ -15,7 +15,10 @@ class Command(NoArgsCommand): """Runs the management command.""" verbosity = int(options.get("verbosity", 1)) backend = get_backend() - if backend.is_installed(): + if not backend.requires_installation: + if verbosity >= 2: + self.stdout.write("Your search backend does not require installation.\n") + elif backend.is_installed(): if verbosity >= 2: self.stdout.write("django-watson is already installed.\n") else: diff --git a/src/watson/management/commands/uninstallwatson.py b/src/watson/management/commands/uninstallwatson.py index 2f58c84..66af0a4 100644 --- a/src/watson/management/commands/uninstallwatson.py +++ b/src/watson/management/commands/uninstallwatson.py @@ -15,7 +15,10 @@ class Command(NoArgsCommand): """Runs the management command.""" verbosity = int(options.get("verbosity", 1)) backend = get_backend() - if backend.is_installed(): + if not backend.requires_installation: + if verbosity >= 2: + self.stdout.write("Your search backend does not require installation.\n") + elif backend.is_installed(): backend.do_uninstall() if verbosity >= 2: self.stdout.write("django-watson has been successfully uninstalled.\n") diff --git a/src/watson/tests.py b/src/watson/tests.py index e47a0d6..bfbe52f 100644 --- a/src/watson/tests.py +++ b/src/watson/tests.py @@ -92,6 +92,23 @@ class RegistrationTest(TestCase): complex_registration_search_engine = SearchEngine("restricted") +class InstallUninstallTestBase(TestCase): + + def testUninstallAndInstall(self): + # Not too much to test here, as some backends don't require installation. + # Just make sure the commands don't error. + call_command("uninstallwatson", verbosity=0) + call_command("installwatson", verbosity=0) + + @skipUnless(get_backend().requires_installation, "search backend does not require installation") + def testRealInstallAndUninstall(self): + backend = get_backend() + call_command("uninstallwatson", verbosity=0) + self.assertFalse(backend.is_installed()) + call_command("installwatson", verbosity=0) + self.assertTrue(backend.is_installed()) + + class SearchTestBase(TestCase): model1 = TestModel1