def test_shared_structure(): """Test item with properties sharing the same structure.""" with TemporaryDirectory() as temp_dir: file_ap = make_file_ap(temp_dir) properties = [ ("name" , XMLProperty(unicode, "//bar/name")), ("color", XMLProperty(unicode, "//bar/color"))] access_point = XML(file_ap, properties, "stream", "foo") site = Site() site.register("test", access_point) item = site.create("test", {"name": "hulk", "color": "green", "id": 1}) item.save() item = site.open("test", {"id": 1}) eq_(item["stream"].read().decode("utf-8"), "<foo><bar><name>hulk</name><color>green</color></bar></foo>")
def test_filesytem_init(): """Assert that the filesystem access point can be properly initialized.""" # Project root, contains kalamar dir root = os.path.dirname(os.path.dirname(kalamar.__file__)) access_point = FileSystem( root, "(.*)/tests/access_point/test_(.*)\.py(.*)", ["package", ("module", FileSystemProperty(unicode)), "extension"]) site = Site() site.register("tests", access_point) eq_(set(access_point.properties.keys()), set(["package", "module", "extension", "content"])) eq_(set((prop.name for prop in access_point.identity_properties)), set(["package", "module", "extension"])) properties = {"package": "kalamar", "module": "filesystem", "extension": ""} filename = __file__[:-1] if __file__.endswith(".pyc") else __file__ eq_(access_point._item_filename(properties), filename) items_file = site.open("tests", properties)["content"] eq_(items_file.name, filename) # This test tests its own presence! assert "RANDOM STRING A6buCMTbAdCV98j00vK455UIAPC" in str(items_file.read())