diff options
author | Lars Wirzenius <liw@gytha> | 2008-03-23 00:15:31 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@gytha> | 2008-03-23 00:15:31 +0200 |
commit | bf615d5dc6fa5984ce3bc55639da7e8517f61b63 (patch) | |
tree | ce29961f506e0bd5f2dc07d337315123b81595cd /obnam | |
parent | be16ca77c187d288c2cfc25bec2d30530f9bdb76 (diff) | |
download | obnam-bf615d5dc6fa5984ce3bc55639da7e8517f61b63.tar.gz |
Add code to load object to block maps in Application.
Diffstat (limited to 'obnam')
-rw-r--r-- | obnam/app.py | 12 | ||||
-rw-r--r-- | obnam/appTests.py | 51 |
2 files changed, 63 insertions, 0 deletions
diff --git a/obnam/app.py b/obnam/app.py index 32826f81..658956c1 100644 --- a/obnam/app.py +++ b/obnam/app.py @@ -74,6 +74,18 @@ class Application: self._host = obnam.obj.HostBlockObject(host_id=id) return self._host + def load_maps(self): + """Load non-content map blocks.""" + ids = self._host.get_map_block_ids() + logging.info("Decoding %d mapping blocks" % len(ids)) + obnam.io.load_maps(self._context, self._context.map, ids) + + def load_content_maps(self): + """Load content map blocks.""" + ids = self._host.get_contmap_block_ids() + logging.info("Decoding %d content mapping blocks" % len(ids)) + obnam.io.load_maps(self._context, self._context.contmap, ids) + def get_exclusion_regexps(self): """Return list of regexp to exclude things from backup.""" diff --git a/obnam/appTests.py b/obnam/appTests.py index f5f34de1..d2ec391e 100644 --- a/obnam/appTests.py +++ b/obnam/appTests.py @@ -341,3 +341,54 @@ class ApplicationBackupTests(unittest.TestCase): def testReturnsGenerationWithTheRightRootObjects(self): gen = self.app.backup([self.abs("pink"), self.abs("pretty")]) self.failUnlessEqual(len(gen.get_dirrefs()), 2) + + +class ApplicationMapTests(unittest.TestCase): + + def setUp(self): + # First, set up two mappings. + + context = obnam.context.Context() + context.cache = obnam.cache.Cache(context.config) + context.be = obnam.backend.init(context.config, context.cache) + + obnam.map.add(context.map, "pink", "pretty") + obnam.map.add(context.contmap, "black", "beautiful") + + map_id = context.be.generate_block_id() + map_block = obnam.map.encode_new_to_block(context.map, map_id) + context.be.upload_block(map_id, map_block, True) + + contmap_id = context.be.generate_block_id() + contmap_block = obnam.map.encode_new_to_block(context.contmap, + contmap_id) + context.be.upload_block(contmap_id, contmap_block, True) + + host_id = context.config.get("backup", "host-id") + host = obnam.obj.HostBlockObject(host_id=host_id, + map_block_ids=[map_id], + contmap_block_ids=[contmap_id]) + obnam.io.upload_host_block(context, host.encode()) + + # Then set up the real context and app. + + self.context = obnam.context.Context() + self.context.cache = obnam.cache.Cache(self.context.config) + self.context.be = obnam.backend.init(self.context.config, + self.context.cache) + self.app = obnam.Application(self.context) + self.app.load_host() + + def testHasNoMapsLoadedByDefault(self): + self.failUnlessEqual(obnam.map.count(self.context.map), 0) + + def testHasNoContentMapsLoadedByDefault(self): + self.failUnlessEqual(obnam.map.count(self.context.contmap), 0) + + def testLoadsMapsWhenRequested(self): + self.app.load_maps() + self.failUnlessEqual(obnam.map.count(self.context.map), 1) + + def testLoadsContentMapsWhenRequested(self): + self.app.load_content_maps() + self.failUnlessEqual(obnam.map.count(self.context.contmap), 1) |