def test_save(self): database = mock() document = Document('Elena X') when(database).save(document).thenReturn(True) client = Client(database) result = client.save(document) self.assertTrue(result)
def test_search_empty(self): database = mock() when(database).search('').thenReturn([]) client = Client(database) result = client.search('') self.assertEquals(len(result), 0)
#!/usr/bin/env python # -*- coding: utf-8 -*- import codecs from lai import Client, Database, Document client = Client(Database()) filename = '/home/xleo/src/tools12/trunk/scripts/lai/data' with codecs.open(filename, 'r', encoding='latin1') as file: lines = file.readlines() count = 0 for line in lines[1772:]: if line != '': doc = Document(line.strip()) doc.set_keys(line) doc = client.save(doc) if count % 25 == 0: client.commit() count += 1
#!/usr/bin/env python # -*- coding: utf-8 -*- import codecs from lai import Client, Database, Document, Data client = Client(Database()) filename = '/tmp/docs' with codecs.open(filename, 'r', encoding='utf8') as file: lines = file.readlines() count = 0 for line in lines: tokens = line.rsplit('#', 1) content = tokens[0].strip() if len(tokens) == 2: description = tokens[1].strip() else: description = None doc = Document(Data(content, description)) doc = client.save(doc) if count % 50 == 0: client.sync() count += 1 #client.sync()