예제 #1
0
    def test_remove_object(self):
        self.mi.update()
        self.assertEqual(self.sb.search('*')['hits'], 3)

        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.mi.update_object(mock)
        self.assertEqual(self.sb.search('*')['hits'], 4)

        self.mi.remove_object(mock)
        self.assertEqual([(res.content_type(), res.pk) for res in self.sb.search('*')['results']], [('core.mockmodel', '1'), ('core.mockmodel', '2'), ('core.mockmodel', '3')])

        # Put it back so we can test passing kwargs.
        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.mi.update_object(mock)
        self.assertEqual(self.sb.search('*')['hits'], 4)

        self.mi.remove_object(mock, commit=False)
        self.assertEqual([(res.content_type(), res.pk) for res in self.sb.search('*')['results']], [('core.mockmodel', '1'), ('core.mockmodel', '2'), ('core.mockmodel', '3'), ('core.mockmodel', '20')])

        self.sb.clear()
예제 #2
0
    def test_remove_object(self):
        self.mi.update()
        self.assertEqual(self.sb.search('*')['hits'], 3)

        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.mi.update_object(mock)
        self.assertEqual(self.sb.search('*')['hits'], 4)

        self.mi.remove_object(mock)
        self.assertEqual([(res.content_type(), res.pk) for res in self.sb.search('*')['results']], [(u'core.mockmodel', u'1'), (u'core.mockmodel', u'2'), (u'core.mockmodel', u'3')])

        # Put it back so we can test passing kwargs.
        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.mi.update_object(mock)
        self.assertEqual(self.sb.search('*')['hits'], 4)

        self.mi.remove_object(mock, commit=False)
        self.assertEqual([(res.content_type(), res.pk) for res in self.sb.search('*')['results']], [(u'core.mockmodel', u'1'), (u'core.mockmodel', u'2'), (u'core.mockmodel', u'3'), (u'core.mockmodel', u'20')])

        self.sb.clear()
    def test_remove_object(self):
        self.mi.update()
        self.assertEqual(self.sb.search("*")["hits"], 3)

        mock = MockModel()
        mock.pk = 20
        mock.author = "daniel%s" % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.mi.update_object(mock)
        self.assertEqual(self.sb.search("*")["hits"], 4)

        self.mi.remove_object(mock)
        self.assertEqual(
            [(res.content_type(), res.pk) for res in self.sb.search("*")["results"]],
            [("core.mockmodel", "1"), ("core.mockmodel", "2"), ("core.mockmodel", "3")],
        )

        # Put it back so we can test passing kwargs.
        mock = MockModel()
        mock.pk = 20
        mock.author = "daniel%s" % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.mi.update_object(mock)
        self.assertEqual(self.sb.search("*")["hits"], 4)

        self.mi.remove_object(mock, commit=False)
        self.assertEqual(
            [(res.content_type(), res.pk) for res in self.sb.search("*")["results"]],
            [("core.mockmodel", "1"), ("core.mockmodel", "2"), ("core.mockmodel", "3"), ("core.mockmodel", "20")],
        )

        self.sb.clear()
예제 #4
0
    def test_prepare(self):
        mock = MockModel()
        mock.pk = 1
        pk = IntegerField(model_attr='pk')

        self.assertEqual(pk.prepare(mock), 1)

        # Simulate failed lookups.
        mock_tag = MockTag(name='primary')
        mock = MockModel()
        mock.tag = mock_tag
        tag_count = IntegerField(model_attr='tag__count')

        self.assertRaises(SearchFieldError, tag_count.prepare, mock)

        # Simulate default=1.
        mock = MockModel()
        default = IntegerField(default=1)

        self.assertEqual(default.prepare(mock), 1)

        # Simulate null=True.
        mock = MockModel()
        pk_none = IntegerField(model_attr='pk', null=True)

        self.assertEqual(pk_none.prepare(mock), None)
예제 #5
0
    def test_prepare(self):
        mock = MockModel()
        mock.pk = 1
        mock.user = '******'
        template1 = CharField(use_template=True)

        self.assertRaises(SearchFieldError, template1.prepare, mock)

        template2 = CharField(use_template=True)
        template2.instance_name = 'template_x'
        self.assertRaises(TemplateDoesNotExist, template2.prepare, mock)

        template3 = CharField(use_template=True)
        template3.instance_name = 'template'
        self.assertEqual(template3.prepare(mock), 'Indexed!\n1')

        template4 = CharField(use_template=True,
                              template_name='search/indexes/foo.txt')
        template4.instance_name = 'template'
        self.assertEqual(template4.prepare(mock), 'FOO!\n')

        template5 = CharField(
            use_template=True,
            template_name=['foo.txt', 'search/indexes/bar.txt'])
        template5.instance_name = 'template'
        self.assertEqual(template5.prepare(mock), 'BAR!\n')
예제 #6
0
    def test_remove_object(self):
        self.site.register(MockModel, FakeSearchIndex)

        mock = MockModel()
        mock.pk = 20

        self.assertEqual(self.site.remove_object(mock), True)
예제 #7
0
 def test_prepare(self):
     mock = MockModel()
     mock.pk = 1
     pk = IntegerField(model_attr='pk')
     
     self.assertEqual(pk.prepare(mock), 1)
     
     # Simulate failed lookups.
     mock_tag = MockTag(name='primary')
     mock = MockModel()
     mock.tag = mock_tag
     tag_count = IntegerField(model_attr='tag__count')
     
     self.assertRaises(SearchFieldError, tag_count.prepare, mock)
     
     # Simulate default=1.
     mock = MockModel()
     default = IntegerField(default=1)
     
     self.assertEqual(default.prepare(mock), 1)
     
     # Simulate null=True.
     mock = MockModel()
     pk_none = IntegerField(model_attr='pk', null=True)
     
     self.assertEqual(pk_none.prepare(mock), None)
예제 #8
0
 def test_remove_object(self):
     self.site.register(MockModel, FakeSearchIndex)
     
     mock = MockModel()
     mock.pk = 20
     
     self.assertEqual(self.site.remove_object(mock), True)
예제 #9
0
    def test_thread_safety(self):
        # This is a regression. ``SearchIndex`` used to write to
        # ``self.prepared_data``, which would leak between threads if things
        # went too fast.
        exceptions = []

        def threaded_prepare(index_queue, index, model):
            try:
                index.queue = index_queue
                prepped = index.prepare(model)
            except Exception as e:
                exceptions.append(e)
                raise

        class ThreadedSearchIndex(GoodMockSearchIndex):
            def prepare_author(self, obj):
                if obj.pk == 20:
                    time.sleep(0.1)
                else:
                    time.sleep(0.5)

                index_queue.put(self.prepared_data['author'])
                return self.prepared_data['author']

        tmi = ThreadedSearchIndex()
        index_queue = queue.Queue()
        mock_1 = MockModel()
        mock_1.pk = 20
        mock_1.author = 'foo'
        mock_1.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)
        mock_2 = MockModel()
        mock_2.pk = 21
        mock_2.author = 'daniel%s' % mock_2.id
        mock_2.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        th1 = Thread(target=threaded_prepare, args=(index_queue, tmi, mock_1))
        th2 = Thread(target=threaded_prepare, args=(index_queue, tmi, mock_2))

        th1.start()
        th2.start()
        th1.join()
        th2.join()

        mock_1_result = index_queue.get()
        mock_2_result = index_queue.get()
        self.assertEqual(mock_1_result, 'foo')
        self.assertEqual(mock_2_result, 'daniel21')
예제 #10
0
    def test_thread_safety(self):
        # This is a regression. ``SearchIndex`` used to write to
        # ``self.prepared_data``, which would leak between threads if things
        # went too fast.
        exceptions = []

        def threaded_prepare(index_queue, index, model):
            try:
                index.queue = index_queue
                prepped = index.prepare(model)
            except Exception as e:
                exceptions.append(e)
                raise

        class ThreadedSearchIndex(GoodMockSearchIndex):
            def prepare_author(self, obj):
                if obj.pk == 20:
                    time.sleep(0.1)
                else:
                    time.sleep(0.5)

                index_queue.put(self.prepared_data['author'])
                return self.prepared_data['author']

        tmi = ThreadedSearchIndex()
        index_queue = queue.Queue()
        mock_1 = MockModel()
        mock_1.pk = 20
        mock_1.author = 'foo'
        mock_1.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)
        mock_2 = MockModel()
        mock_2.pk = 21
        mock_2.author = 'daniel%s' % mock_2.id
        mock_2.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        th1 = Thread(target=threaded_prepare, args=(index_queue, tmi, mock_1))
        th2 = Thread(target=threaded_prepare, args=(index_queue, tmi, mock_2))

        th1.start()
        th2.start()
        th1.join()
        th2.join()

        mock_1_result = index_queue.get()
        mock_2_result = index_queue.get()
        self.assertEqual(mock_1_result, u'foo')
        self.assertEqual(mock_2_result, u'daniel21')
예제 #11
0
    def test_prepare(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.assertEqual(len(self.mi.prepare(mock)), 7)
        self.assertEqual(sorted(self.mi.prepare(mock).keys()), ['author', 'django_ct', 'django_id', 'extra', 'id', 'pub_date', 'text'])
예제 #12
0
 def test_prepare(self):
     mock = MockModel()
     mock.pk = 20
     mock.author = 'daniel%s' % mock.id
     mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)
     
     self.assertEqual(len(self.mi.prepare(mock)), 7)
     self.assertEqual(sorted(self.mi.prepare(mock).keys()), ['author', 'content', 'django_ct', 'django_id', 'extra', 'id', 'pub_date'])
예제 #13
0
 def test_custom_prepare(self):
     mock = MockModel()
     mock.pk = 20
     mock.user = '******' % mock.id
     mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)
     
     self.assertEqual(len(self.cmi.prepare(mock)), 5)
     self.assertEqual(sorted(self.cmi.prepare(mock).keys()), ['author', 'content', 'extra', 'pub_date', 'whee'])
예제 #14
0
 def test_nullable(self):
     mock = MockModel()
     mock.pk = 20
     mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)
     
     prepared_data = self.cnmi.prepare(mock)
     self.assertEqual(len(prepared_data), 1)
     self.assertEqual(sorted(prepared_data.keys()), ['content'])
예제 #15
0
    def test_nullable(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = None
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        prepared_data = self.cnmi.prepare(mock)
        self.assertEqual(len(prepared_data), 4)
        self.assertEqual(sorted(prepared_data.keys()), ["content", "django_ct", "django_id", "id"])
예제 #16
0
 def test_custom_prepare_author(self):
     mock = MockModel()
     mock.pk = 20
     mock.author = 'daniel%s' % mock.id
     mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)
     
     self.assertEqual(len(self.cmi.prepare(mock)), 6)
     self.assertEqual(sorted(self.cmi.prepare(mock).keys()), ['author', 'content', 'extra', 'hello', 'pub_date', 'whee'])
     self.assertEqual(self.cmi.prepared_data['author'], "Hi, I'm daniel20")
예제 #17
0
 def test_update_object(self):
     self.site.register(MockModel, FakeSearchIndex)
     
     mock = MockModel()
     mock.pk = 20
     mock.user = '******' % mock.id
     mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)
     
     self.assertEqual(self.site.update_object(mock), True)
예제 #18
0
 def test_remove_object(self):
     self.msb.docs = {'core.mockmodel.20': 'Indexed!\n20'}
     
     mock = MockModel()
     mock.pk = 20
     
     self.mi.remove_object(mock)
     self.assertEqual(self.msb.docs, {})
     self.msb.clear()
예제 #19
0
 def test_custom_model_attr(self):
     mock = MockModel()
     mock.pk = 20
     mock.author = 'daniel%s' % mock.id
     mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)
     
     self.assertEqual(len(self.cmi.prepare(mock)), 9)
     self.assertEqual(sorted(self.cmi.prepare(mock).keys()), ['author', 'content', 'django_ct', 'django_id', 'extra', 'hello', 'id', 'pub_date', 'whee'])
     self.assertEqual(self.cmi.prepared_data['hello'], u'World!')
예제 #20
0
    def test_update_object(self):
        self.site.register(MockModel, FakeSearchIndex)

        mock = MockModel()
        mock.pk = 20
        mock.user = '******' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.assertEqual(self.site.update_object(mock), True)
예제 #21
0
    def test_remove_object(self):
        self.msb.docs = {'core.mockmodel.20': 'Indexed!\n20'}

        mock = MockModel()
        mock.pk = 20

        self.mi.remove_object(mock)
        self.assertEqual(self.msb.docs, {})
        self.msb.clear()
예제 #22
0
 def test_custom_prepare(self):
     mock = MockModel()
     mock.pk = 20
     mock.author = 'daniel%s' % mock.id
     mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)
     
     self.assertEqual(len(self.cmi.prepare(mock)), 11)
     self.assertEqual(sorted(self.cmi.prepare(mock).keys()), ['author', 'author_exact', 'content', 'django_ct', 'django_id', 'extra', 'hello', 'id', 'pub_date', 'pub_date_exact', 'whee'])
     
     self.assertEqual(len(self.cmi.full_prepare(mock)), 11)
     self.assertEqual(sorted(self.cmi.full_prepare(mock).keys()), ['author', 'author_exact', 'content', 'django_ct', 'django_id', 'extra', 'hello', 'id', 'pub_date', 'pub_date_exact', 'whee'])
예제 #23
0
    def test_custom_prepare(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.assertEqual(len(self.cmi.prepare(mock)), 11)
        self.assertEqual(sorted(self.cmi.prepare(mock).keys()), ['author', 'author_exact', 'django_ct', 'django_id', 'extra', 'hello', 'id', 'pub_date', 'pub_date_exact', 'text', 'whee'])

        self.assertEqual(len(self.cmi.full_prepare(mock)), 11)
        self.assertEqual(sorted(self.cmi.full_prepare(mock).keys()), ['author', 'author_exact', 'django_ct', 'django_id', 'extra', 'hello', 'id', 'pub_date', 'pub_date_exact', 'text', 'whee'])
예제 #24
0
 def test_custom_index_fieldname(self):
     mock = MockModel()
     mock.pk = 20
     mock.author = 'daniel%s' % mock.id
     mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)
     
     cofnmi = GoodOverriddenFieldNameMockSearchIndex(MockModel, backend=self.msb)
     self.assertEqual(len(cofnmi.prepare(mock)), 6)
     self.assertEqual(sorted(cofnmi.prepare(mock).keys()), ['django_ct', 'django_id', 'hello', 'id', 'more_content', 'name_s'])
     self.assertEqual(cofnmi.prepared_data['name_s'], u'daniel20')
     self.assertEqual(cofnmi.get_content_field(), 'more_content')
예제 #25
0
    def test_prepare(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = "daniel%s" % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.assertEqual(len(self.mi.prepare(mock)), 7)
        self.assertEqual(
            sorted(self.mi.prepare(mock).keys()),
            ["author", "content", "django_ct", "django_id", "extra", "id", "pub_date"],
        )
예제 #26
0
 def test_update_object(self):
     self.assertEqual(self.msb.docs, {})
     
     mock = MockModel()
     mock.pk = 20
     mock.user = '******' % mock.id
     mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)
     
     self.mi.update_object(mock)
     self.assertEqual(self.msb.docs, {'core.mockmodel.20': {'django_id': u'20', 'django_ct': u'core.mockmodel', 'author': u'daniel20', 'extra': u'Stored!\n20', 'content': u'Indexed!\n20', 'pub_date': datetime.datetime(2009, 1, 31, 4, 19), 'id': 'core.mockmodel.20'}})
     self.msb.clear()
예제 #27
0
    def test_custom_index_fieldname(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        cofnmi = GoodOverriddenFieldNameMockSearchIndex()
        self.assertEqual(len(cofnmi.prepare(mock)), 6)
        self.assertEqual(sorted(cofnmi.prepare(mock).keys()), ['django_ct', 'django_id', 'hello', 'id', 'more_content', 'name_s'])
        self.assertEqual(cofnmi.prepared_data['name_s'], 'daniel20')
        self.assertEqual(cofnmi.get_content_field(), 'more_content')
예제 #28
0
 def test_prepare(self):
     mock = MockModel()
     mock.pk = 1
     pk = IntegerField(model_attr='pk')
     
     self.assertEqual(pk.prepare(mock), 1)
     
     # Simulate failed lookups.
     mock_tag = MockTag(name='primary')
     mock = MockModel()
     mock.tag = mock_tag
     tag_count = IntegerField(model_attr='tag__count')
     
     self.assertEqual(tag_count.prepare(mock), 0)
     
     # Simulate null=True.
     mock = MockModel()
     mock.pk = None
     pk_none = IntegerField(model_attr='pk', null=True)
     
     self.assertEqual(pk_none.prepare(mock), None)
예제 #29
0
    def test_update_object(self):
        self.sb.clear()
        self.assertEqual(self.sb.search('*')['hits'], 0)

        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.mi.update_object(mock)
        self.assertEqual([(res.content_type(), res.pk) for res in self.sb.search('*')['results']], [('core.mockmodel', '20')])
        self.sb.clear()
예제 #30
0
    def test_update_object(self):
        self.sb.clear()
        self.assertEqual(self.sb.search('*')['hits'], 0)

        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.mi.update_object(mock)
        self.assertEqual([(res.content_type(), res.pk) for res in self.sb.search('*')['results']], [(u'core.mockmodel', u'20')])
        self.sb.clear()
예제 #31
0
    def test_proper_field_resolution(self):
        mrofsc = MROFieldsSearchChild()
        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)
        mock.test_a = 'This is A'
        mock.test_b = 'This is B'

        self.assertEqual(len(mrofsc.fields), 1)
        prepped_data = mrofsc.prepare(mock)
        self.assertEqual(len(prepped_data), 4)
        self.assertEqual(prepped_data['text'], 'This is A')
예제 #32
0
    def test_nullable(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = None
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        prepared_data = self.cnmi.prepare(mock)
        self.assertEqual(len(prepared_data), 6)
        self.assertEqual(sorted(prepared_data.keys()), ['author', 'author_exact', 'django_ct', 'django_id', 'id', 'text'])

        prepared_data = self.cnmi.full_prepare(mock)
        self.assertEqual(len(prepared_data), 4)
        self.assertEqual(sorted(prepared_data.keys()), ['django_ct', 'django_id', 'id', 'text'])
예제 #33
0
 def test_nullable(self):
     mock = MockModel()
     mock.pk = 20
     mock.author = None
     mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)
     
     prepared_data = self.cnmi.prepare(mock)
     self.assertEqual(len(prepared_data), 6)
     self.assertEqual(sorted(prepared_data.keys()), ['author', 'author_exact', 'content', 'django_ct', 'django_id', 'id'])
     
     prepared_data = self.cnmi.full_prepare(mock)
     self.assertEqual(len(prepared_data), 4)
     self.assertEqual(sorted(prepared_data.keys()), ['content', 'django_ct', 'django_id', 'id'])
예제 #34
0
    def test_proper_field_resolution(self):
        mrofsc = MROFieldsSearchChild()
        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)
        mock.test_a = 'This is A'
        mock.test_b = 'This is B'

        self.assertEqual(len(mrofsc.fields), 1)
        prepped_data = mrofsc.prepare(mock)
        self.assertEqual(len(prepped_data), 4)
        self.assertEqual(prepped_data['text'], 'This is A')
예제 #35
0
    def test_custom_index_fieldname(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = "daniel%s" % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        cofnmi = GoodOverriddenFieldNameMockSearchIndex(MockModel, backend=self.msb)
        self.assertEqual(len(cofnmi.prepare(mock)), 6)
        self.assertEqual(
            sorted(cofnmi.prepare(mock).keys()), ["django_ct", "django_id", "hello", "id", "more_content", "name_s"]
        )
        self.assertEqual(cofnmi.prepared_data["name_s"], u"daniel20")
        self.assertEqual(cofnmi.get_content_field(), "more_content")
예제 #36
0
    def test_update_object(self):
        self.sb.clear()
        self.assertEqual(self.sb.search("*")["hits"], 0)

        mock = MockModel()
        mock.pk = 20
        mock.author = "daniel%s" % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.mi.update_object(mock)
        self.assertEqual(
            [(res.content_type(), res.pk) for res in self.sb.search("*")["results"]], [(u"core.mockmodel", u"20")]
        )
        self.sb.clear()
예제 #37
0
    def test_custom_facet_fields(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel'
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        prepared_data = self.gfmsi.prepare(mock)
        self.assertEqual(len(prepared_data), 8)
        self.assertEqual(sorted(prepared_data.keys()), ['author', 'author_foo', 'django_ct', 'django_id', 'id', 'pub_date', 'pub_date_exact', 'text'])

        prepared_data = self.gfmsi.full_prepare(mock)
        self.assertEqual(len(prepared_data), 8)
        self.assertEqual(sorted(prepared_data.keys()), ['author', 'author_foo', 'django_ct', 'django_id', 'id', 'pub_date', 'pub_date_exact', 'text'])
        self.assertEqual(prepared_data['author_foo'], "Hi, I'm daniel")
        self.assertEqual(prepared_data['pub_date_exact'], '2010-10-26T01:54:32')
예제 #38
0
 def test_custom_facet_fields(self):
     mock = MockModel()
     mock.pk = 20
     mock.author = 'daniel'
     mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)
     
     prepared_data = self.gfmsi.prepare(mock)
     self.assertEqual(len(prepared_data), 8)
     self.assertEqual(sorted(prepared_data.keys()), ['author', 'author_foo', 'content', 'django_ct', 'django_id', 'id', 'pub_date', 'pub_date_exact'])
     
     prepared_data = self.gfmsi.full_prepare(mock)
     self.assertEqual(len(prepared_data), 8)
     self.assertEqual(sorted(prepared_data.keys()), ['author', 'author_foo', 'content', 'django_ct', 'django_id', 'id', 'pub_date', 'pub_date_exact'])
     self.assertEqual(prepared_data['author_foo'], u"Hi, I'm daniel")
     self.assertEqual(prepared_data['pub_date_exact'], '2010-10-26T01:54:32')
예제 #39
0
 def test_prepare(self):
     mock = MockModel()
     mock.pk = 1
     mock.user = '******'
     template1 = CharField(use_template=True)
     
     self.assertRaises(SearchFieldError, template1.prepare, mock)
     
     template2 = CharField(use_template=True)
     template2.instance_name = 'template_x'
     self.assertRaises(TemplateDoesNotExist, template2.prepare, mock)
     
     template3 = CharField(use_template=True)
     template3.instance_name = 'template'
     self.assertEqual(template3.prepare(mock), u'Indexed!\n1')
예제 #40
0
    def test_custom_prepare(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = "daniel%s" % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.assertEqual(len(self.cmi.prepare(mock)), 9)
        self.assertEqual(
            sorted(self.cmi.prepare(mock).keys()),
            ["author", "content", "django_ct", "django_id", "extra", "hello", "id", "pub_date", "whee"],
        )

        self.assertEqual(len(self.cmi.full_prepare(mock)), 10)
        self.assertEqual(
            sorted(self.cmi.full_prepare(mock).keys()),
            ["author", "author_exact", "content", "django_ct", "django_id", "extra", "hello", "id", "pub_date", "whee"],
        )
예제 #41
0
    def test_custom_facet_fields(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = "daniel"
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        prepared_data = self.gfmsi.prepare(mock)
        self.assertEqual(len(prepared_data), 8)
        self.assertEqual(
            sorted(prepared_data.keys()),
            ["author", "author_foo", "django_ct", "django_id", "id", "pub_date", "pub_date_exact", "text"],
        )

        prepared_data = self.gfmsi.full_prepare(mock)
        self.assertEqual(len(prepared_data), 8)
        self.assertEqual(
            sorted(prepared_data.keys()),
            ["author", "author_foo", "django_ct", "django_id", "id", "pub_date", "pub_date_exact", "text"],
        )
        self.assertEqual(prepared_data["author_foo"], u"Hi, I'm daniel")
        self.assertEqual(prepared_data["pub_date_exact"], "2010-10-26T01:54:32")
예제 #42
0
    def test_update_object(self):
        self.assertEqual(self.msb.docs, {})

        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.mi.update_object(mock)
        self.assertEqual(
            self.msb.docs, {
                'core.mockmodel.20': {
                    'django_id': u'20',
                    'django_ct': u'core.mockmodel',
                    'author': u'daniel20',
                    'extra': u'Stored!\n20',
                    'content': u'Indexed!\n20',
                    'pub_date': datetime.datetime(2009, 1, 31, 4, 19),
                    'id': 'core.mockmodel.20'
                }
            })
        self.msb.clear()
예제 #43
0
    def test_prepare(self):
        mock = MockModel()
        mock.pk = 1
        mock.user = "******"
        template1 = CharField(use_template=True)

        self.assertRaises(SearchFieldError, template1.prepare, mock)

        template2 = CharField(use_template=True)
        template2.instance_name = "template_x"
        self.assertRaises(TemplateDoesNotExist, template2.prepare, mock)

        template3 = CharField(use_template=True)
        template3.instance_name = "template"
        self.assertEqual(template3.prepare(mock), u"Indexed!\n1")

        template4 = CharField(use_template=True, template_name="search/indexes/foo.txt")
        template4.instance_name = "template"
        self.assertEqual(template4.prepare(mock), u"FOO!\n")

        template5 = CharField(use_template=True, template_name=["foo.txt", "search/indexes/bar.txt"])
        template5.instance_name = "template"
        self.assertEqual(template5.prepare(mock), u"BAR!\n")
예제 #44
0
 def test_prepare(self):
     mock = MockModel()
     mock.pk = 1
     mock.user = '******'
     template1 = CharField(use_template=True)
     
     self.assertRaises(SearchFieldError, template1.prepare, mock)
     
     template2 = CharField(use_template=True)
     template2.instance_name = 'template_x'
     self.assertRaises(TemplateDoesNotExist, template2.prepare, mock)
     
     template3 = CharField(use_template=True)
     template3.instance_name = 'template'
     self.assertEqual(template3.prepare(mock), u'Indexed!\n1')
     
     template4 = CharField(use_template=True, template_name='search/indexes/foo.txt')
     template4.instance_name = 'template'
     self.assertEqual(template4.prepare(mock), u'FOO!\n')
     
     template5 = CharField(use_template=True, template_name=['foo.txt', 'search/indexes/bar.txt'])
     template5.instance_name = 'template'
     self.assertEqual(template5.prepare(mock), u'BAR!\n')
예제 #45
0
    def test_update_object(self):
        self.assertEqual(self.msb.docs, {})

        mock = MockModel()
        mock.pk = 20
        mock.author = "daniel%s" % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.mi.update_object(mock)
        self.assertEqual(
            self.msb.docs,
            {
                "core.mockmodel.20": {
                    "django_id": u"20",
                    "django_ct": u"core.mockmodel",
                    "author": u"daniel20",
                    "extra": u"Stored!\n20",
                    "content": u"Indexed!\n20",
                    "pub_date": datetime.datetime(2009, 1, 31, 4, 19),
                    "id": "core.mockmodel.20",
                }
            },
        )
        self.msb.clear()