def test_ipaconf_env(self): ipa_confdir = os.environ.get('IPA_CONFDIR', None) try: with TempHome() as home: defaultconf = home.join('default.conf') with open(defaultconf, 'w') as f: f.write( textwrap.dedent(""" [global] basedn = dc=ipa,dc=test realm = IPA.TEST domain = ipa.test """)) os.environ['IPA_CONFDIR'] = home.path api = create_api(mode='unit_test') api.bootstrap() api.finalize() assert api.env.confdir == home.path assert api.env.conf_default == defaultconf assert api.env.realm == 'IPA.TEST' assert api.env.domain == 'ipa.test' os.environ['IPA_CONFDIR'] = home.join('invalid') api = create_api(mode='unit_test') with pytest.raises(errors.EnvironmentError): api.bootstrap() finally: if ipa_confdir: os.environ['IPA_CONFDIR'] = ipa_confdir else: os.environ.pop('IPA_CONFDIR')
def new(self, in_tree=False): """ Set os.environ['HOME'] to a tempdir. Returns tuple with new Env instance and the TempHome instance. This helper method is used in testing the bootstrap related methods below. """ home = TempHome() o = self.cls() if in_tree: o.in_tree = True return (o, home)