Package oort :: Package test :: Module test_rdfview_context
[hide private]
[frames] | no frames]

Source Code for Module oort.test.test_rdfview_context

 1  from rdflib import Literal 
 2  from oort.rdfview import QueryContext 
 3   
 4   
 5  from oort.test.test_rdfview import T, testgraph, itemX, Item 
 6  from oort.test import test_rdfview 
 7   
 8   
9 -class TypedItem(Item):
10 RDF_TYPE = T.Item
11 12
13 -class TestQueryContext(object):
14
15 - def test_by_attr(self):
16 context = QueryContext(testgraph, 'en', query_modules=[test_rdfview]) 17 item = context.Item(itemX) 18 self.assert_item_stuff(item)
19
20 - def test_find_all(self):
21 context = QueryContext(testgraph, 'en', queries=[TypedItem]) 22 items = context.TypedItem.find_all() 23 assert itemX in [item.uri for item in items]
24
25 - def test_by_find(self):
26 context = QueryContext(testgraph, 'en', queries=[Item, TypedItem]) 27 item = context.view_for(itemX) 28 assert isinstance(item, TypedItem) 29 self.assert_item_stuff(item)
30
32 context = QueryContext(testgraph, 'en', queries=[Item]) 33 found = context.Item.find_by(name=Literal(u'Item X')) 34 assert list(found)[0].uri == itemX
35
36 - def test_callable_lang(self):
37 def getlang(): 38 return 'en'
39 context = QueryContext(testgraph, getlang, queries=[Item]) 40 item = context.Item(itemX) 41 self.assert_item_stuff(item)
42
43 - def assert_item_stuff(self, item):
44 assert item.uri == itemX, \ 45 "Unexpected uri: %r" % item.uri 46 assert item.title == Literal(u'Example Item', 'en'), \ 47 "Unexpected title: %r" % item.title
48