def test_bad_rackspace_token(self): response_mock = mock.MagicMock() response_mock.ok = False response_mock.status_code = 401 response_mock.text = 'Narp' with mock.patch('fleece.cli.run.run.requests.post', return_value=response_mock): with self.assertRaises(SystemExit) as exc: run.get_rackspace_token('foo', 'bar') self.assertIn( run.RS_AUTH_ERROR.format(response_mock.status_code, response_mock.text), str(exc.exception), )
def test_good_rackspace_token(self): response_mock = mock.MagicMock() response_mock.ok = True response_mock.json = lambda: utils.USER_DATA with mock.patch('fleece.cli.run.run.requests.post', return_value=response_mock) as requests_mock: token, tenant = run.get_rackspace_token('foo', 'bar') requests_mock.assert_called_with( 'https://identity.api.rackspacecloud.com/v2.0/tokens', json={ 'auth': { 'RAX-KSKEY:apiKeyCredentials': { 'username': '******', 'apiKey': 'bar' } } }, ) self.assertEqual(utils.TEST_TOKEN, token) self.assertEqual(utils.USER_DATA['access']['token']['tenant']['id'], tenant)
def test_good_rackspace_token(self): response_mock = mock.MagicMock() response_mock.ok = True response_mock.json = lambda: utils.USER_DATA with mock.patch("fleece.cli.run.run.requests.post", return_value=response_mock) as requests_mock: token, tenant = run.get_rackspace_token("foo", "bar") requests_mock.assert_called_with( "https://identity.api.rackspacecloud.com/v2.0/tokens", json={ "auth": { "RAX-KSKEY:apiKeyCredentials": { "username": "******", "apiKey": "bar", } } }, ) self.assertEqual(utils.TEST_TOKEN, token) self.assertEqual(utils.USER_DATA["access"]["token"]["tenant"]["id"], tenant)
def _get_rax_token(self): if self.rax_token is None: self.rax_token, self.tenant = run.get_rackspace_token( self.rs_username, self.rs_api_key) return self.rax_token, self.tenant