def testRegistration(self): # Register the model and test. watson.register(WatsonTestModel1) self.assertTrue(watson.is_registered(WatsonTestModel1)) self.assertRaises(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(RegistrationError, lambda: watson.unregister(WatsonTestModel1)) self.assertTrue(WatsonTestModel1 not in watson.get_registered_models()) self.assertRaises(RegistrationError, lambda: isinstance(watson.get_adapter(WatsonTestModel1)))
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", )
def get_q(self): # Get filters as a q object q = self._get_filters_from_queryset() model = self.queryset.model if self.query_string is not None: could_search = False for m in watson.get_registered_models(): if issubclass(m, model): could_search = True if could_search: query_subset = () for m in watson.get_registered_models(): query_subset += (m.objects.filter(q), ) return watson.search(self.query_string, models=query_subset) #return watson.search(self.query_string) return model.objects.none()
def setUpClass(cls): call_command("installwatson", verbosity=0) cls.registered_models = watson.get_registered_models() # Remove all the current registered models. for model in cls.registered_models: watson.unregister(model) # Register the test models. watson.register(Feed) watson.register(Post) watson.register(Topic) # init user cls.user = User.objects.create_user(username="******", email="*****@*****.**", password="******") cls.user.save() #init videogame Feeds Feed.createByURL("http://penny-arcade.com/feed").save() Feed.createByURL("http://thepunchlineismachismo.com/feed").save() Feed.createByURL( "http://rss.escapistmagazine.com/articles/comicsandcosplay/comics/critical-miss.xml" ).save() Feed.createByURL("http://xkcd.com/rss.xml").save() Feed.createByURL( "http://rss.nytimes.com/services/xml/rss/nyt/Golf.xml").save() cls.f1_m = Feed.objects.get(URL="http://penny-arcade.com/feed") cls.f1 = FeedSerializer(cls.f1_m).data cls.f2_m = Feed.objects.get( URL="http://thepunchlineismachismo.com/feed") cls.f2 = FeedSerializer(cls.f2_m).data cls.f3_m = Feed.objects.get( URL= "http://rss.escapistmagazine.com/articles/comicsandcosplay/comics/critical-miss.xml" ) cls.f3 = FeedSerializer(cls.f3_m).data cls.f4_m = Feed.objects.get(URL="http://xkcd.com/rss.xml") cls.f4 = FeedSerializer(cls.f4_m).data cls.f5_m = Feed.objects.get( URL="http://rss.nytimes.com/services/xml/rss/nyt/Golf.xml") cls.f5 = FeedSerializer(cls.f5_m).data
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__)