Esempio n. 1
0
 def test_auth_with_tenant(self):
     token_client_v2 = token_client.TokenClient('fake_url')
     post_mock = self.useFixture(
         mockpatch.PatchObject(token_client_v2,
                               'post',
                               return_value=self.fake_200_http.request(
                                   'fake_url',
                                   body={'access': {
                                       'token': 'fake_token'
                                   }})))
     resp = token_client_v2.auth('fake_user', 'fake_pass', 'fake_tenant')
     self.assertIsInstance(resp, rest_client.ResponseBody)
     req_dict = json.dumps(
         {
             'auth': {
                 'tenantName': 'fake_tenant',
                 'passwordCredentials': {
                     'username': '******',
                     'password': '******',
                 },
             }
         },
         sort_keys=True)
     post_mock.mock.assert_called_once_with('fake_url/tokens',
                                            body=req_dict)
Esempio n. 2
0
    def test_auth_with_tenant(self):
        token_client_v2 = token_client.TokenClient('fake_url')
        response = fake_http.fake_http_response(
            None,
            status=200,
        )
        body = {'access': {'token': 'fake_token'}}

        with mock.patch.object(token_client_v2, 'post') as post_mock:
            post_mock.return_value = response, body
            resp = token_client_v2.auth('fake_user', 'fake_pass',
                                        'fake_tenant')

        self.assertIsInstance(resp, rest_client.ResponseBody)
        req_dict = json.dumps(
            {
                'auth': {
                    'tenantName': 'fake_tenant',
                    'passwordCredentials': {
                        'username': '******',
                        'password': '******',
                    },
                }
            },
            sort_keys=True)
        post_mock.assert_called_once_with('fake_url/tokens', body=req_dict)
Esempio n. 3
0
 def _auth_client(self, auth_url):
     return json_v2id.TokenClient(
         auth_url,
         disable_ssl_certificate_validation=self.dscv,
         ca_certs=self.ca_certs,
         trace_requests=self.trace_requests,
         http_timeout=self.http_timeout)
Esempio n. 4
0
 def test_request_with_bytes_body(self):
     token_client_v2 = token_client.TokenClient('fake_url')
     self.useFixture(
         mockpatch.PatchObject(
             token_client_v2,
             'raw_request',
             return_value=(httplib2.Response({'status': '200'}),
                           bytes(b'{"access": {"token": "fake_token"}}'))))
     resp, body = token_client_v2.request('GET', 'fake_uri')
     self.assertIsInstance(resp, httplib2.Response)
     self.assertIsInstance(body, dict)
Esempio n. 5
0
    def test_request_with_str_body(self):
        token_client_v2 = token_client.TokenClient('fake_url')
        response = fake_http.fake_http_response(
            None, status=200,
        )
        body = str('{"access": {"token": "fake_token"}}')

        with mock.patch.object(token_client_v2, 'raw_request') as mock_raw_r:
            mock_raw_r.return_value = response, body
            resp, body = token_client_v2.request('GET', 'fake_uri')
        self.assertIsInstance(body, dict)