def test_global_env_valid_non_scoped_envs(self): """ Checks global_env_valid returns false for non account scoped envs. Returns: None Raises: AssertionError if any of the assert checks fail """ # Loop through all environments that are not mgmt or global for env in EFConfig.ENV_ACCOUNT_MAP: if env == "mgmt" or env == "global": continue with self.assertRaises(ValueError) as exception: ef_conf_utils.global_env_valid(env) self.assertIn("Invalid global env", str(exception.exception)) # Hard coded junk values with self.assertRaises(ValueError) as exception: ef_conf_utils.global_env_valid("not_global") self.assertIn("Invalid global env", str(exception.exception)) with self.assertRaises(ValueError) as exception: ef_conf_utils.global_env_valid("not_mgmt") self.assertIn("Invalid global env", str(exception.exception)) with self.assertRaises(ValueError) as exception: ef_conf_utils.global_env_valid("") self.assertIn("Invalid global env", str(exception.exception)) with self.assertRaises(ValueError) as exception: ef_conf_utils.global_env_valid(None) self.assertIn("Invalid global env", str(exception.exception))
def test_global_env_valid(self): """ Checks global_env_valid returns true for account scoped envs. Returns: None Raises: AssertionError if any of the assert checks fail """ if "global" in EFConfig.ENV_ACCOUNT_MAP: self.assertTrue(ef_conf_utils.global_env_valid("global")) if "mgmt" in EFConfig.ENV_ACCOUNT_MAP: self.assertTrue(ef_conf_utils.global_env_valid("mgmt"))
def env(self, value): """ Sets context.env, context.env_short, and context.account_alias if env is valid For envs of the form "global.<account>" and "mgmt.<account_alias>", env is captured as "global" or "mgmt" and account_alias is parsed out of the full env rather than looked up Args: value: the fully-qualified env value Raises: ValueError if env is not valid """ env_valid(value) self._env_full = value if value.find(".") == -1: # plain environment, e.g. prod, staging, proto<n> self._env = value self._account_alias = get_account_alias(value) else: # "<env>.<account_alias>" form, e.g. global.ellationeng or mgmt.ellationeng self._env, self._account_alias = value.split(".") # since we extracted an env, must reconfirm that it's legit global_env_valid(self._env) self._env_short = get_env_short(value)