def deserialize(self, serial): self.hash = serial['hash'] for r_serial in serial['resources'].values(): r_real = Resource() r_real.deserialize(r_serial) self.add_resource(r_real)
def _set_resource(self, path, prop, value, state=None): container = state or self.document try: res = container.get_resource(path) except KeyError: res = Resource(path) container.add_resource(res) res.set_property(prop, value)
def test_on_resource_update(self): exampletxt = Resource("/example.txt", "blerg", type="text/plain") self.doc.add_resource(exampletxt) self.assertOutput("on_resource_update /example.txt add\n") exampletxt.type = "text/html" self.assertOutput("on_resource_update /example.txt type\n") exampletxt.content = "I like turtles." self.assertOutput("on_resource_update /example.txt content\n") exampletxt.comment = "Meaningless drivel" self.assertOutput("on_resource_update /example.txt comment\n") exampletxt.path = "/fridge/turtles.txt" self.assertOutput( "on_resource_update /fridge/turtles.txt path\n" + "/example.txt was moved to /fridge/turtles.txt\n" )