diff options
Diffstat (limited to 'tests/test_types.py')
-rw-r--r-- | tests/test_types.py | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/test_types.py b/tests/test_types.py index 90f6482..6f0c33e 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -2,6 +2,8 @@ import datetime import decimal import unittest +import xapian + from lesana import types @@ -308,5 +310,96 @@ class testTypes(unittest.TestCase): checker.load(d) +class testTypeIndexing(unittest.TestCase): + def setUp(self): + self.doc = xapian.Document() + self.indexer = xapian.TermGenerator() + + def _get_field_def(self, type_name): + return { + 'type': type_name, + 'name': 'test_field', + 'index': 'field', + 'sortable': True, + } + + def test_base(self): + checker = types.LesanaType(self._get_field_def('base'), {}, 16) + + checker.index(self.doc, self.indexer, "some string") + + def test_base_value_index_too_low(self): + checker = types.LesanaType(self._get_field_def('base'), {}, 1) + + checker.index(self.doc, self.indexer, "some string") + + # TODO: check that the string has not been indexed + + def test_string(self): + checker = types.LesanaString(self._get_field_def('string'), {}, 16) + + checker.index(self.doc, self.indexer, "some string") + + def test_text(self): + checker = types.LesanaText(self._get_field_def('text'), {}, 16) + + checker.index(self.doc, self.indexer, "some string") + + def test_int(self): + checker = types.LesanaInt(self._get_field_def('integer'), {}, 16) + + checker.index(self.doc, self.indexer, 1) + + def test_float(self): + checker = types.LesanaFloat(self._get_field_def('float'), {}, 16) + + checker.index(self.doc, self.indexer, 1.5) + + def test_decimal(self): + checker = types.LesanaDecimal(self._get_field_def('decimal'), {}, 16) + + checker.index(self.doc, self.indexer, decimal.Decimal('1.0')) + + def test_timestamp(self): + checker = types.LesanaTimestamp( + self._get_field_def('timestamp'), {}, 16 + ) + + checker.index(self.doc, self.indexer, 1600000000) + + def test_datetime(self): + checker = types.LesanaDatetime(self._get_field_def('datetime'), {}, 16) + + checker.index(self.doc, self.indexer, datetime.datetime.now()) + + def test_date(self): + checker = types.LesanaDate(self._get_field_def('date'), {}, 16) + + checker.index(self.doc, self.indexer, datetime.date.today()) + + def test_boolean(self): + checker = types.LesanaBoolean(self._get_field_def('boolean'), {}, 16) + + checker.index(self.doc, self.indexer, True) + + def test_url(self): + checker = types.LesanaURL(self._get_field_def('url'), {}, 16) + + checker.index(self.doc, self.indexer, "http://example.org") + + def test_yaml(self): + checker = types.LesanaYAML(self._get_field_def('yaml'), {}, 16) + + checker.index(self.doc, self.indexer, {'a': 1, 'b': 2}) + + def test_list(self): + field_def = self._get_field_def('yaml') + # we use one type that is easy to check for correct validation + field_def['list'] = 'int' + checker = types.LesanaList(field_def, {'int': types.LesanaInt}, 16) + + checker.index(self.doc, self.indexer, ["some", "thing"]) + + if __name__ == '__main__': unittest.main() |