Add full pep8 check
This patch adds almost full pep8 check including unit test code. All code style problems is solved. Change-Id: Ie9b31b2ecfafc22fc299d749ca45ce69fdc64472 Closes-Bug: #1645342 Signed-off-by: Ruslan Aliev <raliev@mirantis.com>
This commit is contained in:
parent
2500e1e572
commit
6010f1cbe8
@ -12,9 +12,10 @@
|
|||||||
# 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 unittest
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import unittest
|
|
||||||
|
|
||||||
from freezerclient.v1 import client
|
from freezerclient.v1 import client
|
||||||
|
|
||||||
@ -89,7 +90,8 @@ class TestSupportFunctions(unittest.TestCase):
|
|||||||
|
|
||||||
@mock.patch('freezerclient.v1.client.v3')
|
@mock.patch('freezerclient.v1.client.v3')
|
||||||
@mock.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()
|
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 = ''
|
||||||
@ -107,7 +109,8 @@ class TestClientMock(unittest.TestCase):
|
|||||||
|
|
||||||
@mock.patch('freezerclient.v1.client.ksa_session')
|
@mock.patch('freezerclient.v1.client.ksa_session')
|
||||||
@mock.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',
|
||||||
'password': 'charlie',
|
'password': 'charlie',
|
||||||
@ -140,7 +143,8 @@ class TestClientMock(unittest.TestCase):
|
|||||||
@mock.patch('freezerclient.v1.client.socket')
|
@mock.patch('freezerclient.v1.client.socket')
|
||||||
@mock.patch('freezerclient.v1.client.ksa_session')
|
@mock.patch('freezerclient.v1.client.ksa_session')
|
||||||
@mock.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()
|
mock_session = mock.Mock()
|
||||||
mock_session.get_project_id.return_value = 'H2O'
|
mock_session.get_project_id.return_value = 'H2O'
|
||||||
|
@ -12,16 +12,15 @@
|
|||||||
# 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 unittest
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import unittest
|
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.v1.managers import actions
|
from freezerclient.v1.managers import actions
|
||||||
|
|
||||||
|
|
||||||
class TestActionManager(unittest.TestCase):
|
class TestActionManager(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.mock_client = mock.Mock()
|
self.mock_client = mock.Mock()
|
||||||
self.mock_response = mock.Mock()
|
self.mock_response = mock.Mock()
|
||||||
@ -32,7 +31,8 @@ class TestActionManager(unittest.TestCase):
|
|||||||
|
|
||||||
@mock.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',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'},
|
'Accept': 'application/json'},
|
||||||
@ -50,7 +50,8 @@ class TestActionManager(unittest.TestCase):
|
|||||||
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'})
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -63,7 +64,8 @@ class TestActionManager(unittest.TestCase):
|
|||||||
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')
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -77,7 +79,8 @@ class TestActionManager(unittest.TestCase):
|
|||||||
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')
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -89,7 +92,8 @@ class TestActionManager(unittest.TestCase):
|
|||||||
@mock.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'}]
|
||||||
self.mock_response.json.return_value = {'actions': action_list}
|
self.mock_response.json.return_value = {'actions': action_list}
|
||||||
mock_requests.get.return_value = self.mock_response
|
mock_requests.get.return_value = self.mock_response
|
||||||
retval = self.action_manager.list()
|
retval = self.action_manager.list()
|
||||||
@ -98,10 +102,12 @@ class TestActionManager(unittest.TestCase):
|
|||||||
@mock.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'}]
|
||||||
self.mock_response.json.return_value = {'clients': action_list}
|
self.mock_response.json.return_value = {'clients': action_list}
|
||||||
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)
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -112,19 +118,25 @@ class TestActionManager(unittest.TestCase):
|
|||||||
"action_id": "d454beec-1f3c-4d11-aa1a-404116a40502"
|
"action_id": "d454beec-1f3c-4d11-aa1a-404116a40502"
|
||||||
}
|
}
|
||||||
mock_requests.patch.return_value = self.mock_response
|
mock_requests.patch.return_value = self.mock_response
|
||||||
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)
|
||||||
|
|
||||||
@mock.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"},
|
||||||
"version": 12,
|
"version": 12,
|
||||||
"action_id": "d454beec-1f3c-4d11-aa1a-404116a40502"
|
"action_id": "d454beec-1f3c-4d11-aa1a-404116a40502"
|
||||||
}
|
}
|
||||||
self.mock_response.status_code = 404
|
self.mock_response.status_code = 404
|
||||||
self.mock_response.text = '{"title": "Not Found","description":"No document found with ID d454beec-1f3c-4d11-aa1a-404116a40502x"}'
|
self.mock_response.text = (
|
||||||
|
'{"title": "Not Found","description":"No document found with ID '
|
||||||
|
'd454beec-1f3c-4d11-aa1a-404116a40502x"}'
|
||||||
|
)
|
||||||
mock_requests.patch.return_value = self.mock_response
|
mock_requests.patch.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.action_manager.update,
|
self.assertRaises(exceptions.ApiClientException,
|
||||||
'd454beec-1f3c-4d11-aa1a-404116a40502', {'status': 'bamboozled'})
|
self.action_manager.update,
|
||||||
|
'd454beec-1f3c-4d11-aa1a-404116a40502',
|
||||||
|
{'status': 'bamboozled'})
|
||||||
|
@ -12,16 +12,15 @@
|
|||||||
# 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 unittest
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import unittest
|
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.v1.managers import backups
|
from freezerclient.v1.managers import backups
|
||||||
|
|
||||||
|
|
||||||
class TestBackupManager(unittest.TestCase):
|
class TestBackupManager(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.mock_client = mock.Mock()
|
self.mock_client = mock.Mock()
|
||||||
self.mock_client.endpoint = 'http://testendpoint:9999'
|
self.mock_client.endpoint = 'http://testendpoint:9999'
|
||||||
@ -30,7 +29,8 @@ class TestBackupManager(unittest.TestCase):
|
|||||||
|
|
||||||
@mock.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',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'},
|
'Accept': 'application/json'},
|
||||||
@ -50,7 +50,8 @@ class TestBackupManager(unittest.TestCase):
|
|||||||
mock_response = mock.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'})
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -65,7 +66,8 @@ class TestBackupManager(unittest.TestCase):
|
|||||||
mock_response = mock.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')
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -96,7 +98,8 @@ class TestBackupManager(unittest.TestCase):
|
|||||||
def test_list_ok(self, mock_requests):
|
def test_list_ok(self, mock_requests):
|
||||||
mock_response = mock.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}
|
||||||
mock_requests.get.return_value = mock_response
|
mock_requests.get.return_value = mock_response
|
||||||
retval = self.b.list()
|
retval = self.b.list()
|
||||||
@ -106,7 +109,8 @@ class TestBackupManager(unittest.TestCase):
|
|||||||
def test_list_parameters(self, mock_requests):
|
def test_list_parameters(self, mock_requests):
|
||||||
mock_response = mock.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}
|
||||||
mock_requests.get.return_value = mock_response
|
mock_requests.get.return_value = mock_response
|
||||||
retval = self.b.list(limit=5,
|
retval = self.b.list(limit=5,
|
||||||
@ -126,8 +130,8 @@ class TestBackupManager(unittest.TestCase):
|
|||||||
def test_list_error(self, mock_requests):
|
def test_list_error(self, mock_requests):
|
||||||
mock_response = mock.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}
|
||||||
mock_requests.get.return_value = mock_response
|
mock_requests.get.return_value = mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.b.list)
|
self.assertRaises(exceptions.ApiClientException, self.b.list)
|
||||||
|
|
||||||
|
@ -12,15 +12,15 @@
|
|||||||
# 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
|
||||||
|
|
||||||
|
import mock
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.v1.client import clients
|
from freezerclient.v1.client import clients
|
||||||
|
|
||||||
|
|
||||||
class TestClientManager(unittest.TestCase):
|
class TestClientManager(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.mock_client = mock.Mock()
|
self.mock_client = mock.Mock()
|
||||||
self.mock_client.endpoint = 'http://testendpoint:9999'
|
self.mock_client.endpoint = 'http://testendpoint:9999'
|
||||||
@ -29,7 +29,8 @@ class TestClientManager(unittest.TestCase):
|
|||||||
|
|
||||||
@mock.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',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'},
|
'Accept': 'application/json'},
|
||||||
@ -49,7 +50,8 @@ class TestClientManager(unittest.TestCase):
|
|||||||
mock_response = mock.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'})
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -64,7 +66,8 @@ class TestClientManager(unittest.TestCase):
|
|||||||
mock_response = mock.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')
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -84,17 +87,20 @@ class TestClientManager(unittest.TestCase):
|
|||||||
self.assertIsNone(retval)
|
self.assertIsNone(retval)
|
||||||
|
|
||||||
@mock.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()
|
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')
|
||||||
|
|
||||||
@mock.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()
|
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}
|
||||||
mock_requests.get.return_value = mock_response
|
mock_requests.get.return_value = mock_response
|
||||||
retval = self.r.list()
|
retval = self.r.list()
|
||||||
@ -104,8 +110,8 @@ class TestClientManager(unittest.TestCase):
|
|||||||
def test_list_error(self, mock_requests):
|
def test_list_error(self, mock_requests):
|
||||||
mock_response = mock.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}
|
||||||
mock_requests.get.return_value = mock_response
|
mock_requests.get.return_value = mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.r.list)
|
self.assertRaises(exceptions.ApiClientException, self.r.list)
|
||||||
|
|
||||||
|
@ -13,15 +13,15 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import mock
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
import mock
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.v1.client import jobs
|
from freezerclient.v1.client import jobs
|
||||||
|
|
||||||
|
|
||||||
class TestJobManager(unittest.TestCase):
|
class TestJobManager(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.mock_client = mock.Mock()
|
self.mock_client = mock.Mock()
|
||||||
self.mock_response = mock.Mock()
|
self.mock_response = mock.Mock()
|
||||||
@ -33,11 +33,12 @@ class TestJobManager(unittest.TestCase):
|
|||||||
'X-Auth-Token': 'testtoken',
|
'X-Auth-Token': 'testtoken',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json'
|
||||||
}
|
}
|
||||||
|
|
||||||
@mock.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',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'},
|
'Accept': 'application/json'},
|
||||||
@ -53,7 +54,8 @@ class TestJobManager(unittest.TestCase):
|
|||||||
|
|
||||||
@mock.patch('freezerclient.v1.managers.jobs.json')
|
@mock.patch('freezerclient.v1.managers.jobs.json')
|
||||||
@mock.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'}
|
||||||
mock_json.dumps.return_value = {'job': 'mocked'}
|
mock_json.dumps.return_value = {'job': 'mocked'}
|
||||||
@ -61,8 +63,9 @@ class TestJobManager(unittest.TestCase):
|
|||||||
|
|
||||||
retval = self.job_manager.create({'job': 'metadata'})
|
retval = self.job_manager.create({'job': 'metadata'})
|
||||||
|
|
||||||
mock_json.dumps.assert_called_with({'job': 'metadata',
|
mock_json.dumps.assert_called_with({
|
||||||
'client_id': 'test_client_id_78900987'})
|
'job': 'metadata', 'client_id': 'test_client_id_78900987'
|
||||||
|
})
|
||||||
self.assertEqual('qwerqwer', retval)
|
self.assertEqual('qwerqwer', retval)
|
||||||
|
|
||||||
@mock.patch('freezerclient.v1.managers.jobs.json')
|
@mock.patch('freezerclient.v1.managers.jobs.json')
|
||||||
@ -73,7 +76,8 @@ class TestJobManager(unittest.TestCase):
|
|||||||
mock_json.dumps.return_value = {'job': 'mocked'}
|
mock_json.dumps.return_value = {'job': 'mocked'}
|
||||||
mock_requests.post.return_value = self.mock_response
|
mock_requests.post.return_value = self.mock_response
|
||||||
|
|
||||||
retval = self.job_manager.create({'job': 'metadata', 'client_id': 'parmenide'})
|
retval = self.job_manager.create(
|
||||||
|
{'job': 'metadata', 'client_id': 'parmenide'})
|
||||||
|
|
||||||
mock_json.dumps.assert_called_with({'job': 'metadata',
|
mock_json.dumps.assert_called_with({'job': 'metadata',
|
||||||
'client_id': 'parmenide'})
|
'client_id': 'parmenide'})
|
||||||
@ -83,7 +87,8 @@ class TestJobManager(unittest.TestCase):
|
|||||||
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'})
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -96,7 +101,8 @@ class TestJobManager(unittest.TestCase):
|
|||||||
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')
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -110,7 +116,8 @@ class TestJobManager(unittest.TestCase):
|
|||||||
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')
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -145,22 +152,28 @@ class TestJobManager(unittest.TestCase):
|
|||||||
"job_id": "d454beec-1f3c-4d11-aa1a-404116a40502"
|
"job_id": "d454beec-1f3c-4d11-aa1a-404116a40502"
|
||||||
}
|
}
|
||||||
mock_requests.patch.return_value = self.mock_response
|
mock_requests.patch.return_value = self.mock_response
|
||||||
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)
|
||||||
|
|
||||||
@mock.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"},
|
||||||
"version": 12,
|
"version": 12,
|
||||||
"job_id": "d454beec-1f3c-4d11-aa1a-404116a40502"
|
"job_id": "d454beec-1f3c-4d11-aa1a-404116a40502"
|
||||||
}
|
}
|
||||||
self.mock_response.status_code = 404
|
self.mock_response.status_code = 404
|
||||||
self.mock_response.text = '{"title": "Not Found","description":"No document found with ID d454beec-1f3c-4d11-aa1a-404116a40502x"}'
|
self.mock_response.text = (
|
||||||
|
'{"title": "Not Found","description":"No document found with ID '
|
||||||
|
'd454beec-1f3c-4d11-aa1a-404116a40502x"}'
|
||||||
|
)
|
||||||
mock_requests.patch.return_value = self.mock_response
|
mock_requests.patch.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.job_manager.update,
|
self.assertRaises(exceptions.ApiClientException,
|
||||||
'd454beec-1f3c-4d11-aa1a-404116a40502', {'status': 'bamboozled'})
|
self.job_manager.update,
|
||||||
|
'd454beec-1f3c-4d11-aa1a-404116a40502',
|
||||||
|
{'status': 'bamboozled'})
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -170,7 +183,8 @@ class TestJobManager(unittest.TestCase):
|
|||||||
mock_requests.post.return_value = self.mock_response
|
mock_requests.post.return_value = self.mock_response
|
||||||
# /v1/jobs/{job_id}/event
|
# /v1/jobs/{job_id}/event
|
||||||
|
|
||||||
endpoint = '{0}/v1/jobs/{1}/event'.format(self.mock_client.endpoint, job_id)
|
endpoint = '{0}/v1/jobs/{1}/event'.format(self.mock_client.endpoint,
|
||||||
|
job_id)
|
||||||
data = {"start": None}
|
data = {"start": None}
|
||||||
retval = self.job_manager.start_job(job_id)
|
retval = self.job_manager.start_job(job_id)
|
||||||
self.assertEqual({'result': 'success'}, retval)
|
self.assertEqual({'result': 'success'}, retval)
|
||||||
@ -182,12 +196,14 @@ class TestJobManager(unittest.TestCase):
|
|||||||
self.assertEqual(self.headers, kwargs['headers'])
|
self.assertEqual(self.headers, kwargs['headers'])
|
||||||
|
|
||||||
@mock.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
|
||||||
self.mock_response.json.return_value = {'result': 'success'}
|
self.mock_response.json.return_value = {'result': 'success'}
|
||||||
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)
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -197,7 +213,8 @@ class TestJobManager(unittest.TestCase):
|
|||||||
mock_requests.post.return_value = self.mock_response
|
mock_requests.post.return_value = self.mock_response
|
||||||
# /v1/jobs/{job_id}/event
|
# /v1/jobs/{job_id}/event
|
||||||
|
|
||||||
endpoint = '{0}/v1/jobs/{1}/event'.format(self.mock_client.endpoint, job_id)
|
endpoint = '{0}/v1/jobs/{1}/event'.format(self.mock_client.endpoint,
|
||||||
|
job_id)
|
||||||
data = {"stop": None}
|
data = {"stop": None}
|
||||||
retval = self.job_manager.stop_job(job_id)
|
retval = self.job_manager.stop_job(job_id)
|
||||||
self.assertEqual({'result': 'success'}, retval)
|
self.assertEqual({'result': 'success'}, retval)
|
||||||
@ -209,12 +226,14 @@ class TestJobManager(unittest.TestCase):
|
|||||||
self.assertEqual(self.headers, kwargs['headers'])
|
self.assertEqual(self.headers, kwargs['headers'])
|
||||||
|
|
||||||
@mock.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
|
||||||
self.mock_response.json.return_value = {'result': 'success'}
|
self.mock_response.json.return_value = {'result': 'success'}
|
||||||
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)
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -224,7 +243,8 @@ class TestJobManager(unittest.TestCase):
|
|||||||
mock_requests.post.return_value = self.mock_response
|
mock_requests.post.return_value = self.mock_response
|
||||||
# /v1/jobs/{job_id}/event
|
# /v1/jobs/{job_id}/event
|
||||||
|
|
||||||
endpoint = '{0}/v1/jobs/{1}/event'.format(self.mock_client.endpoint, job_id)
|
endpoint = '{0}/v1/jobs/{1}/event'.format(self.mock_client.endpoint,
|
||||||
|
job_id)
|
||||||
data = {"abort": None}
|
data = {"abort": None}
|
||||||
retval = self.job_manager.abort_job(job_id)
|
retval = self.job_manager.abort_job(job_id)
|
||||||
self.assertEqual({'result': 'success'}, retval)
|
self.assertEqual({'result': 'success'}, retval)
|
||||||
@ -236,10 +256,11 @@ class TestJobManager(unittest.TestCase):
|
|||||||
self.assertEqual(self.headers, kwargs['headers'])
|
self.assertEqual(self.headers, kwargs['headers'])
|
||||||
|
|
||||||
@mock.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
|
||||||
self.mock_response.json.return_value = {'result': 'success'}
|
self.mock_response.json.return_value = {'result': 'success'}
|
||||||
mock_requests.post.return_value = self.mock_response
|
mock_requests.post.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.job_manager.abort_job, job_id)
|
self.assertRaises(exceptions.ApiClientException,
|
||||||
|
self.job_manager.abort_job, job_id)
|
||||||
|
@ -13,15 +13,15 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import mock
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
import mock
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.v1.client import sessions
|
from freezerclient.v1.client import sessions
|
||||||
|
|
||||||
|
|
||||||
class TestSessionManager(unittest.TestCase):
|
class TestSessionManager(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.mock_client = mock.Mock()
|
self.mock_client = mock.Mock()
|
||||||
self.mock_response = mock.Mock()
|
self.mock_response = mock.Mock()
|
||||||
@ -34,7 +34,7 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
'X-Auth-Token': 'testtoken',
|
'X-Auth-Token': 'testtoken',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json'
|
||||||
}
|
}
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -50,10 +50,12 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
self.assertEqual('qwerqwer', retval)
|
self.assertEqual('qwerqwer', retval)
|
||||||
|
|
||||||
@mock.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'})
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -63,10 +65,12 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
self.assertIsNone(retval)
|
self.assertIsNone(retval)
|
||||||
|
|
||||||
@mock.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')
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -77,10 +81,12 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
self.assertEqual({'session_id': 'qwerqwer'}, retval)
|
self.assertEqual({'session_id': 'qwerqwer'}, retval)
|
||||||
|
|
||||||
@mock.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_diff_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')
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -92,19 +98,23 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
@mock.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'}]
|
||||||
self.mock_response.json.return_value = {'sessions': session_list}
|
self.mock_response.json.return_value = {'sessions': session_list}
|
||||||
mock_requests.get.return_value = self.mock_response
|
mock_requests.get.return_value = self.mock_response
|
||||||
retval = self.session_manager.list()
|
retval = self.session_manager.list()
|
||||||
self.assertEqual(session_list, retval)
|
self.assertEqual(session_list, retval)
|
||||||
|
|
||||||
@mock.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'}]
|
||||||
self.mock_response.json.return_value = {'clients': session_list}
|
self.mock_response.json.return_value = {'clients': session_list}
|
||||||
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)
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -115,21 +125,28 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
"session_id": "d454beec-1f3c-4d11-aa1a-404116a40502"
|
"session_id": "d454beec-1f3c-4d11-aa1a-404116a40502"
|
||||||
}
|
}
|
||||||
mock_requests.patch.return_value = self.mock_response
|
mock_requests.patch.return_value = self.mock_response
|
||||||
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)
|
||||||
|
|
||||||
@mock.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"},
|
||||||
"version": 12,
|
"version": 12,
|
||||||
"session_id": "d454beec-1f3c-4d11-aa1a-404116a40502"
|
"session_id": "d454beec-1f3c-4d11-aa1a-404116a40502"
|
||||||
}
|
}
|
||||||
self.mock_response.status_code = 404
|
self.mock_response.status_code = 404
|
||||||
self.mock_response.text = '{"title": "Not Found","description":"No document found with ID d454beec-1f3c-4d11-aa1a-404116a40502x"}'
|
self.mock_response.text = (
|
||||||
|
'{"title": "Not Found","description":"No document found with ID '
|
||||||
|
'd454beec-1f3c-4d11-aa1a-404116a40502x"}'
|
||||||
|
)
|
||||||
mock_requests.patch.return_value = self.mock_response
|
mock_requests.patch.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.session_manager.update,
|
self.assertRaises(exceptions.ApiClientException,
|
||||||
'd454beec-1f3c-4d11-aa1a-404116a40502', {'status': 'bamboozled'})
|
self.session_manager.update,
|
||||||
|
'd454beec-1f3c-4d11-aa1a-404116a40502',
|
||||||
|
{'status': 'bamboozled'})
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -141,14 +158,17 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
retval = self.session_manager.add_job(session_id, job_id)
|
retval = self.session_manager.add_job(session_id, job_id)
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
@mock.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)
|
||||||
|
|
||||||
@mock.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):
|
||||||
@ -160,20 +180,24 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
retval = self.session_manager.remove_job(session_id, job_id)
|
retval = self.session_manager.remove_job(session_id, job_id)
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
@mock.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)
|
||||||
|
|
||||||
@mock.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
|
||||||
self.mock_response.json.return_value = {'result': 'success', 'session_tag': 24}
|
self.mock_response.json.return_value = {'result': 'success',
|
||||||
|
'session_tag': 24}
|
||||||
mock_requests.post.return_value = self.mock_response
|
mock_requests.post.return_value = self.mock_response
|
||||||
# /v1/sessions/{sessions_id}/action
|
# /v1/sessions/{sessions_id}/action
|
||||||
endpoint = '{0}{1}/action'.format(self.endpoint, session_id)
|
endpoint = '{0}{1}/action'.format(self.endpoint, session_id)
|
||||||
@ -188,24 +212,30 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
self.assertEqual(self.headers, kwargs['headers'])
|
self.assertEqual(self.headers, kwargs['headers'])
|
||||||
|
|
||||||
@mock.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
|
||||||
self.mock_response.json.return_value = {'result': 'success', 'session_tag': 24}
|
self.mock_response.json.return_value = {'result': 'success',
|
||||||
|
'session_tag': 24}
|
||||||
mock_requests.post.return_value = self.mock_response
|
mock_requests.post.return_value = self.mock_response
|
||||||
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)
|
||||||
|
|
||||||
@mock.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
|
||||||
self.mock_response.json.return_value = {'result': 'success', 'session_tag': 24}
|
self.mock_response.json.return_value = {'result': 'success',
|
||||||
|
'session_tag': 24}
|
||||||
mock_requests.post.return_value = self.mock_response
|
mock_requests.post.return_value = self.mock_response
|
||||||
# /v1/sessions/{sessions_id}/action
|
# /v1/sessions/{sessions_id}/action
|
||||||
endpoint = '{0}{1}/action'.format(self.endpoint, session_id)
|
endpoint = '{0}{1}/action'.format(self.endpoint, session_id)
|
||||||
data = {"end": {"current_tag": 23, "job_id": "jobqwerty1234", "result": "fail"}}
|
data = {"end": {"current_tag": 23, "job_id": "jobqwerty1234",
|
||||||
retval = self.session_manager.end_session(session_id, job_id, tag, 'fail')
|
"result": "fail"}}
|
||||||
|
retval = self.session_manager.end_session(session_id, job_id, tag,
|
||||||
|
'fail')
|
||||||
self.assertEqual({'result': 'success', 'session_tag': 24}, retval)
|
self.assertEqual({'result': 'success', 'session_tag': 24}, retval)
|
||||||
|
|
||||||
args = mock_requests.post.call_args[0]
|
args = mock_requests.post.call_args[0]
|
||||||
@ -215,11 +245,13 @@ class TestSessionManager(unittest.TestCase):
|
|||||||
self.assertEqual(self.headers, kwargs['headers'])
|
self.assertEqual(self.headers, kwargs['headers'])
|
||||||
|
|
||||||
@mock.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
|
||||||
self.mock_response.json.return_value = {'result': 'success', 'session_tag': 24}
|
self.mock_response.json.return_value = {'result': 'success',
|
||||||
|
'session_tag': 24}
|
||||||
mock_requests.post.return_value = self.mock_response
|
mock_requests.post.return_value = self.mock_response
|
||||||
self.assertRaises(exceptions.ApiClientException, self.session_manager.end_session,
|
self.assertRaises(exceptions.ApiClientException,
|
||||||
|
self.session_manager.end_session,
|
||||||
session_id, job_id, tag, 'fail')
|
session_id, job_id, tag, 'fail')
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
logging = logging.getLogger(__name__)
|
logging = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -57,7 +56,7 @@ class Namespace(dict):
|
|||||||
def from_object(cls, obj, names=None):
|
def from_object(cls, obj, names=None):
|
||||||
if names is None:
|
if names is None:
|
||||||
names = dir(obj)
|
names = dir(obj)
|
||||||
ns = {name:getattr(obj, name) for name in names}
|
ns = {name: getattr(obj, name) for name in names}
|
||||||
return cls(ns)
|
return cls(ns)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -94,7 +93,6 @@ class Namespace(dict):
|
|||||||
|
|
||||||
|
|
||||||
class CachedProperty(object):
|
class CachedProperty(object):
|
||||||
|
|
||||||
def __init__(self, func):
|
def __init__(self, func):
|
||||||
self.__doc__ = getattr(func, '__doc__')
|
self.__doc__ = getattr(func, '__doc__')
|
||||||
self.func = func
|
self.func = func
|
||||||
@ -140,4 +138,3 @@ def prepare_search(search_term):
|
|||||||
if search_term:
|
if search_term:
|
||||||
return {"match": [{"_all": search_term}, ], }
|
return {"match": [{"_all": search_term}, ], }
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
@ -107,7 +107,8 @@ class ActionList(lister.Lister):
|
|||||||
data = ((action.get('action-id', ''),
|
data = ((action.get('action-id', ''),
|
||||||
action.get('freezer_action', {}).get('backup_name', ''),
|
action.get('freezer_action', {}).get('backup_name', ''),
|
||||||
action.get('freezer_action', {}).get('action', ''),
|
action.get('freezer_action', {}).get('action', ''),
|
||||||
action.get('freezer_action', {}).get('path_to_backup', ''),
|
action.get('freezer_action', {}).get(
|
||||||
|
'path_to_backup', ''),
|
||||||
action.get('freezer_action', {}).get('mode', ''),
|
action.get('freezer_action', {}).get('mode', ''),
|
||||||
action.get('freezer_action', {}).get('storage', ''),
|
action.get('freezer_action', {}).get('storage', ''),
|
||||||
action.get('freezer_action', {}).get('snapshot', '')
|
action.get('freezer_action', {}).get('snapshot', '')
|
||||||
@ -116,7 +117,8 @@ class ActionList(lister.Lister):
|
|||||||
data = ((action.get('action_id'),
|
data = ((action.get('action_id'),
|
||||||
action.get('freezer_action', {}).get('backup_name', ''),
|
action.get('freezer_action', {}).get('backup_name', ''),
|
||||||
action.get('freezer_action', {}).get('action', 'backup'),
|
action.get('freezer_action', {}).get('action', 'backup'),
|
||||||
action.get('freezer_action', {}).get('path_to_backup', ''),
|
action.get('freezer_action', {}).get(
|
||||||
|
'path_to_backup', ''),
|
||||||
action.get('freezer_action', {}).get('mode', 'fs'),
|
action.get('freezer_action', {}).get('mode', 'fs'),
|
||||||
action.get('freezer_action', {}).get('storage', 'swift'),
|
action.get('freezer_action', {}).get('storage', 'swift'),
|
||||||
action.get('freezer_action', {}).get('snapshot', 'False')
|
action.get('freezer_action', {}).get('snapshot', 'False')
|
||||||
|
@ -117,4 +117,3 @@ class BackupList(lister.Lister):
|
|||||||
) for b in backups)
|
) for b in backups)
|
||||||
|
|
||||||
return columns, data
|
return columns, data
|
||||||
|
|
||||||
|
@ -95,11 +95,11 @@ class ClientList(lister.Lister):
|
|||||||
|
|
||||||
columns = ('Client ID', 'uuid', 'hostname', 'description')
|
columns = ('Client ID', 'uuid', 'hostname', 'description')
|
||||||
data = ((
|
data = ((
|
||||||
client.get('client', {}).get('client_id', ''),
|
client.get('client', {}).get('client_id', ''),
|
||||||
client.get('uuid', ''),
|
client.get('uuid', ''),
|
||||||
client.get('client', {}).get('hostname', ''),
|
client.get('client', {}).get('hostname', ''),
|
||||||
client.get('client', {}).get('description', '')
|
client.get('client', {}).get('description', '')
|
||||||
) for client in clients)
|
) for client in clients)
|
||||||
|
|
||||||
return columns, data
|
return columns, data
|
||||||
|
|
||||||
|
@ -105,16 +105,16 @@ class JobList(lister.Lister):
|
|||||||
|
|
||||||
if parsed_args.client_id:
|
if parsed_args.client_id:
|
||||||
jobs = self.app.client.jobs.list(
|
jobs = self.app.client.jobs.list(
|
||||||
limit=parsed_args.limit,
|
limit=parsed_args.limit,
|
||||||
offset=parsed_args.offset,
|
offset=parsed_args.offset,
|
||||||
search=search,
|
search=search,
|
||||||
client_id=parsed_args.client_id
|
client_id=parsed_args.client_id
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
jobs = self.app.client.jobs.list_all(
|
jobs = self.app.client.jobs.list_all(
|
||||||
limit=parsed_args.limit,
|
limit=parsed_args.limit,
|
||||||
offset=parsed_args.offset,
|
offset=parsed_args.offset,
|
||||||
search=search
|
search=search
|
||||||
)
|
)
|
||||||
|
|
||||||
columns = ('Job ID', 'Description', '# Actions', 'Result', 'Event',
|
columns = ('Job ID', 'Description', '# Actions', 'Result', 'Event',
|
||||||
|
@ -125,7 +125,7 @@ class SessionManager(object):
|
|||||||
doc = {"start": {
|
doc = {"start": {
|
||||||
"job_id": job_id,
|
"job_id": job_id,
|
||||||
"current_tag": session_tag
|
"current_tag": session_tag
|
||||||
}}
|
}}
|
||||||
r = requests.post(endpoint,
|
r = requests.post(endpoint,
|
||||||
headers=self.headers,
|
headers=self.headers,
|
||||||
data=json.dumps(doc),
|
data=json.dumps(doc),
|
||||||
@ -151,7 +151,7 @@ class SessionManager(object):
|
|||||||
"job_id": job_id,
|
"job_id": job_id,
|
||||||
"current_tag": session_tag,
|
"current_tag": session_tag,
|
||||||
"result": result
|
"result": result
|
||||||
}}
|
}}
|
||||||
r = requests.post(endpoint,
|
r = requests.post(endpoint,
|
||||||
headers=self.headers,
|
headers=self.headers,
|
||||||
data=json.dumps(doc),
|
data=json.dumps(doc),
|
||||||
|
@ -96,12 +96,12 @@ class SessionList(lister.Lister):
|
|||||||
|
|
||||||
columns = ('Session ID', 'Description', 'Status', '# Jobs')
|
columns = ('Session ID', 'Description', 'Status', '# Jobs')
|
||||||
data = ((
|
data = ((
|
||||||
session.get('session_id', ''),
|
session.get('session_id', ''),
|
||||||
session.get('description', ''),
|
session.get('description', ''),
|
||||||
session.get('status', ''),
|
session.get('status', ''),
|
||||||
len(session.get('jobs', [])) if session.get(
|
len(session.get('jobs', [])) if session.get(
|
||||||
'session_id') else '',
|
'session_id') else '',
|
||||||
) for session in sessions)
|
) for session in sessions)
|
||||||
|
|
||||||
return columns, data
|
return columns, data
|
||||||
|
|
||||||
@ -181,7 +181,8 @@ class SessionRemoveJob(command.Command):
|
|||||||
except Exception as error:
|
except Exception as error:
|
||||||
# there is an error coming from the api when a job is removed
|
# there is an error coming from the api when a job is removed
|
||||||
# with the following text:
|
# with the following text:
|
||||||
# Additional properties are not allowed ('job_event' was unexpected)
|
# Additional properties are not allowed
|
||||||
|
# ('job_event' was unexpected)
|
||||||
# but in reality the job gets removed correctly.
|
# but in reality the job gets removed correctly.
|
||||||
if 'Additional properties are not allowed' in error.message:
|
if 'Additional properties are not allowed' in error.message:
|
||||||
pass
|
pass
|
||||||
|
16
tox.ini
16
tox.ini
@ -66,16 +66,14 @@ commands = flake8 freezerclient
|
|||||||
commands = pylint --rcfile .pylintrc freezerclient
|
commands = pylint --rcfile .pylintrc freezerclient
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
# it's not a bug that we aren't using all of hacking
|
# Ignored hackings:
|
||||||
# H102 -> apache2 license exists
|
# H104 -> empty file, only comments
|
||||||
# H103 -> license is apache
|
# H202 -> assertRaises(Exception, ...) too broad
|
||||||
# H201 -> no bare excepts
|
# H404 -> Multi line docstrings should start without a leading new line.
|
||||||
# H501 -> don't use locals() for str formatting
|
# H405 -> Multi line docstrings should start with a one line summary followed by an empty line.
|
||||||
# H903 -> \n not \r\n
|
ignore = H104,H202,H404,H405
|
||||||
ignore = H
|
|
||||||
select = H102, H103, H201, H501, H903, H201, H306, H301, H233
|
|
||||||
show-source = True
|
show-source = True
|
||||||
exclude = .venv,.tox,dist,doc,test,*egg,tests,releasenotes
|
exclude = .venv,.tox,dist,doc,*egg,releasenotes
|
||||||
|
|
||||||
|
|
||||||
[testenv:releasenotes]
|
[testenv:releasenotes]
|
||||||
|
Loading…
Reference in New Issue
Block a user