summaryrefslogtreecommitdiff
path: root/tests/test_collection.py
blob: d0a98649b4a6389de3035523856ba8b2d3907386 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import logging
import os.path
import shutil
import unittest

import lesana


class testCollectionLoading(unittest.TestCase):
    def tearDown(self):
        shutil.rmtree(os.path.join(self.collection.basedir, '.lesana'))

    def test_empty(self):
        self.collection = lesana.Collection('tests/data/empty')
        self.assertEqual(self.collection.schema, {})
        self.assertIsNotNone(self.collection.cache)
        self.assertIsNotNone(self.collection.stemmer)

        self.collection.update_cache()

    def test_simple(self):
        self.collection = lesana.Collection('tests/data/simple')
        self.assertIsNotNone(self.collection.schema)
        self.assertEqual(self.collection.schema['name'], "Simple lesana collection")
        self.assertEqual(len(self.collection.schema['fields']), 3)
        self.assertIsNotNone(self.collection.cache)
        self.assertIsNotNone(self.collection.stemmer)

        self.collection.update_cache()

    def test_wrong_language(self):
        # This loads a collection with an invalid value in lang
        with self.assertLogs(level=logging.WARNING) as cm:
            self.collection = lesana.Collection('tests/data/wrong')
        self.assertEqual(len(cm.output), 1)
        self.assertIn("Invalid language", cm.output[0])
        # The collection will default to english, but should still work.
        self.assertIsNotNone(self.collection.schema)
        self.assertIsNotNone(self.collection.cache)
        self.assertIsNotNone(self.collection.stemmer)