class TestTalesWithCore(TestCase, WithCheckPathMixin): def setUp(self): self.p = p = CorePackage("tmp", create=True) p.uri = "urn:1234" p.create_media("m1", "http://media.org/m1") p.create_annotation("a1", p.get("m1"), 42, 101, "text/plain") p.create_tag("t1") p.associate_tag(p["a1"], p["t1"]) self.c = AdveneContext(p) self.c.addGlobal("package", p) def tearDown(self): pass def test_misc(self): p = self.p self.check_path("here", p) self.check_path("here/a1", p["a1"]) self.check_path("here/a1/media", p["a1"].media) self.check_path("here/a1/begin", p["a1"].begin) self.check_path("here/a1/my_tags", p["a1"].iter_my_tags(p)) self.check_path("here/a1/my_tags/0", p["a1"].iter_my_tags(p).next()) assert self.c.evaluate("foo|string:") is "" def test_absolute_url(self): p = self.p; c = self.c p1 = CorePackage("tmp1", create=True) p2 = CorePackage("tmp2", create=True) p3 = CorePackage("tmp3", create=True) t = p.create_tag("t") t1 = p1.create_tag("t1") t2 = p2.create_tag("t2") t3 = p3.create_tag("t3") p.create_import("i1", p1) p1.create_import("i2", p2) options = { "packages": {"p": p, "p1": p1}, "aliases": {p: "p", p1: "p1"}, "p": p, "p1": p1, "p2": p2, "p3": p3, } c.addGlobal("options", options) # check on package self.check_path("options/p/absolute_url", "/p") self.check_path("options/p1/absolute_url", "/p1") try: self.check_path("options/p2/absolute_url", "/p/i1:i2/package") # it is either one or the other, we can't predict except AssertionError: self.check_path("options/p2/absolute_url", "/p1/i2/package") self.check_path("options/p/absolute_url/a/b/c", "/p/a/b/c") base = options["package_url"] = "http://localhost:1234/packages" self.check_path("options/p/absolute_url/a/b/c", base+"/p/a/b/c") self.check_path("options/p3/absolute_url|nothing", None) del options["package_url"] # check on element self.check_path("options/p/t/absolute_url", "/p/t") self.check_path("options/p1/t1/absolute_url", "/p1/t1") try: self.check_path("options/p2/t2/absolute_url", "/p/i1:i2:t2") # it is either one or the other, we can't predict except AssertionError: self.check_path("options/p2/t2/absolute_url", "/p1/i2:t2") self.check_path("options/p/t/absolute_url/a/b/c", "/p/t/a/b/c") base = options["package_url"] = "http://localhost:1234/packages" self.check_path("options/p/t/absolute_url/a/b/c", base+"/p/t/a/b/c") self.check_path("options/p3/t3/absolute_url|nothing", None)