|
40 | 40 | import sys
|
41 | 41 | from unittest import TestCase, main as testmain
|
42 | 42 |
|
| 43 | +from tests.support.configsupp import FakeConfiguration |
43 | 44 | from tests.support.suppconst import MIG_BASE, TEST_BASE, TEST_FIXTURE_DIR, \
|
44 | 45 | TEST_OUTPUT_DIR
|
45 | 46 |
|
|
48 | 49 | # force defaults to a local environment
|
49 | 50 | os.environ['MIG_ENV'] = 'local'
|
50 | 51 |
|
| 52 | +# expose the configuraed environment as a constant |
| 53 | +MIG_ENV = os.environ['MIG_ENV'] |
| 54 | + |
| 55 | +if MIG_ENV == 'local': |
| 56 | + # force testconfig as the conig file path |
| 57 | + is_py2 = PY2 |
| 58 | + _conf_dir_suffix = "-py%s" % ('2' if is_py2 else '3',) |
| 59 | + _conf_dir = "testconfs%s" % (_conf_dir_suffix,) |
| 60 | + _local_conf = os.path.join( |
| 61 | + MIG_BASE, 'envhelp/output', _conf_dir, 'MiGserver.conf') |
| 62 | + _config_file = os.getenv('MIG_CONF', None) |
| 63 | + if _config_file is None: |
| 64 | + os.environ['MIG_CONF'] = _local_conf |
| 65 | + |
51 | 66 | # All MiG related code will at some point include bits from the mig module
|
52 | 67 | # namespace. Rather than have this knowledge spread through every test file,
|
53 | 68 | # make the sole responsbility of test files to find the support file and
|
@@ -103,6 +118,7 @@ def __init__(self, *args):
|
103 | 118 | super(MigTestCase, self).__init__(*args)
|
104 | 119 | self._cleanup_checks = list()
|
105 | 120 | self._cleanup_paths = set()
|
| 121 | + self._configuration = None |
106 | 122 | self._logger = None
|
107 | 123 | self._skip_logging = False
|
108 | 124 |
|
@@ -153,6 +169,31 @@ def _reset_logging(self, stream):
|
153 | 169 | root_handler = root_logger.handlers[0]
|
154 | 170 | root_handler.stream = stream
|
155 | 171 |
|
| 172 | + # testcase defaults |
| 173 | + |
| 174 | + @staticmethod |
| 175 | + def _make_configuration_instance(configuration_to_make): |
| 176 | + if configuration_to_make == 'fakeconfig': |
| 177 | + return FakeConfiguration() |
| 178 | + elif configuration_to_make == 'testconfig': |
| 179 | + from mig.shared.conf import get_configuration_object |
| 180 | + return get_configuration_object(skip_log=True, disable_auth_log=True) |
| 181 | + else: |
| 182 | + raise AssertionError( |
| 183 | + "MigTestCase: unknown configuration %r" % (configuration_to_make,)) |
| 184 | + |
| 185 | + def _provide_configuration(self): |
| 186 | + return 'fakeconfig' |
| 187 | + |
| 188 | + @property |
| 189 | + def configuration(self): |
| 190 | + """Init a fake configuration if not already done""" |
| 191 | + if self._configuration is None: |
| 192 | + configuration_to_make = self._provide_configuration() |
| 193 | + self._configuration = self._make_configuration_instance( |
| 194 | + configuration_to_make) |
| 195 | + return self._configuration |
| 196 | + |
156 | 197 | @property
|
157 | 198 | def logger(self):
|
158 | 199 | """Init a fake logger if not already done"""
|
@@ -199,6 +240,10 @@ def assertPathExists(self, relative_path):
|
199 | 240 | assert not os.path.isabs(
|
200 | 241 | relative_path), "expected relative path within output folder"
|
201 | 242 | absolute_path = os.path.join(TEST_OUTPUT_DIR, relative_path)
|
| 243 | + return MigTestCase._absolute_path_kind(absolute_path) |
| 244 | + |
| 245 | + @staticmethod |
| 246 | + def _absolute_path_kind(absolute_path): |
202 | 247 | stat_result = os.lstat(absolute_path)
|
203 | 248 | if stat.S_ISLNK(stat_result.st_mode):
|
204 | 249 | return "symlink"
|
|
0 commit comments