Added in tests for install and uninstall commands.

This commit is contained in:
Dave Hall 2011-09-11 21:09:01 +01:00
parent d68ba068ff
commit 5e141b38ba
4 changed files with 31 additions and 2 deletions

View file

@ -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):

View file

@ -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:

View file

@ -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")

View file

@ -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