def _assert_config_leads_to_msg(self, config_txt, msg): os.environ["MY_USERNAME"] = "******" os.environ["MY_APIKEY"] = "bar" config = yaml.safe_load(config_txt) try: run.get_account(config, None, "sandwhich") self.fail("Expected SystemExit") except SystemExit as se: self.assertIn(msg, str(se))
def _assert_config_leads_to_msg(self, config_txt, msg): os.environ['MY_USERNAME'] = '******' os.environ['MY_APIKEY'] = 'bar' config = yaml.load(config_txt) try: run.get_account(config, None, 'sandwhich') self.fail("Expected SystemExit") except SystemExit as se: self.assertIn(msg, str(se))
def test_get_account(self): config = yaml.load(self.config) account, role, username, apikey = run.get_account( config, self.environment) self.assertEqual(account, self.account) self.assertIsNone(role) self.assertIsNone(username) self.assertIsNone(apikey)
def test_get_account_with_creds(self): os.environ['MY_USERNAME'] = '******' os.environ['MY_APIKEY'] = 'bar' config = yaml.load('environments:\n' ' - name: {}\n' ' account: "{}"\n' ' rs_username_var: MY_USERNAME\n' ' rs_apikey_var: MY_APIKEY'.format( self.environment, self.account)) account, role, username, apikey = run.get_account( config, self.environment) del os.environ['MY_USERNAME'] del os.environ['MY_APIKEY'] self.assertEqual(account, self.account) self.assertIsNone(role) self.assertEqual(username, 'foo') self.assertEqual(apikey, 'bar')
def test_get_account_with_creds(self): os.environ["MY_USERNAME"] = "******" os.environ["MY_APIKEY"] = "bar" config = yaml.safe_load("environments:\n" " - name: {}\n" ' account: "{}"\n' " rs_username_var: MY_USERNAME\n" " rs_apikey_var: MY_APIKEY".format( self.environment, self.account)) account, role, username, apikey = run.get_account( config, self.environment) del os.environ["MY_USERNAME"] del os.environ["MY_APIKEY"] self.assertEqual(account, self.account) self.assertIsNone(role) self.assertEqual(username, "foo") self.assertEqual(apikey, "bar")
def test_get_account_with_stage_creds_2(self): os.environ['MY_USERNAME'] = '******' os.environ['MY_APIKEY'] = 'bar' config = yaml.load( 'stages:\n' ' /.*/:\n' ' environment: {env_name}\n' 'environments:\n' ' - name: {env_name}\n' ' account: "{account}"\n' ' rs_username_var: MY_USERNAME\n' ' rs_apikey_var: MY_APIKEY'.format(env_name=self.environment, account=self.account)) account, role, username, apikey = run.get_account( config, None, 'made-up-nonsense') del os.environ['MY_USERNAME'] del os.environ['MY_APIKEY'] self.assertEqual(account, self.account) self.assertIsNone(role) self.assertEqual(username, 'foo') self.assertEqual(apikey, 'bar')
def test_get_account_with_stage_creds_2(self): os.environ["MY_USERNAME"] = "******" os.environ["MY_APIKEY"] = "bar" config = yaml.safe_load("stages:\n" " /.*/:\n" " environment: {env_name}\n" "environments:\n" " - name: {env_name}\n" ' account: "{account}"\n' " rs_username_var: MY_USERNAME\n" " rs_apikey_var: MY_APIKEY".format( env_name=self.environment, account=self.account)) account, role, username, apikey = run.get_account( config, None, "made-up-nonsense") del os.environ["MY_USERNAME"] del os.environ["MY_APIKEY"] self.assertEqual(account, self.account) self.assertIsNone(role) self.assertEqual(username, "foo") self.assertEqual(apikey, "bar")
def test_environment_not_found(self): with self.assertRaises(SystemExit) as exc: run.get_account({}, self.environment) self.assertIn(run.ACCT_NOT_FOUND_ERROR.format(self.environment), str(exc.exception))
def test_get_account(self): config = yaml.load(self.config) account, role = run.get_account(config, self.environment) self.assertEqual(account, self.account) self.assertIsNone(role)