Package grassyknoll :: Package tests :: Module test_backends
[hide private]

Source Code for Module grassyknoll.tests.test_backends

 1  import wsgi_intercept.httplib2_intercept 
 2  wsgi_intercept.httplib2_intercept.install() 
 3   
 4  from grassyknoll.lib import Norman 
 5   
 6  from grassyknoll.tests.test_GenericCollection import makeTests 
 7  from grassyknoll.backend.dictionary.DictCollection import DictCollection 
 8  from grassyknoll.backend.litesql.SqliteCollection import SqliteCollection, TableMaker 
 9  from grassyknoll.backend.lucene.LuceneCollection import LuceneCollection, LuceneNorman, SmartFieldNorman 
10  from grassyknoll.frontend.RestCollection import CollectionApplication 
11  from grassyknoll.client.ClientCollection import ClientCollection 
12   
13   
14  norman = LuceneNorman() 
15  norman.size = SmartFieldNorman(store=True) 
16  norman.color = SmartFieldNorman(store=True) 
17   
18  table = TableMaker.Table('main') 
19  table.size = TableMaker.Column(int) 
20  table.color = TableMaker.Column(str) 
21   
22  # below tests are dynamically generated and added to the module 
23  makeTests(DictCollection) 
24  makeTests(SqliteCollection.factory(filename='data', table=table, create=True), 
25            __name__ + '.SqliteCollection') 
26  makeTests(LuceneCollection.factory(index_dir='data', default_storage_norman=norman, create=True),  
27            __name__ + '.LuceneCollection') 
28   
29  ## ClientCollection tests. This requires some tricksiness, because 
30  ## wsgi_intercept creates a new wsgi app for each *request*. We need create a 
31  ## new underlying DictCollection for each test method instead (ie, in the 
32  ## GenericTest's load_data). 
33   
34  client_underlying_collection=None 
35  create_app=lambda: CollectionApplication(client_underlying_collection, Norman.IdemNorman()) 
36  wsgi_intercept.add_wsgi_intercept('localhost', 8080, create_app) 
37   
38  makeTests(ClientCollection.factory(base_uri="http://localhost:8080/"), 
39            __name__ + '.ClientCollection') 
40   
41 -def client_setup_hook(self):
42 global client_underlying_collection 43 client_underlying_collection=DictCollection()
44 45 TestClientCollection.setup_hook=client_setup_hook 46 TestCreateClientCollection.setup_hook=client_setup_hook 47 TestEmptyClientCollection.setup_hook=client_setup_hook 48