ranger/orm/tests/unit/ormcli/test_cli_common.py
stewie925 d5ee52f8a2 implement get list rms region authorization
Update Ranger logic to pass the X-Auth-Token in the headers when
creating or updating a ranger resource (flavors, customers,
images, and groups).

Update rds logic to generate a token before making the delete
region request.

These changes are necessary as user authentication logic has been
implemented for RMS region creation and updates.

Change-Id: I6419dbbe440d915268d6b16ae166ab32731d9af2
2019-07-12 14:47:50 -07:00

45 lines
1.5 KiB
Python

import mock
from orm.orm_client.ormcli import cli_common
from unittest import TestCase
class CmsTests(TestCase):
def respond(self, value, code, headers={}):
response = mock.Mock()
response.json.return_value = value
response.status_code = code
response.headers = headers
return response
@mock.patch.object(cli_common.requests, 'post')
def test_get_token_errors(self, mock_post):
# Bad status code
my_response = mock.MagicMock()
my_response.status_code = 200
mock_post.return_value = my_response
self.assertRaises(cli_common.ConnectionError, cli_common.get_token,
3, mock.MagicMock())
# Post fails
mock_post.side_effect = ValueError('test')
self.assertRaises(cli_common.ConnectionError, cli_common.get_token,
3, mock.MagicMock(),)
@mock.patch.object(cli_common.requests, 'post')
def test_get_token_success(self, mock_post):
args = mock.MagicMock()
args.tenant_name = 'tenant_name'
args.username = 'username'
args.password = 'password'
args.auth_region = 'auth_region'
args.keystone_auth_url = 'url'
# Bad status code
my_response = mock.MagicMock()
my_response.status_code = 201
mock_post.return_value = self.respond(
{"access": {"token": {"id": 989}}}, 201, {"x-subject-token": 989})
self.assertTrue(989, cli_common.get_token(3, args))