def testObjectsImplementingITextIndexable(self): o = Mock(SearchableText=u'The quick brown fox jumps over the lazy dog', language='en') d = extract_content(('SearchableText',), o) data = d.getFieldData('SearchableText')[0] self.assertEqual(data['content'], u'The quick brown fox jumps over the lazy dog') self.assertEqual(data['language'],'en') o = Mock(SearchableText=u'The quick brown fox jumps over the lazy dog', language='en') d = extract_content(('searchabletext',), o) self.assertEqual(d, None)
def testObjectImplementingOldZopeTwoAPI(self): o = MockOld() icc = extract_content(('SearchableText',), o) d = icc.getFieldData('SearchableText')[0] self.assertEqual(d['content'], u'The quick brown fox jumps over the lazy dog') self.assertEqual(d['language'], DEFAULT_LANGUAGE) icc = extract_content(('text',), o) d = icc.getFieldData('text')[0] self.assertEqual(d['content'], u'The quick brown fox jumps over the lazy dog') self.assertEqual(d['language'], DEFAULT_LANGUAGE) icc = extract_content(('searchabletext',), o) self.assertEqual(icc, None)
def testObjectsImplementingITextIndexable(self): o = Mock(SearchableText=u'The quick brown fox jumps over the lazy dog', language='en') d = extract_content(('SearchableText', ), o) data = d.getFieldData('SearchableText')[0] self.assertEqual(data['content'], u'The quick brown fox jumps over the lazy dog') self.assertEqual(data['language'], 'en') o = Mock(SearchableText=u'The quick brown fox jumps over the lazy dog', language='en') d = extract_content(('searchabletext', ), o) self.assertEqual(d, None)
def testObjectsImplementingITextIndexableRaw(self): o = MockPDF('data/test.pdf') d = extract_content(('SearchableText',), o, True) data = d.getFieldData('SearchableText')[0] self.assertEqual(data['content'], u'Die Vögel') self.assertEqual(data['language'], 'de') data = d.getFieldData('SearchableText')[1] self.assertEqual(data['content'].strip(), u'Viel Vögel sprangen artig in den Tüpel und über Feld und Wüste') self.assertEqual(data['language'], None) d = extract_content(('searchabletext',), o, True) self.assertEqual(d, None)
def testObjectImplementingOldZopeTwoAPI(self): o = MockOld() icc = extract_content(('SearchableText', ), o) d = icc.getFieldData('SearchableText')[0] self.assertEqual(d['content'], u'The quick brown fox jumps over the lazy dog') self.assertEqual(d['language'], DEFAULT_LANGUAGE) icc = extract_content(('text', ), o) d = icc.getFieldData('text')[0] self.assertEqual(d['content'], u'The quick brown fox jumps over the lazy dog') self.assertEqual(d['language'], DEFAULT_LANGUAGE) icc = extract_content(('searchabletext', ), o) self.assertEqual(icc, None)
def testStupidMockWithAdapter(self): # this test checks if we can extract content from stupid objects not implementing # the TXNG interfaces through adapters provideAdapter(StupidMockAdapter, (IStupidMock,), IIndexableContent) o = StupidMock(SearchableText='god save the queen komma acht komma eins', language='en') d = extract_content(('SearchableText',), o, True) self.assertEqual(d.getFieldData('SearchableText')[0]['content'], 'i am so stupid')
def testObjectsImplementingITextIndexableRaw(self): o = MockPDF('data/test.pdf') d = extract_content(('SearchableText', ), o, True) data = d.getFieldData('SearchableText')[0] self.assertEqual(data['content'], u'Die Vögel') self.assertEqual(data['language'], 'de') data = d.getFieldData('SearchableText')[1] self.assertEqual( data['content'].strip(), u'Viel Vögel sprangen artig in den Tüpel und über Feld und Wüste' ) self.assertEqual(data['language'], None) d = extract_content(('searchabletext', ), o, True) self.assertEqual(d, None)
def testStupidMockWithAdapter(self): # this test checks if we can extract content from stupid objects not implementing # the TXNG interfaces through adapters provideAdapter(StupidMockAdapter, (IStupidMock, ), IIndexableContent) o = StupidMock( SearchableText='god save the queen komma acht komma eins', language='en') d = extract_content(('SearchableText', ), o, True) self.assertEqual( d.getFieldData('SearchableText')[0]['content'], 'i am so stupid')