Пример #1
0
    def _verify_request_invoked_with_pool(self, **kwargs):
        pool = kwargs.get("pool", None)
        response = mock.Mock(code=200)
        response_body = {
            'access': {
                'token': {'id': '1111111111'}
            }
        }
        self.treq.json_content.return_value = succeed(response_body)
        self.treq.post.return_value = succeed(response)

        d = authenticate_user('http://identity/v2.0', 'user', 'pass',
                              log=self.log, **kwargs)

        self.assertEqual(self.successResultOf(d), response_body)

        self.treq.post.assert_called_once_with(
            'http://identity/v2.0/tokens',
            SameJSON({'auth': {
                'passwordCredentials': {
                    'username': '******',
                    'password': '******'
                }
            }}),
            headers={'accept': ['application/json'],
                     'content-type': ['application/json'],
                     'User-Agent': ['OtterScale/0.0']},
            log=self.log,
            pool=pool)
Пример #2
0
    def test_authenticate_user(self):
        """
        authenticate_user sends the username and password to the tokens
        endpoint.
        """
        response = mock.Mock(code=200)
        response_body = {
            'access': {
                'token': {'id': '1111111111'}
            }
        }
        self.treq.json_content.return_value = succeed(response_body)
        self.treq.post.return_value = succeed(response)

        d = authenticate_user('http://identity/v2.0', 'user', 'pass')

        self.assertEqual(self.successResultOf(d), response_body)

        self.treq.post.assert_called_once_with(
            'http://identity/v2.0/tokens',
            SameJSON({'auth': {
                'passwordCredentials': {
                    'username': '******',
                    'password': '******'
                }
            }}),
            headers={'accept': ['application/json'],
                     'content-type': ['application/json']})
Пример #3
0
    def test_authenticate_user_with_tenant_id(self):
        """
        authenticate_user will include tenant_id in request if given
        """
        response = mock.Mock(code=200)
        response_body = {
            'access': {
                'token': {'id': '1111111111'}
            }
        }
        self.treq.json_content.return_value = succeed(response_body)
        self.treq.post.return_value = succeed(response)

        d = authenticate_user('http://identity/v2.0', 'user', 'pass',
                              tenant_id='1111', log=self.log)

        self.assertEqual(self.successResultOf(d), response_body)

        self.treq.post.assert_called_once_with(
            'http://identity/v2.0/tokens',
            SameJSON({'auth': {
                'passwordCredentials': {
                    'username': '******',
                    'password': '******'
                },
                'tenantId': '1111',
            }}),
            headers={'accept': ['application/json'],
                     'content-type': ['application/json'],
                     'User-Agent': ['OtterScale/0.0']},
            log=self.log,
            pool=None)
Пример #4
0
    def test_authenticate_user(self):
        """
        authenticate_user sends the username and password to the tokens
        endpoint.
        """
        response = mock.Mock(code=200)
        response_body = {'access': {'token': {'id': '1111111111'}}}
        self.treq.json_content.return_value = succeed(response_body)
        self.treq.post.return_value = succeed(response)

        d = authenticate_user('http://identity/v2.0', 'user', 'pass')

        self.assertEqual(self.successResultOf(d), response_body)

        self.treq.post.assert_called_once_with('http://identity/v2.0/tokens',
                                               SameJSON({
                                                   'auth': {
                                                       'passwordCredentials': {
                                                           'username': '******',
                                                           'password': '******'
                                                       }
                                                   }
                                               }),
                                               headers={
                                                   'accept':
                                                   ['application/json'],
                                                   'content-type':
                                                   ['application/json']
                                               })
Пример #5
0
    def _verify_request_invoked_with_pool(self, **kwargs):
        pool = kwargs.get("pool", None)
        response = mock.Mock(code=200)
        response_body = {'access': {'token': {'id': '1111111111'}}}
        self.treq.json_content.return_value = succeed(response_body)
        self.treq.post.return_value = succeed(response)

        d = authenticate_user('http://identity/v2.0',
                              'user',
                              'pass',
                              log=self.log,
                              **kwargs)

        self.assertEqual(self.successResultOf(d), response_body)

        self.treq.post.assert_called_once_with('http://identity/v2.0/tokens',
                                               SameJSON({
                                                   'auth': {
                                                       'passwordCredentials': {
                                                           'username': '******',
                                                           'password': '******'
                                                       }
                                                   }
                                               }),
                                               headers={
                                                   'accept':
                                                   ['application/json'],
                                                   'content-type':
                                                   ['application/json'],
                                                   'User-Agent':
                                                   ['OtterScale/0.0']
                                               },
                                               log=self.log,
                                               pool=pool)
Пример #6
0
    def test_authenticate_user_propagates_error(self):
        """
        authenticate_user propogates API errors.
        """
        response = mock.Mock(code=500)
        self.treq.content.return_value = succeed('error_body')
        self.treq.post.return_value = succeed(response)

        d = authenticate_user('http://identity/v2.0', 'user', 'pass')
        failure = self.failureResultOf(d)

        self.assertTrue(failure.check(RequestError))
        real_failure = failure.value.reason

        self.assertTrue(real_failure.check(APIError))
        self.assertEqual(real_failure.value.code, 500)
        self.assertEqual(real_failure.value.body, 'error_body')
Пример #7
0
    def test_authenticate_user_propagates_error(self):
        """
        authenticate_user propogates API errors.
        """
        response = mock.Mock(code=500)
        self.treq.content.return_value = succeed('error_body')
        self.treq.post.return_value = succeed(response)

        d = authenticate_user('http://identity/v2.0', 'user', 'pass')
        failure = self.failureResultOf(d)

        self.assertTrue(failure.check(RequestError))
        real_failure = failure.value.reason

        self.assertTrue(real_failure.check(APIError))
        self.assertEqual(real_failure.value.code, 500)
        self.assertEqual(real_failure.value.body, 'error_body')
Пример #8
0
    def test_authenticate_user_with_tenant_id(self):
        """
        authenticate_user will include tenant_id in request if given
        """
        response = mock.Mock(code=200)
        response_body = {'access': {'token': {'id': '1111111111'}}}
        self.treq.json_content.return_value = succeed(response_body)
        self.treq.post.return_value = succeed(response)

        d = authenticate_user('http://identity/v2.0',
                              'user',
                              'pass',
                              tenant_id='1111',
                              log=self.log)

        self.assertEqual(self.successResultOf(d), response_body)

        self.treq.post.assert_called_once_with('http://identity/v2.0/tokens',
                                               SameJSON({
                                                   'auth': {
                                                       'passwordCredentials': {
                                                           'username': '******',
                                                           'password': '******'
                                                       },
                                                       'tenantId': '1111',
                                                   }
                                               }),
                                               headers={
                                                   'accept':
                                                   ['application/json'],
                                                   'content-type':
                                                   ['application/json'],
                                                   'User-Agent':
                                                   ['OtterScale/0.0']
                                               },
                                               log=self.log,
                                               pool=None)