'Checks that recusrive deletion of objects works.'

def testRecursiveDelete(self):

    paths_to_delete = ['aff4:/tmp/dir1/hello1.txt', 'aff4:/tmp/dir1/foo/hello2.txt', 'aff4:/tmp/dir1/foo/bar/hello3.txt']
    safe_paths = ['aff4:/tmp/dir2/hello4.txt']
    for path in (paths_to_delete + safe_paths):
        with aff4.FACTORY.Create(path, aff4.AFF4MemoryStream, token=self.token) as fd:
            fd.Write('hello')
    fd = aff4.FACTORY.Open('aff4:/tmp', token=self.token)
    self.assertListEqual(sorted(fd.ListChildren()), ['aff4:/tmp/dir1', 'aff4:/tmp/dir2'])
    aff4.FACTORY.Delete('aff4:/tmp/dir1', token=self.token)
    for path in paths_to_delete:
        self.assertRaises(IOError, aff4.FACTORY.Open, path, aff4.AFF4MemoryStream, token=self.token)
        fd = aff4.FACTORY.Open(os.path.dirname(path), token=self.token)
        self.assertFalse(list(fd.ListChildren()))
    fd = aff4.FACTORY.Open('aff4:/tmp', token=self.token)
    self.assertListEqual(list(fd.ListChildren()), ['aff4:/tmp/dir2'])
    fd = aff4.FACTORY.Open('aff4:/tmp/dir2', token=self.token)
    self.assertListEqual(list(fd.ListChildren()), ['aff4:/tmp/dir2/hello4.txt'])
