def test_get_aws_creds_fail(self): response_mock = mock.MagicMock() response_mock.ok = False response_mock.status_code = 404 response_mock.test = 'Narp' with mock.patch('fleece.cli.run.run.requests.post', return_value=response_mock): with self.assertRaises(SystemExit) as exc: run.get_aws_creds(self.account, '123456', 'foo') self.assertIn( run.FAWS_API_ERROR.format(response_mock.status_code, response_mock.text), str(exc.exception), )
def get_awscreds(self, environment): if environment not in self.awscreds: account = None for env in self.environments: if env['name'] == environment: account = env['account'] break if account is None: raise ValueError('Environment "{}" is not known, add it to ' 'environments.yml file'.format(environment)) token, tenant = self._get_rax_token() self.awscreds[environment] = run.get_aws_creds( account, tenant, token) return self.awscreds[environment]
def get_awscreds(self, environment): if environment not in self.awscreds: account = None for env in self.environments: if env["name"] == environment: account = env["account"] break if account is None: raise ValueError( f'Environment "{environment}" is not known, add it to environments.yml file' ) token, tenant = self._get_rax_token() self.awscreds[environment] = run.get_aws_creds( account, tenant, token) return self.awscreds[environment]
def test_get_aws_creds(self): response_mock = mock.MagicMock() response_mock.ok = True response_mock.json = mock.MagicMock(return_value=self.aws_credentials) with mock.patch('fleece.cli.run.run.requests.post', return_value=response_mock) as requests_mock: creds = run.get_aws_creds(self.account, '123456', 'foo') requests_mock.assert_called_with( run.FAWS_API_URL.format(self.account), headers={ 'X-Auth-Token': 'foo', 'X-Tenant-Id': '123456', }, json={'credential': { 'duration': '3600' }}, ) self.assertDictEqual(self.aws_credentials['credential'], creds)
def test_get_aws_creds(self): response_mock = mock.MagicMock() response_mock.ok = True response_mock.json = mock.MagicMock(return_value=self.aws_credentials) with mock.patch("fleece.cli.run.run.requests.post", return_value=response_mock) as requests_mock: creds = run.get_aws_creds(self.account, "123456", "foo") requests_mock.assert_called_with( run.FAWS_API_URL.format(self.account), headers={ "X-Auth-Token": "foo", "X-Tenant-Id": "123456" }, json={"credential": { "duration": "3600" }}, ) self.assertDictEqual(self.aws_credentials["credential"], creds)