diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-08-31 18:13:18 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-08-31 18:13:18 -0700 |
commit | 1d67756be9e768ff9f55e7322c1ab3a6b5cdec34 (patch) | |
tree | 17cf38aa1e590acc30c945ea269617e57415f5af /tests/unittests/helpers.py | |
parent | ec911fd083db63521aa425203fb30dd6fc7302d5 (diff) | |
download | vyos-cloud-init-1d67756be9e768ff9f55e7322c1ab3a6b5cdec34.tar.gz vyos-cloud-init-1d67756be9e768ff9f55e7322c1ab3a6b5cdec34.zip |
1. Add a helper for tests to use to load resource/data files from
2. Add a set of tests+data that ensure the launch index filtering
works as expected in the various modes including raw yaml
and via mime/email message formats.
Diffstat (limited to 'tests/unittests/helpers.py')
-rw-r--r-- | tests/unittests/helpers.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py new file mode 100644 index 00000000..60891191 --- /dev/null +++ b/tests/unittests/helpers.py @@ -0,0 +1,41 @@ +import os + +from mocker import MockerTestCase + +from cloudinit import helpers as ch + + +class ResourceUsingTestCase(MockerTestCase): + def __init__(self, methodName="runTest"): + MockerTestCase.__init__(self, methodName) + self.resource_path = None + + def resourceLocation(self, subname=None): + if self.resource_path is None: + paths = [ + os.path.join('tests', 'data'), + os.path.join('data'), + os.path.join(os.pardir, 'tests', 'data'), + os.path.join(os.pardir, 'data'), + ] + for p in paths: + if os.path.isdir(p): + self.resource_path = p + break + self.assertTrue((self.resource_path and os.path.isdir(self.resource_path)), + msg="Unable to locate test resource data path!") + if not subname: + return self.resource_path + return os.path.join(self.resource_path, subname) + + def readResource(self, name): + where = self.resourceLocation(name) + with open(where, 'r') as fh: + return fh.read() + + def getCloudPaths(self): + cp = ch.Paths({ + 'cloud_dir': self.makeDir(), + 'templates_dir': self.resourceLocation(), + }) + return cp |