| Home | Trees | Indices | Help |
|
|---|
|
|
1 """ 2 Test various sample json data with various backends. 3 """ 4 5 import unittest 6 import logging 7 import os 8 import tempfile 9 import datetime 10 from grassyknoll.tests import loadFixtures 11 from grassyknoll.collection import Collection 12 from grassyknoll.backend.dictionary import DictCollection 13 from grassyknoll.backend.litesql import SqliteCollection 14 from grassyknoll.backend.lucene import LuceneCollection 15 from grassyknoll.frontend.RestCollection import CollectionApplication 16 from grassyknoll.client.ClientCollection import ClientCollection 17 from grassyknoll.lib import Norman 18 import nsf 19 20 import wsgi_intercept.httplib2_intercept 21 wsgi_intercept.httplib2_intercept.install() 22 23 directory = os.path.normpath(os.path.dirname(__file__) + '/../../samples') 2426 "Handle generic data loading and deleting." 27 source = None 28 input_norman=Norman.IdemNorman() 29 324934 self.collection=self.make_collection() 35 items = loadFixtures(os.path.join(directory, self.source)) 36 for id, doc in items: 37 try: 38 doc=self.input_norman(doc) 39 except Norman.NormanError: 40 # just drop things that don't norman 41 logging.warn("norman error %s", id, exc_info=True) 42 else: 43 doc = Collection.CollectionDocument(doc, __id__=id) 44 self.collection.create([doc])4551 source = 'shakespeare' 52 556157 fields = '__id__', 'act', 'contents', 'play', 'scene', 'title' 58 ids = self.collection.list() 59 assert len(self.collection) == len(ids) == 754 60 assert sorted(self.collection.retrieve([ids[0]])[0]) == list(fields)63 source = 'shakespeare' 64 storage_norman = LuceneCollection.LuceneNorman() 65 storage_norman.play = LuceneCollection.SmartFieldNorman(store=True, index='tokenized', alltext=True) 66 storage_norman.title = LuceneCollection.SmartFieldNorman(store=True, index='tokenized', alltext=True) 67 storage_norman.contents = LuceneCollection.SmartFieldNorman(index='tokenized', alltext=True) 68 storage_norman.act = LuceneCollection.SmartFieldNorman(index='untokenized') 69 storage_norman.scene = LuceneCollection.SmartFieldNorman(index='untokenized') 7089 9372 return LuceneCollection.LuceneCollection(tempfile.mktemp(prefix='gk_shakespeare_'), 73 self.storage_norman, create=True)7476 fields = '__id__', 'play', 'title' 77 ids = self.collection.list() 78 assert len(self.collection) == len(ids) == 754 79 assert sorted(self.collection.retrieve([ids[0]])[0]) == list(fields) 80 docs = self.collection.searchQuery('play:"romeo and juliet"') 81 assert len(docs) == 26 82 assert all(doc['play'] == 'Romeo and Juliet' for doc in docs) 83 docs = self.collection.searchQuery('play:"romeo and juliet" AND act:1') 84 assert len(docs) == 6 85 scores = [doc['__score__'] for doc in docs] 86 assert all(scores) and scores == sorted(scores, reverse=True) 87 docs = self.collection.searchQuery('play:"romeo and juliet" AND act:1', fields=set(['play'])) 88 assert sorted(docs[0]) == ['__score__', 'play']95 source = 'nsf_ra' 96 storage_norman = nsf.NSFLuceneNorman 97 input_norman=nsf.NSFNorman 98116100 return LuceneCollection.LuceneCollection(tempfile.mktemp(prefix='gk_nsf_lucene_'), 101 self.storage_norman, create=True)102104 ids = self.collection.list() 105 106 # XXX breaks on Client tests, see #67 107 if not isinstance(self, ClientTestBase): 108 assert len(self.collection) == len(ids) == 645 109 110 docs = self.collection.searchQuery(q='"machine learning"') 111 assert [d.id for d in docs] == ['a0305543', 'a0305567', 'a0313480'] 112 assert docs[0]['Title'].startswith('ALGORITHMS') 113 # XXX some more tests would be nice 114 assert len(self.collection.searchQuery(q='model')) == 91 115 assert len(self.collection.searchQuery(q='Date:[20030101 TO 20030601]')) == 562118 source = 'nsf_ra' 119 table = nsf.NSFTable 120 input_norman=nsf.NSFNorman 121139123 return SqliteCollection.SqliteCollection(tempfile.mktemp(prefix='gk_nsf_sqlite_'), 124 self.table, create=True)125127 ids = self.collection.list() 128 129 # XXX breaks on Client tests, see #67 130 if not isinstance(self, ClientTestBase): 131 assert len(self.collection) == len(ids) == 645 132 133 assert len(self.collection.andQuery(Type='Award')) == 645 134 assert len(self.collection.andQuery(Type='Award', Award_Instr='Standard Grant')) == 457 135 assert len(self.collection.andQuery(Date=datetime.date(2003, 3, 26))) == 12 136 results=self.collection.andQuery(NSF_Program=1214, Award_Instr='Standard Grant') 137 assert len(results) == 1 138 assert results[0].id == 'a0300005'147 150 153142 underlying = super(ClientTestBase, self).make_collection() 143 wsgi_intercept.add_wsgi_intercept('localhost', 8080, 144 lambda: CollectionApplication(underlying, nsf.NSFNorman)) 145 146 return ClientCollection(base_uri="http://localhost:8080/")
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0beta1 on Mon Mar 10 05:37:19 2008 | http://epydoc.sourceforge.net |