Import objects replaced by modules
Change-Id: If22b5968983537187f3a4a5515b7a3f173eb168b Closes-Bug: #1641864
This commit is contained in:
parent
43fcf3e8a8
commit
d71101139b
@ -16,8 +16,8 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from cliff.app import App
|
from cliff import app
|
||||||
from cliff.commandmanager import CommandManager
|
from cliff import commandmanager
|
||||||
|
|
||||||
from freezerclient.v1 import actions
|
from freezerclient.v1 import actions
|
||||||
from freezerclient.v1 import backups
|
from freezerclient.v1 import backups
|
||||||
@ -32,7 +32,7 @@ log = logging.getLogger(__name__)
|
|||||||
logging.getLogger('requests').setLevel(logging.WARN)
|
logging.getLogger('requests').setLevel(logging.WARN)
|
||||||
|
|
||||||
|
|
||||||
class FreezerCommandManager(CommandManager):
|
class FreezerCommandManager(commandmanager.CommandManager):
|
||||||
"""All commands available for the shell are registered here"""
|
"""All commands available for the shell are registered here"""
|
||||||
SHELL_COMMANDS = {
|
SHELL_COMMANDS = {
|
||||||
'job-show': jobs.JobShow,
|
'job-show': jobs.JobShow,
|
||||||
@ -70,7 +70,7 @@ class FreezerCommandManager(CommandManager):
|
|||||||
self.add_command(name, command_class)
|
self.add_command(name, command_class)
|
||||||
|
|
||||||
|
|
||||||
class FreezerShell(App):
|
class FreezerShell(app.App):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(FreezerShell, self).__init__(
|
super(FreezerShell, self).__init__(
|
||||||
description='Python Freezer Client',
|
description='Python Freezer Client',
|
||||||
|
@ -13,85 +13,84 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
|
import mock
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from freezerclient.v1 import client
|
from freezerclient.v1 import client
|
||||||
|
|
||||||
from mock import Mock, patch
|
|
||||||
|
|
||||||
|
|
||||||
class TestSupportFunctions(unittest.TestCase):
|
class TestSupportFunctions(unittest.TestCase):
|
||||||
|
|
||||||
def test_guess_auth_version_returns_none(self):
|
def test_guess_auth_version_returns_none(self):
|
||||||
mock_opts = Mock()
|
mock_opts = mock.Mock()
|
||||||
mock_opts.os_identity_api_version = ''
|
mock_opts.os_identity_api_version = ''
|
||||||
mock_opts.os_auth_url = ''
|
mock_opts.os_auth_url = ''
|
||||||
self.assertRaises(Exception, client.guess_auth_version, mock_opts)
|
self.assertRaises(Exception, client.guess_auth_version, mock_opts)
|
||||||
|
|
||||||
def test_guess_auth_version_explicit_3(self):
|
def test_guess_auth_version_explicit_3(self):
|
||||||
mock_opts = Mock()
|
mock_opts = mock.Mock()
|
||||||
mock_opts.os_identity_api_version = '3'
|
mock_opts.os_identity_api_version = '3'
|
||||||
self.assertEqual(client.guess_auth_version(mock_opts), '3')
|
self.assertEqual(client.guess_auth_version(mock_opts), '3')
|
||||||
|
|
||||||
def test_guess_auth_version_explicit_2(self):
|
def test_guess_auth_version_explicit_2(self):
|
||||||
mock_opts = Mock()
|
mock_opts = mock.Mock()
|
||||||
mock_opts.os_identity_api_version = '2.0'
|
mock_opts.os_identity_api_version = '2.0'
|
||||||
self.assertEqual(client.guess_auth_version(mock_opts), '2.0')
|
self.assertEqual(client.guess_auth_version(mock_opts), '2.0')
|
||||||
|
|
||||||
def test_guess_auth_version_implicit_3(self):
|
def test_guess_auth_version_implicit_3(self):
|
||||||
mock_opts = Mock()
|
mock_opts = mock.Mock()
|
||||||
mock_opts.os_auth_url = 'http://whatever/v3'
|
mock_opts.os_auth_url = 'http://whatever/v3'
|
||||||
self.assertEqual(client.guess_auth_version(mock_opts), '3')
|
self.assertEqual(client.guess_auth_version(mock_opts), '3')
|
||||||
|
|
||||||
def test_guess_auth_version_implicit_2(self):
|
def test_guess_auth_version_implicit_2(self):
|
||||||
mock_opts = Mock()
|
mock_opts = mock.Mock()
|
||||||
mock_opts.os_auth_url = 'http://whatever/v2.0'
|
mock_opts.os_auth_url = 'http://whatever/v2.0'
|
||||||
self.assertEqual(client.guess_auth_version(mock_opts), '2.0')
|
self.assertEqual(client.guess_auth_version(mock_opts), '2.0')
|
||||||
|
|
||||||
@patch('freezerclient.v1.client.v3')
|
@mock.patch('freezerclient.v1.client.v3')
|
||||||
@patch('freezerclient.v1.client.v2')
|
@mock.patch('freezerclient.v1.client.v2')
|
||||||
def test_get_auth_plugin_v3_Password(self, mock_v2, mock_v3):
|
def test_get_auth_plugin_v3_Password(self, mock_v2, mock_v3):
|
||||||
mock_opts = Mock()
|
mock_opts = mock.Mock()
|
||||||
mock_opts.os_identity_api_version = '3'
|
mock_opts.os_identity_api_version = '3'
|
||||||
mock_opts.os_user_name = 'myuser'
|
mock_opts.os_user_name = 'myuser'
|
||||||
mock_opts.os_token = ''
|
mock_opts.os_token = ''
|
||||||
client.get_auth_plugin(mock_opts)
|
client.get_auth_plugin(mock_opts)
|
||||||
self.assertTrue(mock_v3.Password.called)
|
self.assertTrue(mock_v3.Password.called)
|
||||||
|
|
||||||
@patch('freezerclient.v1.client.v3')
|
@mock.patch('freezerclient.v1.client.v3')
|
||||||
@patch('freezerclient.v1.client.v2')
|
@mock.patch('freezerclient.v1.client.v2')
|
||||||
def test_get_auth_plugin_v3_Token(self, mock_v2, mock_v3):
|
def test_get_auth_plugin_v3_Token(self, mock_v2, mock_v3):
|
||||||
mock_opts = Mock()
|
mock_opts = mock.Mock()
|
||||||
mock_opts.os_identity_api_version = '3'
|
mock_opts.os_identity_api_version = '3'
|
||||||
mock_opts.os_username = ''
|
mock_opts.os_username = ''
|
||||||
mock_opts.os_token = 'mytoken'
|
mock_opts.os_token = 'mytoken'
|
||||||
client.get_auth_plugin(mock_opts)
|
client.get_auth_plugin(mock_opts)
|
||||||
self.assertTrue(mock_v3.Token.called)
|
self.assertTrue(mock_v3.Token.called)
|
||||||
|
|
||||||
@patch('freezerclient.v1.client.v3')
|
@mock.patch('freezerclient.v1.client.v3')
|
||||||
@patch('freezerclient.v1.client.v2')
|
@mock.patch('freezerclient.v1.client.v2')
|
||||||
def test_get_auth_plugin_v2_Password(self, mock_v2, mock_v3):
|
def test_get_auth_plugin_v2_Password(self, mock_v2, mock_v3):
|
||||||
mock_opts = Mock()
|
mock_opts = mock.Mock()
|
||||||
mock_opts.os_identity_api_version = '2.0'
|
mock_opts.os_identity_api_version = '2.0'
|
||||||
mock_opts.os_user_name = 'myuser'
|
mock_opts.os_user_name = 'myuser'
|
||||||
mock_opts.os_token = ''
|
mock_opts.os_token = ''
|
||||||
client.get_auth_plugin(mock_opts)
|
client.get_auth_plugin(mock_opts)
|
||||||
self.assertTrue(mock_v2.Password.called)
|
self.assertTrue(mock_v2.Password.called)
|
||||||
|
|
||||||
@patch('freezerclient.v1.client.v3')
|
@mock.patch('freezerclient.v1.client.v3')
|
||||||
@patch('freezerclient.v1.client.v2')
|
@mock.patch('freezerclient.v1.client.v2')
|
||||||
def test_get_auth_plugin_v2_Token(self, mock_v2, mock_v3):
|
def test_get_auth_plugin_v2_Token(self, mock_v2, mock_v3):
|
||||||
mock_opts = Mock()
|
mock_opts = mock.Mock()
|
||||||
mock_opts.os_identity_api_version = '2.0'
|
mock_opts.os_identity_api_version = '2.0'
|
||||||
mock_opts.os_username = ''
|
mock_opts.os_username = ''
|
||||||
mock_opts.os_token = 'mytoken'
|
mock_opts.os_token = 'mytoken'
|
||||||
client.get_auth_plugin(mock_opts)
|
client.get_auth_plugin(mock_opts)
|
||||||
self.assertTrue(mock_v2.Token.called)
|
self.assertTrue(mock_v2.Token.called)
|
||||||
|
|
||||||
@patch('freezerclient.v1.client.v3')
|
@mock.patch('freezerclient.v1.client.v3')
|
||||||
@patch('freezerclient.v1.client.v2')
|
@mock.patch('freezerclient.v1.client.v2')
|
||||||
def test_get_auth_plugin_raises_when_no_username_token(self, mock_v2, mock_v3):
|
def test_get_auth_plugin_raises_when_no_username_token(self, mock_v2, mock_v3):
|
||||||
mock_opts = Mock()
|
mock_opts = mock.Mock()
|
||||||
mock_opts.os_identity_api_version = '2.0'
|
mock_opts.os_identity_api_version = '2.0'
|
||||||
mock_opts.os_username = ''
|
mock_opts.os_username = ''
|
||||||
mock_opts.os_token = ''
|
mock_opts.os_token = ''
|
||||||
@ -100,14 +99,14 @@ class TestSupportFunctions(unittest.TestCase):
|
|||||||
|
|
||||||
class TestClientMock(unittest.TestCase):
|
class TestClientMock(unittest.TestCase):
|
||||||
|
|
||||||
@patch('freezerclient.v1.client.ksa_session')
|
@mock.patch('freezerclient.v1.client.ksa_session')
|
||||||
@patch('freezerclient.v1.client.get_auth_plugin')
|
@mock.patch('freezerclient.v1.client.get_auth_plugin')
|
||||||
def test_client_new(self, mock_get_auth_plugin, mock_ksa_session):
|
def test_client_new(self, mock_get_auth_plugin, mock_ksa_session):
|
||||||
c = client.Client(endpoint='blabla', auth_url='blabla')
|
c = client.Client(endpoint='blabla', auth_url='blabla')
|
||||||
self.assertIsInstance(c, client.Client)
|
self.assertIsInstance(c, client.Client)
|
||||||
|
|
||||||
@patch('freezerclient.v1.client.ksa_session')
|
@mock.patch('freezerclient.v1.client.ksa_session')
|
||||||
@patch('freezerclient.v1.client.get_auth_plugin')
|
@mock.patch('freezerclient.v1.client.get_auth_plugin')
|
||||||
def test_client_new_with_kwargs(self, mock_get_auth_plugin, mock_ksa_session):
|
def test_client_new_with_kwargs(self, mock_get_auth_plugin, mock_ksa_session):
|
||||||
kwargs = {'token': 'alpha',
|
kwargs = {'token': 'alpha',
|
||||||
'username': 'bravo',
|
'username': 'bravo',
|
||||||
@ -128,22 +127,22 @@ class TestClientMock(unittest.TestCase):
|
|||||||
self.assertEqual('foxtrot', c.session)
|
self.assertEqual('foxtrot', c.session)
|
||||||
self.assertEqual('golf', c.endpoint)
|
self.assertEqual('golf', c.endpoint)
|
||||||
|
|
||||||
@patch('freezerclient.v1.client.ksa_session')
|
@mock.patch('freezerclient.v1.client.ksa_session')
|
||||||
@patch('freezerclient.v1.client.get_auth_plugin')
|
@mock.patch('freezerclient.v1.client.get_auth_plugin')
|
||||||
def test_get_token(self, mock_get_auth_plugin, mock_ksa_session):
|
def test_get_token(self, mock_get_auth_plugin, mock_ksa_session):
|
||||||
mock_session = Mock()
|
mock_session = mock.Mock()
|
||||||
mock_session.get_token.return_value = 'antaniX2'
|
mock_session.get_token.return_value = 'antaniX2'
|
||||||
c = client.Client(session=mock_session, endpoint='justtest',
|
c = client.Client(session=mock_session, endpoint='justtest',
|
||||||
auth_url='blabla')
|
auth_url='blabla')
|
||||||
self.assertIsInstance(c, client.Client)
|
self.assertIsInstance(c, client.Client)
|
||||||
self.assertEqual(c.auth_token, 'antaniX2')
|
self.assertEqual(c.auth_token, 'antaniX2')
|
||||||
|
|
||||||
@patch('freezerclient.v1.client.socket')
|
@mock.patch('freezerclient.v1.client.socket')
|
||||||
@patch('freezerclient.v1.client.ksa_session')
|
@mock.patch('freezerclient.v1.client.ksa_session')
|
||||||
@patch('freezerclient.v1.client.get_auth_plugin')
|
@mock.patch('freezerclient.v1.client.get_auth_plugin')
|
||||||
def test_get_client_id(self, mock_get_auth_plugin, mock_ksa_session, mock_socket):
|
def test_get_client_id(self, mock_get_auth_plugin, mock_ksa_session, mock_socket):
|
||||||
mock_socket.gethostname.return_value = 'parmenide'
|
mock_socket.gethostname.return_value = 'parmenide'
|
||||||
mock_session = Mock()
|
mock_session = mock.Mock()
|
||||||
mock_session.get_project_id.return_value = 'H2O'
|
mock_session.get_project_id.return_value = 'H2O'
|
||||||
c = client.Client(session=mock_session, endpoint='justtest',
|
c = client.Client(session=mock_session, endpoint='justtest',
|
||||||
auth_url='blabla')
|
auth_url='blabla')
|
||||||
|
@ -13,25 +13,24 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
|
import mock
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.v1.managers import actions
|
from freezerclient.v1.managers import actions
|
||||||
|
|
||||||
from mock import Mock, patch
|
|
||||||
|
|
||||||
|
|
||||||
class TestActionManager(unittest.TestCase):
|
class TestActionManager(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.mock_client = Mock()
|
self.mock_client = mock.Mock()
|
||||||
self.mock_response = Mock()
|
self.mock_response = mock.Mock()
|
||||||
self.mock_client.endpoint = 'http://testendpoint:9999'
|
self.mock_client.endpoint = 'http://testendpoint:9999'
|
||||||
self.mock_client.auth_token = 'testtoken'
|
self.mock_client.auth_token = 'testtoken'
|
||||||
self.mock_client.client_id = 'test_client_id_78900987'
|
self.mock_client.client_id = 'test_client_id_78900987'
|
||||||
self.action_manager = actions.ActionManager(self.mock_client)
|
self.action_manager = actions.ActionManager(self.mock_client)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.actions.requests')
|
@mock.patch('freezerclient.v1.managers.actions.requests')
|
||||||
def test_create(self, mock_requests):
|
def test_create(self, mock_requests):
|
||||||
self.assertEqual('http://testendpoint:9999/v1/actions/', self.action_manager.endpoint)
|
self.assertEqual('http://testendpoint:9999/v1/actions/', self.action_manager.endpoint)
|
||||||
self.assertEqual({'X-Auth-Token': 'testtoken',
|
self.assertEqual({'X-Auth-Token': 'testtoken',
|
||||||
@ -39,7 +38,7 @@ class TestActionManager(unittest.TestCase):
|
|||||||
'Accept': 'application/json'},
|
'Accept': 'application/json'},
|
||||||
self.action_manager.headers)
|
self.action_manager.headers)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.actions.requests')
|
@mock.patch('freezerclient.v1.managers.actions.requests')
|
||||||
def test_create_ok(self, mock_requests):
|
def test_create_ok(self, mock_requests):
|
||||||
self.mock_response.status_code = 201
|
self.mock_response.status_code = 201
|
||||||
self.mock_response.json.return_value = {'action_id': 'qwerqwer'}
|
self.mock_response.json.return_value = {'action_id': 'qwerqwer'}
|
||||||
@ -47,26 +46,26 @@ class TestActionManager(unittest.TestCase):
|
|||||||
retval = self.action_manager.create({'action': 'metadata'})
|
retval = self.action_manager.create({'action': 'metadata'})
|
||||||
self.assertEqual('qwerqwer', retval)
|
self.assertEqual('qwerqwer', retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.actions.requests')
|
@mock.patch('freezerclient.v1.managers.actions.requests')
|
||||||
def test_create_fail_when_api_return_error_code(self, mock_requests):
|
def test_create_fail_when_api_return_error_code(self, mock_requests):
|
||||||
self.mock_response.status_code = 500
|
self.mock_response.status_code = 500
|
||||||
mock_requests.post.return_value = self.mock_response
|
mock_requests.post.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.action_manager.create, {'action': 'metadata'})
|
self.assertRaises(exceptions.ApiClientException, self.action_manager.create, {'action': 'metadata'})
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.actions.requests')
|
@mock.patch('freezerclient.v1.managers.actions.requests')
|
||||||
def test_delete_ok(self, mock_requests):
|
def test_delete_ok(self, mock_requests):
|
||||||
self.mock_response.status_code = 204
|
self.mock_response.status_code = 204
|
||||||
mock_requests.delete.return_value = self.mock_response
|
mock_requests.delete.return_value = self.mock_response
|
||||||
retval = self.action_manager.delete('test_action_id')
|
retval = self.action_manager.delete('test_action_id')
|
||||||
self.assertIsNone(retval)
|
self.assertIsNone(retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.actions.requests')
|
@mock.patch('freezerclient.v1.managers.actions.requests')
|
||||||
def test_delete_fail(self, mock_requests):
|
def test_delete_fail(self, mock_requests):
|
||||||
self.mock_response.status_code = 500
|
self.mock_response.status_code = 500
|
||||||
mock_requests.delete.return_value = self.mock_response
|
mock_requests.delete.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.action_manager.delete, 'test_action_id')
|
self.assertRaises(exceptions.ApiClientException, self.action_manager.delete, 'test_action_id')
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.actions.requests')
|
@mock.patch('freezerclient.v1.managers.actions.requests')
|
||||||
def test_get_ok(self, mock_requests):
|
def test_get_ok(self, mock_requests):
|
||||||
self.mock_response.status_code = 200
|
self.mock_response.status_code = 200
|
||||||
self.mock_response.json.return_value = {'action_id': 'qwerqwer'}
|
self.mock_response.json.return_value = {'action_id': 'qwerqwer'}
|
||||||
@ -74,20 +73,20 @@ class TestActionManager(unittest.TestCase):
|
|||||||
retval = self.action_manager.get('test_action_id')
|
retval = self.action_manager.get('test_action_id')
|
||||||
self.assertEqual({'action_id': 'qwerqwer'}, retval)
|
self.assertEqual({'action_id': 'qwerqwer'}, retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.actions.requests')
|
@mock.patch('freezerclient.v1.managers.actions.requests')
|
||||||
def test_get_fails_on_error_different_from_404(self, mock_requests):
|
def test_get_fails_on_error_different_from_404(self, mock_requests):
|
||||||
self.mock_response.status_code = 500
|
self.mock_response.status_code = 500
|
||||||
mock_requests.get.return_value = self.mock_response
|
mock_requests.get.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.action_manager.get, 'test_action_id')
|
self.assertRaises(exceptions.ApiClientException, self.action_manager.get, 'test_action_id')
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.actions.requests')
|
@mock.patch('freezerclient.v1.managers.actions.requests')
|
||||||
def test_get_none(self, mock_requests):
|
def test_get_none(self, mock_requests):
|
||||||
self.mock_response.status_code = 404
|
self.mock_response.status_code = 404
|
||||||
mock_requests.get.return_value = self.mock_response
|
mock_requests.get.return_value = self.mock_response
|
||||||
retval = self.action_manager.get('test_action_id')
|
retval = self.action_manager.get('test_action_id')
|
||||||
self.assertIsNone(retval)
|
self.assertIsNone(retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.actions.requests')
|
@mock.patch('freezerclient.v1.managers.actions.requests')
|
||||||
def test_list_ok(self, mock_requests):
|
def test_list_ok(self, mock_requests):
|
||||||
self.mock_response.status_code = 200
|
self.mock_response.status_code = 200
|
||||||
action_list = [{'action_id_0': 'bomboloid'}, {'action_id_1': 'asdfasdf'}]
|
action_list = [{'action_id_0': 'bomboloid'}, {'action_id_1': 'asdfasdf'}]
|
||||||
@ -96,7 +95,7 @@ class TestActionManager(unittest.TestCase):
|
|||||||
retval = self.action_manager.list()
|
retval = self.action_manager.list()
|
||||||
self.assertEqual(action_list, retval)
|
self.assertEqual(action_list, retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.actions.requests')
|
@mock.patch('freezerclient.v1.managers.actions.requests')
|
||||||
def test_list_error(self, mock_requests):
|
def test_list_error(self, mock_requests):
|
||||||
self.mock_response.status_code = 404
|
self.mock_response.status_code = 404
|
||||||
action_list = [{'action_id_0': 'bomboloid'}, {'action_id_1': 'asdfasdf'}]
|
action_list = [{'action_id_0': 'bomboloid'}, {'action_id_1': 'asdfasdf'}]
|
||||||
@ -104,7 +103,7 @@ class TestActionManager(unittest.TestCase):
|
|||||||
mock_requests.get.return_value = self.mock_response
|
mock_requests.get.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.action_manager.list)
|
self.assertRaises(exceptions.ApiClientException, self.action_manager.list)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.actions.requests')
|
@mock.patch('freezerclient.v1.managers.actions.requests')
|
||||||
def test_update_ok(self, mock_requests):
|
def test_update_ok(self, mock_requests):
|
||||||
self.mock_response.status_code = 200
|
self.mock_response.status_code = 200
|
||||||
self.mock_response.json.return_value = {
|
self.mock_response.json.return_value = {
|
||||||
@ -116,7 +115,7 @@ class TestActionManager(unittest.TestCase):
|
|||||||
retval = self.action_manager.update('d454beec-1f3c-4d11-aa1a-404116a40502', {'status': 'bamboozled'})
|
retval = self.action_manager.update('d454beec-1f3c-4d11-aa1a-404116a40502', {'status': 'bamboozled'})
|
||||||
self.assertEqual(12, retval)
|
self.assertEqual(12, retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.actions.requests')
|
@mock.patch('freezerclient.v1.managers.actions.requests')
|
||||||
def test_update_raise_MetadataUpdateFailure_when_api_return_error_code(self, mock_requests):
|
def test_update_raise_MetadataUpdateFailure_when_api_return_error_code(self, mock_requests):
|
||||||
self.mock_response.json.return_value = {
|
self.mock_response.json.return_value = {
|
||||||
"patch": {"status": "bamboozled"},
|
"patch": {"status": "bamboozled"},
|
||||||
|
@ -13,23 +13,22 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
|
import mock
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.v1.managers import backups
|
from freezerclient.v1.managers import backups
|
||||||
|
|
||||||
from mock import Mock, patch
|
|
||||||
|
|
||||||
|
|
||||||
class TestBackupManager(unittest.TestCase):
|
class TestBackupManager(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.mock_client = Mock()
|
self.mock_client = mock.Mock()
|
||||||
self.mock_client.endpoint = 'http://testendpoint:9999'
|
self.mock_client.endpoint = 'http://testendpoint:9999'
|
||||||
self.mock_client.auth_token = 'testtoken'
|
self.mock_client.auth_token = 'testtoken'
|
||||||
self.b = backups.BackupsManager(self.mock_client)
|
self.b = backups.BackupsManager(self.mock_client)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.backups.requests')
|
@mock.patch('freezerclient.v1.managers.backups.requests')
|
||||||
def test_create(self, mock_requests):
|
def test_create(self, mock_requests):
|
||||||
self.assertEqual('http://testendpoint:9999/v1/backups/', self.b.endpoint)
|
self.assertEqual('http://testendpoint:9999/v1/backups/', self.b.endpoint)
|
||||||
self.assertEqual({'X-Auth-Token': 'testtoken',
|
self.assertEqual({'X-Auth-Token': 'testtoken',
|
||||||
@ -37,65 +36,65 @@ class TestBackupManager(unittest.TestCase):
|
|||||||
'Accept': 'application/json'},
|
'Accept': 'application/json'},
|
||||||
self.b.headers)
|
self.b.headers)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.backups.requests')
|
@mock.patch('freezerclient.v1.managers.backups.requests')
|
||||||
def test_create_ok(self, mock_requests):
|
def test_create_ok(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 201
|
mock_response.status_code = 201
|
||||||
mock_response.json.return_value = {'backup_id': 'qwerqwer'}
|
mock_response.json.return_value = {'backup_id': 'qwerqwer'}
|
||||||
mock_requests.post.return_value = mock_response
|
mock_requests.post.return_value = mock_response
|
||||||
retval = self.b.create(backup_metadata={'backup': 'metadata'})
|
retval = self.b.create(backup_metadata={'backup': 'metadata'})
|
||||||
self.assertEqual('qwerqwer', retval)
|
self.assertEqual('qwerqwer', retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.backups.requests')
|
@mock.patch('freezerclient.v1.managers.backups.requests')
|
||||||
def test_create_fail_when_api_return_error_code(self, mock_requests):
|
def test_create_fail_when_api_return_error_code(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 500
|
mock_response.status_code = 500
|
||||||
mock_requests.post.return_value = mock_response
|
mock_requests.post.return_value = mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.b.create, {'backup': 'metadata'})
|
self.assertRaises(exceptions.ApiClientException, self.b.create, {'backup': 'metadata'})
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.backups.requests')
|
@mock.patch('freezerclient.v1.managers.backups.requests')
|
||||||
def test_delete_ok(self, mock_requests):
|
def test_delete_ok(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 204
|
mock_response.status_code = 204
|
||||||
mock_requests.delete.return_value = mock_response
|
mock_requests.delete.return_value = mock_response
|
||||||
retval = self.b.delete('test_backup_id')
|
retval = self.b.delete('test_backup_id')
|
||||||
self.assertIsNone(retval)
|
self.assertIsNone(retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.backups.requests')
|
@mock.patch('freezerclient.v1.managers.backups.requests')
|
||||||
def test_delete_fail(self, mock_requests):
|
def test_delete_fail(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 500
|
mock_response.status_code = 500
|
||||||
mock_requests.delete.return_value = mock_response
|
mock_requests.delete.return_value = mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.b.delete, 'test_backup_id')
|
self.assertRaises(exceptions.ApiClientException, self.b.delete, 'test_backup_id')
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.backups.requests')
|
@mock.patch('freezerclient.v1.managers.backups.requests')
|
||||||
def test_get_ok(self, mock_requests):
|
def test_get_ok(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 200
|
mock_response.status_code = 200
|
||||||
mock_response.json.return_value = {'backup_id': 'qwerqwer'}
|
mock_response.json.return_value = {'backup_id': 'qwerqwer'}
|
||||||
mock_requests.get.return_value = mock_response
|
mock_requests.get.return_value = mock_response
|
||||||
retval = self.b.get('test_backup_id')
|
retval = self.b.get('test_backup_id')
|
||||||
self.assertEqual({'backup_id': 'qwerqwer'}, retval)
|
self.assertEqual({'backup_id': 'qwerqwer'}, retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.backups.requests')
|
@mock.patch('freezerclient.v1.managers.backups.requests')
|
||||||
def test_get_none(self, mock_requests):
|
def test_get_none(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 404
|
mock_response.status_code = 404
|
||||||
mock_requests.get.return_value = mock_response
|
mock_requests.get.return_value = mock_response
|
||||||
retval = self.b.get('test_backup_id')
|
retval = self.b.get('test_backup_id')
|
||||||
self.assertIsNone(retval)
|
self.assertIsNone(retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.backups.requests')
|
@mock.patch('freezerclient.v1.managers.backups.requests')
|
||||||
def test_get_error(self, mock_requests):
|
def test_get_error(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 403
|
mock_response.status_code = 403
|
||||||
mock_requests.get.return_value = mock_response
|
mock_requests.get.return_value = mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException,
|
self.assertRaises(exceptions.ApiClientException,
|
||||||
self.b.get, 'test_backup_id')
|
self.b.get, 'test_backup_id')
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.backups.requests')
|
@mock.patch('freezerclient.v1.managers.backups.requests')
|
||||||
def test_list_ok(self, mock_requests):
|
def test_list_ok(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 200
|
mock_response.status_code = 200
|
||||||
backup_list = [{'backup_id_0': 'qwerqwer'}, {'backup_id_1': 'asdfasdf'}]
|
backup_list = [{'backup_id_0': 'qwerqwer'}, {'backup_id_1': 'asdfasdf'}]
|
||||||
mock_response.json.return_value = {'backups': backup_list}
|
mock_response.json.return_value = {'backups': backup_list}
|
||||||
@ -103,9 +102,9 @@ class TestBackupManager(unittest.TestCase):
|
|||||||
retval = self.b.list()
|
retval = self.b.list()
|
||||||
self.assertEqual(backup_list, retval)
|
self.assertEqual(backup_list, retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.backups.requests')
|
@mock.patch('freezerclient.v1.managers.backups.requests')
|
||||||
def test_list_parameters(self, mock_requests):
|
def test_list_parameters(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 200
|
mock_response.status_code = 200
|
||||||
backup_list = [{'backup_id_0': 'qwerqwer'}, {'backup_id_1': 'asdfasdf'}]
|
backup_list = [{'backup_id_0': 'qwerqwer'}, {'backup_id_1': 'asdfasdf'}]
|
||||||
mock_response.json.return_value = {'backups': backup_list}
|
mock_response.json.return_value = {'backups': backup_list}
|
||||||
@ -123,9 +122,9 @@ class TestBackupManager(unittest.TestCase):
|
|||||||
verify=True)
|
verify=True)
|
||||||
self.assertEqual(backup_list, retval)
|
self.assertEqual(backup_list, retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.backups.requests')
|
@mock.patch('freezerclient.v1.managers.backups.requests')
|
||||||
def test_list_error(self, mock_requests):
|
def test_list_error(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 404
|
mock_response.status_code = 404
|
||||||
backup_list = [{'backup_id_0': 'qwerqwer'}, {'backup_id_1': 'asdfasdf'}]
|
backup_list = [{'backup_id_0': 'qwerqwer'}, {'backup_id_1': 'asdfasdf'}]
|
||||||
mock_response.json.return_value = {'backups': backup_list}
|
mock_response.json.return_value = {'backups': backup_list}
|
||||||
|
@ -12,23 +12,22 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import mock
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.v1.client import clients
|
from freezerclient.v1.client import clients
|
||||||
|
|
||||||
from mock import Mock, patch
|
|
||||||
|
|
||||||
|
|
||||||
class TestClientManager(unittest.TestCase):
|
class TestClientManager(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.mock_client = Mock()
|
self.mock_client = mock.Mock()
|
||||||
self.mock_client.endpoint = 'http://testendpoint:9999'
|
self.mock_client.endpoint = 'http://testendpoint:9999'
|
||||||
self.mock_client.auth_token = 'testtoken'
|
self.mock_client.auth_token = 'testtoken'
|
||||||
self.r = clients.ClientManager(self.mock_client)
|
self.r = clients.ClientManager(self.mock_client)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.clients.requests')
|
@mock.patch('freezerclient.v1.managers.clients.requests')
|
||||||
def test_create(self, mock_requests):
|
def test_create(self, mock_requests):
|
||||||
self.assertEqual('http://testendpoint:9999/v1/clients/', self.r.endpoint)
|
self.assertEqual('http://testendpoint:9999/v1/clients/', self.r.endpoint)
|
||||||
self.assertEqual({'X-Auth-Token': 'testtoken',
|
self.assertEqual({'X-Auth-Token': 'testtoken',
|
||||||
@ -36,64 +35,64 @@ class TestClientManager(unittest.TestCase):
|
|||||||
'Accept': 'application/json'},
|
'Accept': 'application/json'},
|
||||||
self.r.headers)
|
self.r.headers)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.clients.requests')
|
@mock.patch('freezerclient.v1.managers.clients.requests')
|
||||||
def test_create_ok(self, mock_requests):
|
def test_create_ok(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 201
|
mock_response.status_code = 201
|
||||||
mock_response.json.return_value = {'client_id': 'qwerqwer'}
|
mock_response.json.return_value = {'client_id': 'qwerqwer'}
|
||||||
mock_requests.post.return_value = mock_response
|
mock_requests.post.return_value = mock_response
|
||||||
retval = self.r.create(client_info={'client': 'metadata'})
|
retval = self.r.create(client_info={'client': 'metadata'})
|
||||||
self.assertEqual('qwerqwer', retval)
|
self.assertEqual('qwerqwer', retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.clients.requests')
|
@mock.patch('freezerclient.v1.managers.clients.requests')
|
||||||
def test_create_fail_when_api_return_error_code(self, mock_requests):
|
def test_create_fail_when_api_return_error_code(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 500
|
mock_response.status_code = 500
|
||||||
mock_requests.post.return_value = mock_response
|
mock_requests.post.return_value = mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.r.create, {'client': 'metadata'})
|
self.assertRaises(exceptions.ApiClientException, self.r.create, {'client': 'metadata'})
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.clients.requests')
|
@mock.patch('freezerclient.v1.managers.clients.requests')
|
||||||
def test_delete_ok(self, mock_requests):
|
def test_delete_ok(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 204
|
mock_response.status_code = 204
|
||||||
mock_requests.delete.return_value = mock_response
|
mock_requests.delete.return_value = mock_response
|
||||||
retval = self.r.delete('test_client_id')
|
retval = self.r.delete('test_client_id')
|
||||||
self.assertIsNone(retval)
|
self.assertIsNone(retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.clients.requests')
|
@mock.patch('freezerclient.v1.managers.clients.requests')
|
||||||
def test_delete_fail(self, mock_requests):
|
def test_delete_fail(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 500
|
mock_response.status_code = 500
|
||||||
mock_requests.delete.return_value = mock_response
|
mock_requests.delete.return_value = mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.r.delete, 'test_client_id')
|
self.assertRaises(exceptions.ApiClientException, self.r.delete, 'test_client_id')
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.clients.requests')
|
@mock.patch('freezerclient.v1.managers.clients.requests')
|
||||||
def test_get_ok(self, mock_requests):
|
def test_get_ok(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 200
|
mock_response.status_code = 200
|
||||||
mock_response.json.return_value = {'client_id': 'qwerqwer'}
|
mock_response.json.return_value = {'client_id': 'qwerqwer'}
|
||||||
mock_requests.get.return_value = mock_response
|
mock_requests.get.return_value = mock_response
|
||||||
retval = self.r.get('test_client_id')
|
retval = self.r.get('test_client_id')
|
||||||
self.assertEqual({'client_id': 'qwerqwer'}, retval)
|
self.assertEqual({'client_id': 'qwerqwer'}, retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.clients.requests')
|
@mock.patch('freezerclient.v1.managers.clients.requests')
|
||||||
def test_get_none(self, mock_requests):
|
def test_get_none(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 404
|
mock_response.status_code = 404
|
||||||
mock_requests.get.return_value = mock_response
|
mock_requests.get.return_value = mock_response
|
||||||
retval = self.r.get('test_client_id')
|
retval = self.r.get('test_client_id')
|
||||||
self.assertIsNone(retval)
|
self.assertIsNone(retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.clients.requests')
|
@mock.patch('freezerclient.v1.managers.clients.requests')
|
||||||
def test_get_raises_ApiClientException_on_error_not_404(self, mock_requests):
|
def test_get_raises_ApiClientException_on_error_not_404(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 500
|
mock_response.status_code = 500
|
||||||
mock_requests.get.return_value = mock_response
|
mock_requests.get.return_value = mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.r.get, 'test_client_id')
|
self.assertRaises(exceptions.ApiClientException, self.r.get, 'test_client_id')
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.clients.requests')
|
@mock.patch('freezerclient.v1.managers.clients.requests')
|
||||||
def test_list_ok(self, mock_requests):
|
def test_list_ok(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 200
|
mock_response.status_code = 200
|
||||||
client_list = [{'client_id_0': 'qwerqwer'}, {'client_id_1': 'asdfasdf'}]
|
client_list = [{'client_id_0': 'qwerqwer'}, {'client_id_1': 'asdfasdf'}]
|
||||||
mock_response.json.return_value = {'clients': client_list}
|
mock_response.json.return_value = {'clients': client_list}
|
||||||
@ -101,9 +100,9 @@ class TestClientManager(unittest.TestCase):
|
|||||||
retval = self.r.list()
|
retval = self.r.list()
|
||||||
self.assertEqual(client_list, retval)
|
self.assertEqual(client_list, retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.clients.requests')
|
@mock.patch('freezerclient.v1.managers.clients.requests')
|
||||||
def test_list_error(self, mock_requests):
|
def test_list_error(self, mock_requests):
|
||||||
mock_response = Mock()
|
mock_response = mock.Mock()
|
||||||
mock_response.status_code = 404
|
mock_response.status_code = 404
|
||||||
client_list = [{'client_id_0': 'qwerqwer'}, {'client_id_1': 'asdfasdf'}]
|
client_list = [{'client_id_0': 'qwerqwer'}, {'client_id_1': 'asdfasdf'}]
|
||||||
mock_response.json.return_value = {'clients': client_list}
|
mock_response.json.return_value = {'clients': client_list}
|
||||||
|
@ -13,19 +13,18 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import mock
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.v1.client import jobs
|
from freezerclient.v1.client import jobs
|
||||||
|
|
||||||
from mock import Mock, patch
|
|
||||||
|
|
||||||
|
|
||||||
class TestJobManager(unittest.TestCase):
|
class TestJobManager(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.mock_client = Mock()
|
self.mock_client = mock.Mock()
|
||||||
self.mock_response = Mock()
|
self.mock_response = mock.Mock()
|
||||||
self.mock_client.endpoint = 'http://testendpoint:9999'
|
self.mock_client.endpoint = 'http://testendpoint:9999'
|
||||||
self.mock_client.auth_token = 'testtoken'
|
self.mock_client.auth_token = 'testtoken'
|
||||||
self.mock_client.client_id = 'test_client_id_78900987'
|
self.mock_client.client_id = 'test_client_id_78900987'
|
||||||
@ -36,7 +35,7 @@ class TestJobManager(unittest.TestCase):
|
|||||||
'Accept': 'application/json'
|
'Accept': 'application/json'
|
||||||
}
|
}
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_create(self, mock_requests):
|
def test_create(self, mock_requests):
|
||||||
self.assertEqual('http://testendpoint:9999/v1/jobs/', self.job_manager.endpoint)
|
self.assertEqual('http://testendpoint:9999/v1/jobs/', self.job_manager.endpoint)
|
||||||
self.assertEqual({'X-Auth-Token': 'testtoken',
|
self.assertEqual({'X-Auth-Token': 'testtoken',
|
||||||
@ -44,7 +43,7 @@ class TestJobManager(unittest.TestCase):
|
|||||||
'Accept': 'application/json'},
|
'Accept': 'application/json'},
|
||||||
self.job_manager.headers)
|
self.job_manager.headers)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_create_ok(self, mock_requests):
|
def test_create_ok(self, mock_requests):
|
||||||
self.mock_response.status_code = 201
|
self.mock_response.status_code = 201
|
||||||
self.mock_response.json.return_value = {'job_id': 'qwerqwer'}
|
self.mock_response.json.return_value = {'job_id': 'qwerqwer'}
|
||||||
@ -52,8 +51,8 @@ class TestJobManager(unittest.TestCase):
|
|||||||
retval = self.job_manager.create({'job': 'metadata'})
|
retval = self.job_manager.create({'job': 'metadata'})
|
||||||
self.assertEqual('qwerqwer', retval)
|
self.assertEqual('qwerqwer', retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.json')
|
@mock.patch('freezerclient.v1.managers.jobs.json')
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_create_adds_client_id_if_not_provided(self, mock_requests, mock_json):
|
def test_create_adds_client_id_if_not_provided(self, mock_requests, mock_json):
|
||||||
self.mock_response.status_code = 201
|
self.mock_response.status_code = 201
|
||||||
self.mock_response.json.return_value = {'job_id': 'qwerqwer'}
|
self.mock_response.json.return_value = {'job_id': 'qwerqwer'}
|
||||||
@ -66,8 +65,8 @@ class TestJobManager(unittest.TestCase):
|
|||||||
'client_id': 'test_client_id_78900987'})
|
'client_id': 'test_client_id_78900987'})
|
||||||
self.assertEqual('qwerqwer', retval)
|
self.assertEqual('qwerqwer', retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.json')
|
@mock.patch('freezerclient.v1.managers.jobs.json')
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_create_leaves_provided_client_id(self, mock_requests, mock_json):
|
def test_create_leaves_provided_client_id(self, mock_requests, mock_json):
|
||||||
self.mock_response.status_code = 201
|
self.mock_response.status_code = 201
|
||||||
self.mock_response.json.return_value = {'job_id': 'qwerqwer'}
|
self.mock_response.json.return_value = {'job_id': 'qwerqwer'}
|
||||||
@ -80,26 +79,26 @@ class TestJobManager(unittest.TestCase):
|
|||||||
'client_id': 'parmenide'})
|
'client_id': 'parmenide'})
|
||||||
self.assertEqual('qwerqwer', retval)
|
self.assertEqual('qwerqwer', retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_create_fail_when_api_return_error_code(self, mock_requests):
|
def test_create_fail_when_api_return_error_code(self, mock_requests):
|
||||||
self.mock_response.status_code = 500
|
self.mock_response.status_code = 500
|
||||||
mock_requests.post.return_value = self.mock_response
|
mock_requests.post.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.job_manager.create, {'job': 'metadata'})
|
self.assertRaises(exceptions.ApiClientException, self.job_manager.create, {'job': 'metadata'})
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_delete_ok(self, mock_requests):
|
def test_delete_ok(self, mock_requests):
|
||||||
self.mock_response.status_code = 204
|
self.mock_response.status_code = 204
|
||||||
mock_requests.delete.return_value = self.mock_response
|
mock_requests.delete.return_value = self.mock_response
|
||||||
retval = self.job_manager.delete('test_job_id')
|
retval = self.job_manager.delete('test_job_id')
|
||||||
self.assertIsNone(retval)
|
self.assertIsNone(retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_delete_fail(self, mock_requests):
|
def test_delete_fail(self, mock_requests):
|
||||||
self.mock_response.status_code = 500
|
self.mock_response.status_code = 500
|
||||||
mock_requests.delete.return_value = self.mock_response
|
mock_requests.delete.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.job_manager.delete, 'test_job_id')
|
self.assertRaises(exceptions.ApiClientException, self.job_manager.delete, 'test_job_id')
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_get_ok(self, mock_requests):
|
def test_get_ok(self, mock_requests):
|
||||||
self.mock_response.status_code = 200
|
self.mock_response.status_code = 200
|
||||||
self.mock_response.json.return_value = {'job_id': 'qwerqwer'}
|
self.mock_response.json.return_value = {'job_id': 'qwerqwer'}
|
||||||
@ -107,20 +106,20 @@ class TestJobManager(unittest.TestCase):
|
|||||||
retval = self.job_manager.get('test_job_id')
|
retval = self.job_manager.get('test_job_id')
|
||||||
self.assertEqual({'job_id': 'qwerqwer'}, retval)
|
self.assertEqual({'job_id': 'qwerqwer'}, retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_get_fails_on_error_different_from_404(self, mock_requests):
|
def test_get_fails_on_error_different_from_404(self, mock_requests):
|
||||||
self.mock_response.status_code = 500
|
self.mock_response.status_code = 500
|
||||||
mock_requests.get.return_value = self.mock_response
|
mock_requests.get.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.job_manager.get, 'test_job_id')
|
self.assertRaises(exceptions.ApiClientException, self.job_manager.get, 'test_job_id')
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_get_none(self, mock_requests):
|
def test_get_none(self, mock_requests):
|
||||||
self.mock_response.status_code = 404
|
self.mock_response.status_code = 404
|
||||||
mock_requests.get.return_value = self.mock_response
|
mock_requests.get.return_value = self.mock_response
|
||||||
retval = self.job_manager.get('test_job_id')
|
retval = self.job_manager.get('test_job_id')
|
||||||
self.assertIsNone(retval)
|
self.assertIsNone(retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_list_ok(self, mock_requests):
|
def test_list_ok(self, mock_requests):
|
||||||
self.mock_response.status_code = 200
|
self.mock_response.status_code = 200
|
||||||
job_list = [{'job_id_0': 'bomboloid'}, {'job_id_1': 'asdfasdf'}]
|
job_list = [{'job_id_0': 'bomboloid'}, {'job_id_1': 'asdfasdf'}]
|
||||||
@ -129,7 +128,7 @@ class TestJobManager(unittest.TestCase):
|
|||||||
retval = self.job_manager.list()
|
retval = self.job_manager.list()
|
||||||
self.assertEqual(job_list, retval)
|
self.assertEqual(job_list, retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_list_error(self, mock_requests):
|
def test_list_error(self, mock_requests):
|
||||||
self.mock_response.status_code = 404
|
self.mock_response.status_code = 404
|
||||||
job_list = [{'job_id_0': 'bomboloid'}, {'job_id_1': 'asdfasdf'}]
|
job_list = [{'job_id_0': 'bomboloid'}, {'job_id_1': 'asdfasdf'}]
|
||||||
@ -137,7 +136,7 @@ class TestJobManager(unittest.TestCase):
|
|||||||
mock_requests.get.return_value = self.mock_response
|
mock_requests.get.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.job_manager.list)
|
self.assertRaises(exceptions.ApiClientException, self.job_manager.list)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_update_ok(self, mock_requests):
|
def test_update_ok(self, mock_requests):
|
||||||
self.mock_response.status_code = 200
|
self.mock_response.status_code = 200
|
||||||
self.mock_response.json.return_value = {
|
self.mock_response.json.return_value = {
|
||||||
@ -149,7 +148,7 @@ class TestJobManager(unittest.TestCase):
|
|||||||
retval = self.job_manager.update('d454beec-1f3c-4d11-aa1a-404116a40502', {'status': 'bamboozled'})
|
retval = self.job_manager.update('d454beec-1f3c-4d11-aa1a-404116a40502', {'status': 'bamboozled'})
|
||||||
self.assertEqual(12, retval)
|
self.assertEqual(12, retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_update_raise_MetadataUpdateFailure_when_api_return_error_code(self, mock_requests):
|
def test_update_raise_MetadataUpdateFailure_when_api_return_error_code(self, mock_requests):
|
||||||
self.mock_response.json.return_value = {
|
self.mock_response.json.return_value = {
|
||||||
"patch": {"status": "bamboozled"},
|
"patch": {"status": "bamboozled"},
|
||||||
@ -163,7 +162,7 @@ class TestJobManager(unittest.TestCase):
|
|||||||
'd454beec-1f3c-4d11-aa1a-404116a40502', {'status': 'bamboozled'})
|
'd454beec-1f3c-4d11-aa1a-404116a40502', {'status': 'bamboozled'})
|
||||||
|
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_start_job_posts_proper_data(self, mock_requests):
|
def test_start_job_posts_proper_data(self, mock_requests):
|
||||||
job_id = 'jobdfsfnqwerty1234'
|
job_id = 'jobdfsfnqwerty1234'
|
||||||
self.mock_response.status_code = 202
|
self.mock_response.status_code = 202
|
||||||
@ -182,7 +181,7 @@ class TestJobManager(unittest.TestCase):
|
|||||||
self.assertEqual(data, json.loads(kwargs['data']))
|
self.assertEqual(data, json.loads(kwargs['data']))
|
||||||
self.assertEqual(self.headers, kwargs['headers'])
|
self.assertEqual(self.headers, kwargs['headers'])
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_start_job_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
def test_start_job_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
||||||
job_id = 'jobdfsfnqwerty1234'
|
job_id = 'jobdfsfnqwerty1234'
|
||||||
self.mock_response.status_code = 500
|
self.mock_response.status_code = 500
|
||||||
@ -190,7 +189,7 @@ class TestJobManager(unittest.TestCase):
|
|||||||
mock_requests.post.return_value = self.mock_response
|
mock_requests.post.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.job_manager.start_job, job_id)
|
self.assertRaises(exceptions.ApiClientException, self.job_manager.start_job, job_id)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_stop_job_posts_proper_data(self, mock_requests):
|
def test_stop_job_posts_proper_data(self, mock_requests):
|
||||||
job_id = 'jobdfsfnqwerty1234'
|
job_id = 'jobdfsfnqwerty1234'
|
||||||
self.mock_response.status_code = 202
|
self.mock_response.status_code = 202
|
||||||
@ -209,7 +208,7 @@ class TestJobManager(unittest.TestCase):
|
|||||||
self.assertEqual(data, json.loads(kwargs['data']))
|
self.assertEqual(data, json.loads(kwargs['data']))
|
||||||
self.assertEqual(self.headers, kwargs['headers'])
|
self.assertEqual(self.headers, kwargs['headers'])
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_stop_job_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
def test_stop_job_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
||||||
job_id = 'jobdfsfnqwerty1234'
|
job_id = 'jobdfsfnqwerty1234'
|
||||||
self.mock_response.status_code = 500
|
self.mock_response.status_code = 500
|
||||||
@ -217,7 +216,7 @@ class TestJobManager(unittest.TestCase):
|
|||||||
mock_requests.post.return_value = self.mock_response
|
mock_requests.post.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.job_manager.start_job, job_id)
|
self.assertRaises(exceptions.ApiClientException, self.job_manager.start_job, job_id)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_abort_job_posts_proper_data(self, mock_requests):
|
def test_abort_job_posts_proper_data(self, mock_requests):
|
||||||
job_id = 'jobdfsfnqwerty1234'
|
job_id = 'jobdfsfnqwerty1234'
|
||||||
self.mock_response.status_code = 202
|
self.mock_response.status_code = 202
|
||||||
@ -236,7 +235,7 @@ class TestJobManager(unittest.TestCase):
|
|||||||
self.assertEqual(data, json.loads(kwargs['data']))
|
self.assertEqual(data, json.loads(kwargs['data']))
|
||||||
self.assertEqual(self.headers, kwargs['headers'])
|
self.assertEqual(self.headers, kwargs['headers'])
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.jobs.requests')
|
@mock.patch('freezerclient.v1.managers.jobs.requests')
|
||||||
def test_abort_job_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
def test_abort_job_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
||||||
job_id = 'jobdfsfnqwerty1234'
|
job_id = 'jobdfsfnqwerty1234'
|
||||||
self.mock_response.status_code = 500
|
self.mock_response.status_code = 500
|
||||||
|
@ -13,19 +13,18 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import mock
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.v1.client import sessions
|
from freezerclient.v1.client import sessions
|
||||||
|
|
||||||
from mock import Mock, patch
|
|
||||||
|
|
||||||
|
|
||||||
class TestSessionManager(unittest.TestCase):
|
class TestSessionManager(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.mock_client = Mock()
|
self.mock_client = mock.Mock()
|
||||||
self.mock_response = Mock()
|
self.mock_response = mock.Mock()
|
||||||
self.mock_client.endpoint = 'http://testendpoint:9999'
|
self.mock_client.endpoint = 'http://testendpoint:9999'
|
||||||
self.mock_client.auth_token = 'testtoken'
|
self.mock_client.auth_token = 'testtoken'
|
||||||
self.mock_client.client_id = 'test_client_id_78900987'
|
self.mock_client.client_id = 'test_client_id_78900987'
|
||||||
@ -37,12 +36,12 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
'Accept': 'application/json'
|
'Accept': 'application/json'
|
||||||
}
|
}
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_create(self, mock_requests):
|
def test_create(self, mock_requests):
|
||||||
self.assertEqual(self.endpoint, self.session_manager.endpoint)
|
self.assertEqual(self.endpoint, self.session_manager.endpoint)
|
||||||
self.assertEqual(self.headers, self.session_manager.headers)
|
self.assertEqual(self.headers, self.session_manager.headers)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_create_ok(self, mock_requests):
|
def test_create_ok(self, mock_requests):
|
||||||
self.mock_response.status_code = 201
|
self.mock_response.status_code = 201
|
||||||
self.mock_response.json.return_value = {'session_id': 'qwerqwer'}
|
self.mock_response.json.return_value = {'session_id': 'qwerqwer'}
|
||||||
@ -50,26 +49,26 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
retval = self.session_manager.create({'session': 'metadata'})
|
retval = self.session_manager.create({'session': 'metadata'})
|
||||||
self.assertEqual('qwerqwer', retval)
|
self.assertEqual('qwerqwer', retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_create_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
def test_create_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
||||||
self.mock_response.status_code = 500
|
self.mock_response.status_code = 500
|
||||||
mock_requests.post.return_value = self.mock_response
|
mock_requests.post.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.session_manager.create, {'session': 'metadata'})
|
self.assertRaises(exceptions.ApiClientException, self.session_manager.create, {'session': 'metadata'})
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_delete_ok(self, mock_requests):
|
def test_delete_ok(self, mock_requests):
|
||||||
self.mock_response.status_code = 204
|
self.mock_response.status_code = 204
|
||||||
mock_requests.delete.return_value = self.mock_response
|
mock_requests.delete.return_value = self.mock_response
|
||||||
retval = self.session_manager.delete('test_session_id')
|
retval = self.session_manager.delete('test_session_id')
|
||||||
self.assertIsNone(retval)
|
self.assertIsNone(retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_delete_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
def test_delete_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
||||||
self.mock_response.status_code = 500
|
self.mock_response.status_code = 500
|
||||||
mock_requests.delete.return_value = self.mock_response
|
mock_requests.delete.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.session_manager.delete, 'test_session_id')
|
self.assertRaises(exceptions.ApiClientException, self.session_manager.delete, 'test_session_id')
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_get_ok(self, mock_requests):
|
def test_get_ok(self, mock_requests):
|
||||||
self.mock_response.status_code = 200
|
self.mock_response.status_code = 200
|
||||||
self.mock_response.json.return_value = {'session_id': 'qwerqwer'}
|
self.mock_response.json.return_value = {'session_id': 'qwerqwer'}
|
||||||
@ -77,20 +76,20 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
retval = self.session_manager.get('test_session_id')
|
retval = self.session_manager.get('test_session_id')
|
||||||
self.assertEqual({'session_id': 'qwerqwer'}, retval)
|
self.assertEqual({'session_id': 'qwerqwer'}, retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_get_raise_ApiClientException_when_api_return_error_different_from_404(self, mock_requests):
|
def test_get_raise_ApiClientException_when_api_return_error_different_from_404(self, mock_requests):
|
||||||
self.mock_response.status_code = 500
|
self.mock_response.status_code = 500
|
||||||
mock_requests.get.return_value = self.mock_response
|
mock_requests.get.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.session_manager.get, 'test_session_id')
|
self.assertRaises(exceptions.ApiClientException, self.session_manager.get, 'test_session_id')
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_get_none(self, mock_requests):
|
def test_get_none(self, mock_requests):
|
||||||
self.mock_response.status_code = 404
|
self.mock_response.status_code = 404
|
||||||
mock_requests.get.return_value = self.mock_response
|
mock_requests.get.return_value = self.mock_response
|
||||||
retval = self.session_manager.get('test_session_id')
|
retval = self.session_manager.get('test_session_id')
|
||||||
self.assertIsNone(retval)
|
self.assertIsNone(retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_list_ok(self, mock_requests):
|
def test_list_ok(self, mock_requests):
|
||||||
self.mock_response.status_code = 200
|
self.mock_response.status_code = 200
|
||||||
session_list = [{'session_id_0': 'bomboloid'}, {'session_id_1': 'asdfasdf'}]
|
session_list = [{'session_id_0': 'bomboloid'}, {'session_id_1': 'asdfasdf'}]
|
||||||
@ -99,7 +98,7 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
retval = self.session_manager.list()
|
retval = self.session_manager.list()
|
||||||
self.assertEqual(session_list, retval)
|
self.assertEqual(session_list, retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_list_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
def test_list_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
||||||
self.mock_response.status_code = 404
|
self.mock_response.status_code = 404
|
||||||
session_list = [{'session_id_0': 'bomboloid'}, {'session_id_1': 'asdfasdf'}]
|
session_list = [{'session_id_0': 'bomboloid'}, {'session_id_1': 'asdfasdf'}]
|
||||||
@ -107,7 +106,7 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
mock_requests.get.return_value = self.mock_response
|
mock_requests.get.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.session_manager.list)
|
self.assertRaises(exceptions.ApiClientException, self.session_manager.list)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_update_ok(self, mock_requests):
|
def test_update_ok(self, mock_requests):
|
||||||
self.mock_response.status_code = 200
|
self.mock_response.status_code = 200
|
||||||
self.mock_response.json.return_value = {
|
self.mock_response.json.return_value = {
|
||||||
@ -119,7 +118,7 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
retval = self.session_manager.update('d454beec-1f3c-4d11-aa1a-404116a40502', {'status': 'bamboozled'})
|
retval = self.session_manager.update('d454beec-1f3c-4d11-aa1a-404116a40502', {'status': 'bamboozled'})
|
||||||
self.assertEqual(12, retval)
|
self.assertEqual(12, retval)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_update_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
def test_update_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
||||||
self.mock_response.json.return_value = {
|
self.mock_response.json.return_value = {
|
||||||
"patch": {"status": "bamboozled"},
|
"patch": {"status": "bamboozled"},
|
||||||
@ -132,7 +131,7 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
self.assertRaises(exceptions.ApiClientException, self.session_manager.update,
|
self.assertRaises(exceptions.ApiClientException, self.session_manager.update,
|
||||||
'd454beec-1f3c-4d11-aa1a-404116a40502', {'status': 'bamboozled'})
|
'd454beec-1f3c-4d11-aa1a-404116a40502', {'status': 'bamboozled'})
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_add_job_uses_proper_endpoint(self, mock_requests):
|
def test_add_job_uses_proper_endpoint(self, mock_requests):
|
||||||
session_id, job_id = 'sessionqwerty1234', 'jobqwerty1234'
|
session_id, job_id = 'sessionqwerty1234', 'jobqwerty1234'
|
||||||
self.mock_response.status_code = 204
|
self.mock_response.status_code = 204
|
||||||
@ -144,14 +143,14 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
self.assertIsNone(retval)
|
self.assertIsNone(retval)
|
||||||
mock_requests.put.assert_called_with(endpoint, headers=self.headers, verify=True)
|
mock_requests.put.assert_called_with(endpoint, headers=self.headers, verify=True)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_add_job_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
def test_add_job_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
||||||
session_id, job_id = 'sessionqwerty1234', 'jobqwerty1234'
|
session_id, job_id = 'sessionqwerty1234', 'jobqwerty1234'
|
||||||
self.mock_response.status_code = 500
|
self.mock_response.status_code = 500
|
||||||
mock_requests.put.return_value = self.mock_response
|
mock_requests.put.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.session_manager.add_job, session_id, job_id)
|
self.assertRaises(exceptions.ApiClientException, self.session_manager.add_job, session_id, job_id)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_remove_job_uses_proper_endpoint(self, mock_requests):
|
def test_remove_job_uses_proper_endpoint(self, mock_requests):
|
||||||
session_id, job_id = 'sessionqwerty1234', 'jobqwerty1234'
|
session_id, job_id = 'sessionqwerty1234', 'jobqwerty1234'
|
||||||
self.mock_response.status_code = 204
|
self.mock_response.status_code = 204
|
||||||
@ -163,14 +162,14 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
self.assertIsNone(retval)
|
self.assertIsNone(retval)
|
||||||
mock_requests.delete.assert_called_with(endpoint, headers=self.headers, verify=True)
|
mock_requests.delete.assert_called_with(endpoint, headers=self.headers, verify=True)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_remove_job_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
def test_remove_job_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
||||||
session_id, job_id = 'sessionqwerty1234', 'jobqwerty1234'
|
session_id, job_id = 'sessionqwerty1234', 'jobqwerty1234'
|
||||||
self.mock_response.status_code = 500
|
self.mock_response.status_code = 500
|
||||||
mock_requests.delete.return_value = self.mock_response
|
mock_requests.delete.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.session_manager.remove_job, session_id, job_id)
|
self.assertRaises(exceptions.ApiClientException, self.session_manager.remove_job, session_id, job_id)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_start_session_posts_proper_data(self, mock_requests):
|
def test_start_session_posts_proper_data(self, mock_requests):
|
||||||
session_id, job_id, tag = 'sessionqwerty1234', 'jobqwerty1234', 23
|
session_id, job_id, tag = 'sessionqwerty1234', 'jobqwerty1234', 23
|
||||||
self.mock_response.status_code = 202
|
self.mock_response.status_code = 202
|
||||||
@ -188,7 +187,7 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
self.assertEqual(data, json.loads(kwargs['data']))
|
self.assertEqual(data, json.loads(kwargs['data']))
|
||||||
self.assertEqual(self.headers, kwargs['headers'])
|
self.assertEqual(self.headers, kwargs['headers'])
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_start_session_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
def test_start_session_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
||||||
session_id, job_id, tag = 'sessionqwerty1234', 'jobqwerty1234', 23
|
session_id, job_id, tag = 'sessionqwerty1234', 'jobqwerty1234', 23
|
||||||
self.mock_response.status_code = 500
|
self.mock_response.status_code = 500
|
||||||
@ -197,7 +196,7 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
self.assertRaises(exceptions.ApiClientException, self.session_manager.start_session,
|
self.assertRaises(exceptions.ApiClientException, self.session_manager.start_session,
|
||||||
session_id, job_id, tag)
|
session_id, job_id, tag)
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_end_session_posts_proper_data(self, mock_requests):
|
def test_end_session_posts_proper_data(self, mock_requests):
|
||||||
session_id, job_id, tag = 'sessionqwerty1234', 'jobqwerty1234', 23
|
session_id, job_id, tag = 'sessionqwerty1234', 'jobqwerty1234', 23
|
||||||
self.mock_response.status_code = 202
|
self.mock_response.status_code = 202
|
||||||
@ -215,7 +214,7 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
self.assertEqual(data, json.loads(kwargs['data']))
|
self.assertEqual(data, json.loads(kwargs['data']))
|
||||||
self.assertEqual(self.headers, kwargs['headers'])
|
self.assertEqual(self.headers, kwargs['headers'])
|
||||||
|
|
||||||
@patch('freezerclient.v1.managers.sessions.requests')
|
@mock.patch('freezerclient.v1.managers.sessions.requests')
|
||||||
def test_end_session_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
def test_end_session_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
|
||||||
session_id, job_id, tag = 'sessionqwerty1234', 'jobqwerty1234', 23
|
session_id, job_id, tag = 'sessionqwerty1234', 'jobqwerty1234', 23
|
||||||
self.mock_response.status_code = 500
|
self.mock_response.status_code = 500
|
||||||
|
@ -14,19 +14,18 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from cliff.command import Command
|
from cliff import command
|
||||||
from cliff.lister import Lister
|
from cliff import lister
|
||||||
from cliff.show import ShowOne
|
from cliff import show
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.utils import doc_from_json_file
|
from freezerclient import utils
|
||||||
from freezerclient.utils import prepare_search
|
|
||||||
|
|
||||||
|
|
||||||
logging = logging.getLogger(__name__)
|
logging = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ActionShow(ShowOne):
|
class ActionShow(show.ShowOne):
|
||||||
"""Show a single action """
|
"""Show a single action """
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(ActionShow, self).get_parser(prog_name)
|
parser = super(ActionShow, self).get_parser(prog_name)
|
||||||
@ -63,7 +62,7 @@ class ActionShow(ShowOne):
|
|||||||
return column, data
|
return column, data
|
||||||
|
|
||||||
|
|
||||||
class ActionList(Lister):
|
class ActionList(lister.Lister):
|
||||||
"""List all actions for your user"""
|
"""List all actions for your user"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(ActionList, self).get_parser(prog_name)
|
parser = super(ActionList, self).get_parser(prog_name)
|
||||||
@ -91,7 +90,7 @@ class ActionList(Lister):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
search = prepare_search(parsed_args.search)
|
search = utils.prepare_search(parsed_args.search)
|
||||||
|
|
||||||
actions = self.app.client.actions.list(
|
actions = self.app.client.actions.list(
|
||||||
limit=parsed_args.limit,
|
limit=parsed_args.limit,
|
||||||
@ -111,7 +110,7 @@ class ActionList(Lister):
|
|||||||
) for action in actions))
|
) for action in actions))
|
||||||
|
|
||||||
|
|
||||||
class ActionDelete(Command):
|
class ActionDelete(command.Command):
|
||||||
"""Delete an action from the api"""
|
"""Delete an action from the api"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(ActionDelete, self).get_parser(prog_name)
|
parser = super(ActionDelete, self).get_parser(prog_name)
|
||||||
@ -124,7 +123,7 @@ class ActionDelete(Command):
|
|||||||
logging.info('Action {0} deleted'.format(parsed_args.action_id))
|
logging.info('Action {0} deleted'.format(parsed_args.action_id))
|
||||||
|
|
||||||
|
|
||||||
class ActionCreate(Command):
|
class ActionCreate(command.Command):
|
||||||
"""Create an action from a file"""
|
"""Create an action from a file"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(ActionCreate, self).get_parser(prog_name)
|
parser = super(ActionCreate, self).get_parser(prog_name)
|
||||||
@ -134,12 +133,12 @@ class ActionCreate(Command):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
action = doc_from_json_file(parsed_args.file)
|
action = utils.doc_from_json_file(parsed_args.file)
|
||||||
action_id = self.app.client.actions.create(action)
|
action_id = self.app.client.actions.create(action)
|
||||||
logging.info('Action {0} created'.format(action_id))
|
logging.info('Action {0} created'.format(action_id))
|
||||||
|
|
||||||
|
|
||||||
class ActionUpdate(Command):
|
class ActionUpdate(command.Command):
|
||||||
"""Update an action from a file"""
|
"""Update an action from a file"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(ActionUpdate, self).get_parser(prog_name)
|
parser = super(ActionUpdate, self).get_parser(prog_name)
|
||||||
@ -151,6 +150,6 @@ class ActionUpdate(Command):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
action = doc_from_json_file(parsed_args.file)
|
action = utils.doc_from_json_file(parsed_args.file)
|
||||||
self.app.client.actions.update(parsed_args.action_id, action)
|
self.app.client.actions.update(parsed_args.action_id, action)
|
||||||
logging.info('Action {0} updated'.format(parsed_args.action_id))
|
logging.info('Action {0} updated'.format(parsed_args.action_id))
|
||||||
|
@ -14,20 +14,19 @@
|
|||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
import pprint
|
||||||
|
|
||||||
from pprint import pformat
|
from cliff import lister
|
||||||
|
from cliff import show
|
||||||
from cliff.lister import Lister
|
|
||||||
from cliff.show import ShowOne
|
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.utils import prepare_search
|
from freezerclient import utils
|
||||||
|
|
||||||
|
|
||||||
logging = logging.getLogger(__name__)
|
logging = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class BackupShow(ShowOne):
|
class BackupShow(show.ShowOne):
|
||||||
"""Show the metadata of a single backup"""
|
"""Show the metadata of a single backup"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(BackupShow, self).get_parser(prog_name)
|
parser = super(BackupShow, self).get_parser(prog_name)
|
||||||
@ -58,12 +57,12 @@ class BackupShow(ShowOne):
|
|||||||
data = (
|
data = (
|
||||||
backup.get('backup_id'),
|
backup.get('backup_id'),
|
||||||
backup.get('backup_uuid'),
|
backup.get('backup_uuid'),
|
||||||
pformat(backup.get('backup_metadata'))
|
pprint.pformat(backup.get('backup_metadata'))
|
||||||
)
|
)
|
||||||
return column, data
|
return column, data
|
||||||
|
|
||||||
|
|
||||||
class BackupList(Lister):
|
class BackupList(lister.Lister):
|
||||||
"""List all backups for your user"""
|
"""List all backups for your user"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(BackupList, self).get_parser(prog_name)
|
parser = super(BackupList, self).get_parser(prog_name)
|
||||||
@ -91,7 +90,7 @@ class BackupList(Lister):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
search = prepare_search(parsed_args.search)
|
search = utils.prepare_search(parsed_args.search)
|
||||||
|
|
||||||
backups = self.app.client.backups.list(limit=parsed_args.limit,
|
backups = self.app.client.backups.list(limit=parsed_args.limit,
|
||||||
offset=parsed_args.offset,
|
offset=parsed_args.offset,
|
||||||
|
@ -13,23 +13,20 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import pprint
|
||||||
|
|
||||||
from pprint import pformat
|
from cliff import command
|
||||||
from pprint import pprint
|
from cliff import lister
|
||||||
|
from cliff import show
|
||||||
from cliff.command import Command
|
|
||||||
from cliff.lister import Lister
|
|
||||||
from cliff.show import ShowOne
|
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.utils import doc_from_json_file
|
from freezerclient import utils
|
||||||
from freezerclient.utils import prepare_search
|
|
||||||
|
|
||||||
|
|
||||||
logging = logging.getLogger(__name__)
|
logging = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class JobShow(ShowOne):
|
class JobShow(show.ShowOne):
|
||||||
"""Show a single job"""
|
"""Show a single job"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(JobShow, self).get_parser(prog_name)
|
parser = super(JobShow, self).get_parser(prog_name)
|
||||||
@ -60,7 +57,7 @@ class JobShow(ShowOne):
|
|||||||
job.get('user_id'),
|
job.get('user_id'),
|
||||||
job.get('session_id', ''),
|
job.get('session_id', ''),
|
||||||
job.get('description'),
|
job.get('description'),
|
||||||
pformat(job.get('job_actions')),
|
pprint.pformat(job.get('job_actions')),
|
||||||
job.get('job_schedule', {}).get('schedule_start_date', ''),
|
job.get('job_schedule', {}).get('schedule_start_date', ''),
|
||||||
job.get('job_schedule', {}).get('schedule_interval', ''),
|
job.get('job_schedule', {}).get('schedule_interval', ''),
|
||||||
job.get('job_schedule', {}).get('schedule_end_date', ''),
|
job.get('job_schedule', {}).get('schedule_end_date', ''),
|
||||||
@ -68,7 +65,7 @@ class JobShow(ShowOne):
|
|||||||
return column, data
|
return column, data
|
||||||
|
|
||||||
|
|
||||||
class JobList(Lister):
|
class JobList(lister.Lister):
|
||||||
"""List all the jobs for your user"""
|
"""List all the jobs for your user"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(JobList, self).get_parser(prog_name)
|
parser = super(JobList, self).get_parser(prog_name)
|
||||||
@ -104,7 +101,7 @@ class JobList(Lister):
|
|||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
|
||||||
search = prepare_search(parsed_args.search)
|
search = utils.prepare_search(parsed_args.search)
|
||||||
|
|
||||||
if parsed_args.client_id:
|
if parsed_args.client_id:
|
||||||
jobs = self.app.client.jobs.list(
|
jobs = self.app.client.jobs.list(
|
||||||
@ -134,7 +131,7 @@ class JobList(Lister):
|
|||||||
) for job in jobs))
|
) for job in jobs))
|
||||||
|
|
||||||
|
|
||||||
class JobGet(Command):
|
class JobGet(command.Command):
|
||||||
"""Download a job as a json file"""
|
"""Download a job as a json file"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(JobGet, self).get_parser(prog_name)
|
parser = super(JobGet, self).get_parser(prog_name)
|
||||||
@ -157,10 +154,10 @@ class JobGet(Command):
|
|||||||
if parsed_args.no_format:
|
if parsed_args.no_format:
|
||||||
print(job)
|
print(job)
|
||||||
else:
|
else:
|
||||||
pprint(job)
|
pprint.pprint(job)
|
||||||
|
|
||||||
|
|
||||||
class JobDelete(Command):
|
class JobDelete(command.Command):
|
||||||
"""Delete a job from the api"""
|
"""Delete a job from the api"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(JobDelete, self).get_parser(prog_name)
|
parser = super(JobDelete, self).get_parser(prog_name)
|
||||||
@ -173,7 +170,7 @@ class JobDelete(Command):
|
|||||||
logging.info('Job {0} deleted'.format(parsed_args.job_id))
|
logging.info('Job {0} deleted'.format(parsed_args.job_id))
|
||||||
|
|
||||||
|
|
||||||
class JobCreate(Command):
|
class JobCreate(command.Command):
|
||||||
"""Create a new job from a file"""
|
"""Create a new job from a file"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(JobCreate, self).get_parser(prog_name)
|
parser = super(JobCreate, self).get_parser(prog_name)
|
||||||
@ -183,12 +180,12 @@ class JobCreate(Command):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
job = doc_from_json_file(parsed_args.file)
|
job = utils.doc_from_json_file(parsed_args.file)
|
||||||
job_id = self.app.client.jobs.create(job)
|
job_id = self.app.client.jobs.create(job)
|
||||||
logging.info('Job {0} created'.format(job_id))
|
logging.info('Job {0} created'.format(job_id))
|
||||||
|
|
||||||
|
|
||||||
class JobStart(Command):
|
class JobStart(command.Command):
|
||||||
"""Send a start signal for a job"""
|
"""Send a start signal for a job"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(JobStart, self).get_parser(prog_name)
|
parser = super(JobStart, self).get_parser(prog_name)
|
||||||
@ -201,7 +198,7 @@ class JobStart(Command):
|
|||||||
logging.info('Job {0} has started'.format(parsed_args.job_id))
|
logging.info('Job {0} has started'.format(parsed_args.job_id))
|
||||||
|
|
||||||
|
|
||||||
class JobStop(Command):
|
class JobStop(command.Command):
|
||||||
"""Send a stop signal for a job"""
|
"""Send a stop signal for a job"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(JobStop, self).get_parser(prog_name)
|
parser = super(JobStop, self).get_parser(prog_name)
|
||||||
@ -214,7 +211,7 @@ class JobStop(Command):
|
|||||||
logging.info('Job {0} has stopped'.format(parsed_args.job_id))
|
logging.info('Job {0} has stopped'.format(parsed_args.job_id))
|
||||||
|
|
||||||
|
|
||||||
class JobAbort(Command):
|
class JobAbort(command.Command):
|
||||||
"""Abort a running job"""
|
"""Abort a running job"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(JobAbort, self).get_parser(prog_name)
|
parser = super(JobAbort, self).get_parser(prog_name)
|
||||||
@ -227,7 +224,7 @@ class JobAbort(Command):
|
|||||||
logging.info('Job {0} has been aborted'.format(parsed_args.job_id))
|
logging.info('Job {0} has been aborted'.format(parsed_args.job_id))
|
||||||
|
|
||||||
|
|
||||||
class JobUpdate(Command):
|
class JobUpdate(command.Command):
|
||||||
"""Update a job from a file"""
|
"""Update a job from a file"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(JobUpdate, self).get_parser(prog_name)
|
parser = super(JobUpdate, self).get_parser(prog_name)
|
||||||
@ -239,6 +236,6 @@ class JobUpdate(Command):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
job = doc_from_json_file(parsed_args.file)
|
job = utils.doc_from_json_file(parsed_args.file)
|
||||||
self.app.client.jobs.update(parsed_args.job_id, job)
|
self.app.client.jobs.update(parsed_args.job_id, job)
|
||||||
logging.info('Job {0} updated'.format(parsed_args.job_id))
|
logging.info('Job {0} updated'.format(parsed_args.job_id))
|
||||||
|
@ -16,7 +16,7 @@ import json
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.utils import create_headers_for_request
|
from freezerclient import utils
|
||||||
|
|
||||||
|
|
||||||
class ActionManager(object):
|
class ActionManager(object):
|
||||||
@ -28,7 +28,7 @@ class ActionManager(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def headers(self):
|
def headers(self):
|
||||||
return create_headers_for_request(self.client.auth_token)
|
return utils.create_headers_for_request(self.client.auth_token)
|
||||||
|
|
||||||
def create(self, doc, action_id=''):
|
def create(self, doc, action_id=''):
|
||||||
action_id = action_id or doc.get('action_id', '')
|
action_id = action_id or doc.get('action_id', '')
|
||||||
|
@ -16,7 +16,7 @@ import json
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.utils import create_headers_for_request
|
from freezerclient import utils
|
||||||
|
|
||||||
|
|
||||||
class BackupsManager(object):
|
class BackupsManager(object):
|
||||||
@ -28,7 +28,7 @@ class BackupsManager(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def headers(self):
|
def headers(self):
|
||||||
return create_headers_for_request(self.client.auth_token)
|
return utils.create_headers_for_request(self.client.auth_token)
|
||||||
|
|
||||||
def create(self, backup_metadata):
|
def create(self, backup_metadata):
|
||||||
r = requests.post(self.endpoint,
|
r = requests.post(self.endpoint,
|
||||||
|
@ -16,7 +16,7 @@ import json
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.utils import create_headers_for_request
|
from freezerclient import utils
|
||||||
|
|
||||||
|
|
||||||
class ClientManager(object):
|
class ClientManager(object):
|
||||||
@ -28,7 +28,7 @@ class ClientManager(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def headers(self):
|
def headers(self):
|
||||||
return create_headers_for_request(self.client.auth_token)
|
return utils.create_headers_for_request(self.client.auth_token)
|
||||||
|
|
||||||
def create(self, client_info):
|
def create(self, client_info):
|
||||||
r = requests.post(self.endpoint,
|
r = requests.post(self.endpoint,
|
||||||
|
@ -16,7 +16,7 @@ import json
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.utils import create_headers_for_request
|
from freezerclient import utils
|
||||||
|
|
||||||
|
|
||||||
class JobManager(object):
|
class JobManager(object):
|
||||||
@ -28,7 +28,7 @@ class JobManager(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def headers(self):
|
def headers(self):
|
||||||
return create_headers_for_request(self.client.auth_token)
|
return utils.create_headers_for_request(self.client.auth_token)
|
||||||
|
|
||||||
def create(self, doc, job_id=''):
|
def create(self, doc, job_id=''):
|
||||||
job_id = job_id or doc.get('job_id', '')
|
job_id = job_id or doc.get('job_id', '')
|
||||||
|
@ -16,7 +16,7 @@ import json
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.utils import create_headers_for_request
|
from freezerclient import utils
|
||||||
|
|
||||||
|
|
||||||
class SessionManager(object):
|
class SessionManager(object):
|
||||||
@ -28,7 +28,7 @@ class SessionManager(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def headers(self):
|
def headers(self):
|
||||||
return create_headers_for_request(self.client.auth_token)
|
return utils.create_headers_for_request(self.client.auth_token)
|
||||||
|
|
||||||
def create(self, doc, session_id=''):
|
def create(self, doc, session_id=''):
|
||||||
session_id = session_id or doc.get('session_id', '')
|
session_id = session_id or doc.get('session_id', '')
|
||||||
|
@ -13,21 +13,20 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import pprint
|
||||||
|
|
||||||
from pprint import pformat
|
from cliff import command
|
||||||
|
from cliff import lister
|
||||||
from cliff.command import Command
|
from cliff import show
|
||||||
from cliff.lister import Lister
|
|
||||||
from cliff.show import ShowOne
|
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.utils import doc_from_json_file
|
from freezerclient import utils
|
||||||
|
|
||||||
|
|
||||||
logging = logging.getLogger(__name__)
|
logging = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SessionShow(ShowOne):
|
class SessionShow(show.ShowOne):
|
||||||
"""Show a single session"""
|
"""Show a single session"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(SessionShow, self).get_parser(prog_name)
|
parser = super(SessionShow, self).get_parser(prog_name)
|
||||||
@ -52,12 +51,12 @@ class SessionShow(ShowOne):
|
|||||||
session.get('session_id'),
|
session.get('session_id'),
|
||||||
session.get('description'),
|
session.get('description'),
|
||||||
session.get('status'),
|
session.get('status'),
|
||||||
pformat(session.get('jobs'))
|
pprint.pformat(session.get('jobs'))
|
||||||
)
|
)
|
||||||
return column, data
|
return column, data
|
||||||
|
|
||||||
|
|
||||||
class SessionList(Lister):
|
class SessionList(lister.Lister):
|
||||||
"""List all the sessions for your user"""
|
"""List all the sessions for your user"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(SessionList, self).get_parser(prog_name)
|
parser = super(SessionList, self).get_parser(prog_name)
|
||||||
@ -99,7 +98,7 @@ class SessionList(Lister):
|
|||||||
) for session in sessions))
|
) for session in sessions))
|
||||||
|
|
||||||
|
|
||||||
class SessionCreate(Command):
|
class SessionCreate(command.Command):
|
||||||
"""Create a session from a file"""
|
"""Create a session from a file"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(SessionCreate, self).get_parser(prog_name)
|
parser = super(SessionCreate, self).get_parser(prog_name)
|
||||||
@ -109,12 +108,12 @@ class SessionCreate(Command):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
session = doc_from_json_file(parsed_args.file)
|
session = utils.doc_from_json_file(parsed_args.file)
|
||||||
session_id = self.app.client.sessions.create(session)
|
session_id = self.app.client.sessions.create(session)
|
||||||
logging.info('Session {0} created'.format(session_id))
|
logging.info('Session {0} created'.format(session_id))
|
||||||
|
|
||||||
|
|
||||||
class SessionAddJob(Command):
|
class SessionAddJob(command.Command):
|
||||||
"""Add a job to a session"""
|
"""Add a job to a session"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(SessionAddJob, self).get_parser(prog_name)
|
parser = super(SessionAddJob, self).get_parser(prog_name)
|
||||||
@ -133,7 +132,7 @@ class SessionAddJob(Command):
|
|||||||
parsed_args.job_id, parsed_args.session_id))
|
parsed_args.job_id, parsed_args.session_id))
|
||||||
|
|
||||||
|
|
||||||
class SessionRemoveJob(Command):
|
class SessionRemoveJob(command.Command):
|
||||||
"""Remove a job from a session"""
|
"""Remove a job from a session"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(SessionRemoveJob, self).get_parser(prog_name)
|
parser = super(SessionRemoveJob, self).get_parser(prog_name)
|
||||||
@ -163,7 +162,7 @@ class SessionRemoveJob(Command):
|
|||||||
parsed_args.job_id, parsed_args.session_id))
|
parsed_args.job_id, parsed_args.session_id))
|
||||||
|
|
||||||
|
|
||||||
class SessionStart(Command):
|
class SessionStart(command.Command):
|
||||||
"""Start a session"""
|
"""Start a session"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
pass
|
pass
|
||||||
@ -172,7 +171,7 @@ class SessionStart(Command):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class SessionEnd(Command):
|
class SessionEnd(command.Command):
|
||||||
"""Stop a session"""
|
"""Stop a session"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
pass
|
pass
|
||||||
@ -181,7 +180,7 @@ class SessionEnd(Command):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class SessionUpdate(Command):
|
class SessionUpdate(command.Command):
|
||||||
"""Update a session from a file"""
|
"""Update a session from a file"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(SessionUpdate, self).get_parser(prog_name)
|
parser = super(SessionUpdate, self).get_parser(prog_name)
|
||||||
@ -193,6 +192,6 @@ class SessionUpdate(Command):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
session = doc_from_json_file(parsed_args.file)
|
session = utils.doc_from_json_file(parsed_args.file)
|
||||||
self.app.client.sessions.update(parsed_args.session_id, session)
|
self.app.client.sessions.update(parsed_args.session_id, session)
|
||||||
logging.info('Session {0} updated'.format(parsed_args.session_id))
|
logging.info('Session {0} updated'.format(parsed_args.session_id))
|
||||||
|
Loading…
Reference in New Issue
Block a user