summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/data/complex/settings.yaml2
-rw-r--r--tests/test_collection.py2
-rw-r--r--tests/test_types.py93
3 files changed, 96 insertions, 1 deletions
diff --git a/tests/data/complex/settings.yaml b/tests/data/complex/settings.yaml
index 51f313f..e6781b5 100644
--- a/tests/data/complex/settings.yaml
+++ b/tests/data/complex/settings.yaml
@@ -31,3 +31,5 @@ fields:
default: 'default value'
- name: amount
type: integer
+ index: field
+ sortable: true
diff --git a/tests/test_collection.py b/tests/test_collection.py
index bbc35ba..f3e06da 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -272,7 +272,7 @@ class testComplexCollection(unittest.TestCase):
)
self.assertEqual(len(self.collection.settings['fields']), 9)
self.assertIsNotNone(self.collection.stemmer)
- self.assertEqual(len(self.collection.indexed_fields), 6)
+ self.assertEqual(len(self.collection.indexed_fields), 7)
def test_index(self):
self.collection.update_cache()
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()