예제 #1
0
 def testRegistration(self):
     # Register the model and test.
     watson.register(WatsonTestModel1)
     self.assertTrue(watson.is_registered(WatsonTestModel1))
     self.assertRaises(watson.RegistrationError, lambda: watson.register(WatsonTestModel1))
     self.assertTrue(WatsonTestModel1 in watson.get_registered_models())
     self.assertTrue(isinstance(watson.get_adapter(WatsonTestModel1), watson.SearchAdapter))
     # Unregister the model and text.
     watson.unregister(WatsonTestModel1)
     self.assertFalse(watson.is_registered(WatsonTestModel1))
     self.assertRaises(watson.RegistrationError, lambda: watson.unregister(WatsonTestModel1))
     self.assertTrue(WatsonTestModel1 not in watson.get_registered_models())
     self.assertRaises(watson.RegistrationError, lambda: isinstance(watson.get_adapter(WatsonTestModel1)))
예제 #2
0
 def testRegistration(self):
     # Register the model and test.
     watson.register(WatsonTestModel1)
     self.assertTrue(watson.is_registered(WatsonTestModel1))
     self.assertRaises(watson.RegistrationError, lambda: watson.register(WatsonTestModel1))
     self.assertTrue(WatsonTestModel1 in watson.get_registered_models())
     self.assertTrue(isinstance(watson.get_adapter(WatsonTestModel1), watson.SearchAdapter))
     # Unregister the model and text.
     watson.unregister(WatsonTestModel1)
     self.assertFalse(watson.is_registered(WatsonTestModel1))
     self.assertRaises(watson.RegistrationError, lambda: watson.unregister(WatsonTestModel1))
     self.assertTrue(WatsonTestModel1 not in watson.get_registered_models())
     self.assertRaises(watson.RegistrationError, lambda: isinstance(watson.get_adapter(WatsonTestModel1)))
예제 #3
0
 def setUp(self):
     # If migrations are off, then this is needed to get the indices installed. It has to
     # be called in the setUp() method, but multiple invocations should be safe.
     call_command("installwatson", verbosity=0)
     # Remove all the current registered models.
     self.registered_models = watson.get_registered_models()
     for model in self.registered_models:
         watson.unregister(model)
     # Register the test models.
     watson.register(self.model1)
     watson.register(self.model2, exclude=("id",))
     complex_registration_search_engine.register(WatsonTestModel1, exclude=("content", "description",), store=("is_published",))
     complex_registration_search_engine.register(WatsonTestModel2, fields=("title",))
     # Create some test models.
     self.test11 = WatsonTestModel1.objects.create(
         title = "title model1 instance11",
         content = "content model1 instance11",
         description = "description model1 instance11",
     )
     self.test12 = WatsonTestModel1.objects.create(
         title = "title model1 instance12",
         content = "content model1 instance12",
         description = "description model1 instance12",
     )
     self.test21 = WatsonTestModel2.objects.create(
         title = "title model2 instance21",
         content = "content model2 instance21",
         description = "description model2 instance21",
     )
     self.test22 = WatsonTestModel2.objects.create(
         title = "title model2 instance22",
         content = "content model2 instance22",
         description = "description model2 instance22",
     )
예제 #4
0
 def handle(self, *args, **options):
     """Runs the management command."""
     self.stdout.write(
         "The following models are registed for the django-watson search engine:\n"
     )
     for mdl in watson.get_registered_models():
         self.stdout.write("- %s\n" % mdl.__name__)
예제 #5
0
 def build_excludes(self):
     """
     Return a list of querysets that should not be matched by Watson. If the
     requesting user is not logged in, then this filters all
     is_published=False models.
     """
     excludes = []
     if self.request.user is None:
         for model in watson.get_registered_models():
             if issubclass(model, core_types_models.PublishableMixin):
                 excludes.append(model.objects.filter(is_published=False))
     return excludes
예제 #6
0
 def setUp(self):
     # If migrations are off, then this is needed to get the indices installed. It has to
     # be called in the setUp() method, but multiple invocations should be safe.
     call_command("installwatson", verbosity=0)
     # Remove all the current registered models.
     self.registered_models = watson.get_registered_models()
     for model in self.registered_models:
         watson.unregister(model)
     # Register the test models.
     watson.register(self.model1)
     watson.register(self.model2, exclude=("id",))
     watson.register(self.model3, exclude=("id",))
     complex_registration_search_engine.register(
         WatsonTestModel1, exclude=("content", "description",), store=("is_published",)
     )
     complex_registration_search_engine.register(
         WatsonTestModel2, fields=("title",)
     )
     # Create some test models.
     self.test11 = WatsonTestModel1.objects.create(
         title="title model1 instance11",
         content="content model1 instance11",
         description="description model1 instance11",
     )
     self.test12 = WatsonTestModel1.objects.create(
         title="title model1 instance12",
         content="content model1 instance12",
         description="description model1 instance12",
     )
     self.test21 = WatsonTestModel2.objects.create(
         title="title model2 instance21",
         content="content model2 instance21",
         description="description model2 instance21",
     )
     self.test22 = WatsonTestModel2.objects.create(
         title="title model2 instance22",
         content="content model2 instance22",
         description="description model2 instance22",
     )
     self.test31 = WatsonTestModel3.objects.create(
         title="title model3 instance31",
         content="content model3 instance31",
         description="description model3 instance31",
     )
     self.test32 = WatsonTestModel3.objects.create(
         title="title model3 instance32",
         content="content model3 instance32",
         description="description model3 instance32",
     )
예제 #7
0
 def handle_noargs(self, **options):
     """Runs the management command."""
     self.stdout.write("The following models are registed for the django-watson search engine:\n")
     for mdl in watson.get_registered_models():
         self.stdout.write("- %s\n" % mdl.__name__)