def test_auth_with_tenant(self): token_client_v2 = token_client.V3TokenClientJSON('fake_url') post_mock = self.useFixture( mockpatch.PatchObject(token_client_v2, 'post', return_value=self.fake_201_http.request( 'fake_url', body={'access': { 'token': 'fake_token' }}))) resp = token_client_v2.auth(username='******', password='******', project_name='fake_tenant') self.assertIsInstance(resp, rest_client.ResponseBody) req_dict = json.dumps({ 'auth': { 'identity': { 'methods': ['password'], 'password': { 'user': { 'name': 'fake_user', 'password': '******', } } }, 'scope': { 'project': { 'name': 'fake_tenant' } }, } }) post_mock.mock.assert_called_once_with('fake_url/auth/tokens', body=req_dict)
def test_request_with_bytes_body(self): token_client_v3 = token_client.V3TokenClientJSON('fake_url') self.useFixture(mockpatch.PatchObject( token_client_v3, 'raw_request', return_value=( httplib2.Response({"status": "200"}), bytes(b'{"access": {"token": "fake_token"}}')))) resp, body = token_client_v3.request('GET', 'fake_uri') self.assertIsInstance(resp, httplib2.Response) self.assertIsInstance(body, dict)
def _auth_client(self, auth_url): return json_v3id.V3TokenClientJSON( auth_url, disable_ssl_certificate_validation=self.dsvm, ca_certs=self.ca_certs, trace_requests=self.trace_requests)