コード例 #1
0
    def test_env_valid_invalid_envs(self):
        """
    Checks if env_valid returns ValueError for incorrectly name environments

    Returns:
      None

    Raises:
      AssertionError if any of the assert checks fail
    """
        # Create junk environment values by attaching numbers to non-ephemeral environments and not attaching numbers
        # to ephemeral environments
        for env in EFConfig.ENV_ACCOUNT_MAP:
            if env not in EFConfig.EPHEMERAL_ENVS:
                env += '0'
            with self.assertRaises(ValueError):
                ef_utils.env_valid(env)

        # Hard coded junk values
        with self.assertRaises(ValueError):
            ef_utils.env_valid("invalid_env")
        with self.assertRaises(ValueError):
            ef_utils.env_valid("")
        with self.assertRaises(ValueError):
            ef_utils.env_valid(None)
コード例 #2
0
 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)
コード例 #3
0
    def test_env_valid(self):
        """
    Checks if env_valid returns true for correctly named environments

    Returns:
      None

    Raises:
      AssertionError if any of the assert checks fail
    """
        for env in EFConfig.ENV_ACCOUNT_MAP:
            # Attach a numeric value to environments that are ephemeral
            if env in EFConfig.EPHEMERAL_ENVS:
                env += '0'
            self.assertTrue(ef_utils.env_valid(env))

        # Do tests for global and mgmt envs, which have a special mapping, Example: global.account_alias
        if "global" in EFConfig.ENV_ACCOUNT_MAP:
            for account_alias in EFConfig.ENV_ACCOUNT_MAP.values():
                self.assertTrue(ef_utils.env_valid("global." + account_alias))
        if "mgmt" in EFConfig.ENV_ACCOUNT_MAP:
            for account_alias in EFConfig.ENV_ACCOUNT_MAP.values():
                self.assertTrue(ef_utils.env_valid("mgmt." + account_alias))
コード例 #4
0
ファイル: test_ef_utils.py プロジェクト: Ly4DuJyE6tm5/ef-open
 def test_env_valid(self):
     """Does valid_env resolve correctly"""
     self.assertTrue(env_valid("prod"))
     self.assertTrue(env_valid("staging"))
     self.assertTrue(env_valid("proto0"))
     self.assertTrue(env_valid("global.ellation"))