1
2 from rdflib import ConjunctiveGraph
3 from oort.sitebase import MultiBaseResourceViewer, AspectBase
4
5
6
9
10
12
13
14 class TestViewer(MultiBaseResourceViewer):
15 resourceBases = {
16 'ont': ("http://example.org/rdfns/ontology#", ''),
17 'ex': ("http://example.org/resources/", "/"),
18 'urn': ("urn:example-org:", ":"),
19 }
20 defaultResource = 'http://example.org/default/resource'
21
22 viewer = TestViewer(ConjunctiveGraph())
23 def test_path(path, expected, samePath=True):
24 resource = viewer.resource_from(path.split('/'))
25 assert resource == expected
26 path2, _success = viewer.resource_to_app_path(resource)
27 assert (path == path2) is samePath
28
29 test_path("ex/path/to/resource", "http://example.org/resources/path/to/resource")
30 test_path("ex/", "http://example.org/resources/")
31 test_path("ont/OneConcept", "http://example.org/rdfns/ontology#OneConcept")
32 test_path("ont/someRelationTo", "http://example.org/rdfns/ontology#someRelationTo")
33 test_path("bad/nothing/to/see/here", "http://example.org/default/resource", False)
34 test_path("bad/", "http://example.org/default/resource", False)
35 test_path("/", "http://example.org/default/resource", False)
36 test_path("", "http://example.org/default/resource", False)
37
38
40 dummy = object()
41 aspect = AspectBase(None)
42 assert aspect == aspect.using(item=dummy)
43 assert aspect.queries['item'] == dummy
44