コード例 #1
0
    def test_searchqueryset_using(self):
        # Using the default.
        sqs = SearchQuerySet('solr')
        self.assertEqual(sqs.count(), 5)
        self.assertEqual(sqs.models(Foo).count(), 2)
        self.assertEqual(sqs.models(Bar).count(), 3)

        self.assertEqual(sqs.using('solr').count(), 5)
        self.assertEqual(sqs.using('solr').models(Foo).count(), 2)
        self.assertEqual(sqs.using('solr').models(Bar).count(), 3)

        self.assertEqual(sqs.using('elasticsearch').count(), 2)
        self.assertEqual(sqs.using('elasticsearch').models(Foo).count(), 2)
        self.assertEqual(sqs.using('elasticsearch').models(Bar).count(), 0)
コード例 #2
0
    def test_handle_delete(self):
        # Because the code here is pretty leaky (abstraction-wise), we'll test
        # the actual setup.
        # First, ensure the signal is setup.
        self.assertEqual(len(models.signals.post_delete.receivers), 1)

        # Second, check the existing search data.
        sqs = SearchQuerySet('solr')
        self.assertEqual(sqs.using('solr').count(), 5)
        self.assertEqual(sqs.using('solr').models(Foo).count(), 2)
        self.assertEqual(sqs.using('solr').models(Bar).count(), 3)
        self.assertEqual(sqs.using('elasticsearch').count(), 2)
        self.assertEqual(sqs.using('elasticsearch').models(Foo).count(), 2)

        self.assertEqual(sqs.using('solr').models(Foo).order_by('django_id')[0].text, 'foo 1')
        self.assertEqual(sqs.using('elasticsearch').models(Foo).order_by('django_id')[0].text, 'foo 1')

        # Third, delete the model, which should fire the signal & remove the
        # record from the index.
        self.foo_1.delete()

        # Fourth, check the search data for the now-removed data, making sure counts
        # have changed correctly.
        sqs = SearchQuerySet('solr')
        self.assertEqual(sqs.using('solr').count(), 4)
        self.assertEqual(sqs.using('solr').models(Foo).count(), 1)
        self.assertEqual(sqs.using('solr').models(Bar).count(), 3)
        self.assertEqual(sqs.using('elasticsearch').count(), 2)
        self.assertEqual(sqs.using('elasticsearch').models(Foo).count(), 2)

        self.assertEqual(sqs.using('solr').models(Foo).order_by('django_id')[0].text, 'foo 2')
        self.assertEqual(sqs.using('elasticsearch').models(Foo).order_by('django_id')[0].text, 'foo 1')
コード例 #3
0
    def test_handle_save(self):
        # Because the code here is pretty leaky (abstraction-wise), we'll test
        # the actual setup.
        # First, ensure the signal is setup.
        self.assertEqual(len(models.signals.post_save.receivers), 1)

        # Second, check the existing search data.
        sqs = SearchQuerySet('solr')
        self.assertEqual(sqs.using('solr').count(), 5)
        self.assertEqual(sqs.using('solr').models(Foo).count(), 2)
        self.assertEqual(sqs.using('solr').models(Bar).count(), 3)
        self.assertEqual(sqs.using('elasticsearch').count(), 2)
        self.assertEqual(sqs.using('elasticsearch').models(Foo).count(), 2)

        self.assertEqual(sqs.using('solr').models(Foo).order_by('django_id')[0].text, 'foo 1')
        self.assertEqual(sqs.using('elasticsearch').models(Foo).order_by('django_id')[0].text, 'foo 1')

        # Third, save the model, which should fire the signal & index the
        # new data.
        self.foo_1.body = 'A different body'
        self.foo_1.save()

        # Fourth, check the search data for the updated data, making sure counts
        # haven't changed.
        sqs = SearchQuerySet('solr')
        self.assertEqual(sqs.using('solr').count(), 5)
        self.assertEqual(sqs.using('solr').models(Foo).count(), 2)
        self.assertEqual(sqs.using('solr').models(Bar).count(), 3)
        self.assertEqual(sqs.using('elasticsearch').count(), 2)
        self.assertEqual(sqs.using('elasticsearch').models(Foo).count(), 2)

        self.assertEqual(sqs.using('solr').models(Foo).order_by('django_id')[0].text, 'A different body')
        self.assertEqual(sqs.using('elasticsearch').models(Foo).order_by('django_id')[0].text, 'foo 1')