diff --git a/blazar/tests/api/v1/test_utils.py b/blazar/tests/api/v1/test_utils.py index 479448d7..90550178 100644 --- a/blazar/tests/api/v1/test_utils.py +++ b/blazar/tests/api/v1/test_utils.py @@ -75,7 +75,7 @@ class UtilsTestCase(tests.TestCase): self.utils.render(result={}, response_type='application/json', status='lol') self.response.assert_called_once_with(mimetype='application/json', - status='lol', response='{}') + status='lol', response=b'{}') def test_request_data_data(self): self.request.parsed_data = "data" diff --git a/blazar/tests/api/v2/test_hosts.py b/blazar/tests/api/v2/test_hosts.py index c2c5299f..ba498bcd 100644 --- a/blazar/tests/api/v2/test_hosts.py +++ b/blazar/tests/api/v2/test_hosts.py @@ -85,17 +85,17 @@ class TestIncorrectHostFromRPC(api.APITest): def test_bad_list(self): expected = { u'error_code': 400, - u'error_message': u"Invalid input for field/attribute " - u"hypervisor_type. Value: '1'. Wrong type. " - u"Expected '', " - u"got ''", + u'error_message': u"Invalid input", u'error_name': 400 } response = self.get_json(self.path, expect_errors=True, headers=self.headers) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertEqual(expected, response.json) + self.assertEqual(expected["error_name"], response.json["error_name"]) + self.assertTrue(expected["error_message"] + in response.json["error_message"]) + self.assertEqual(expected["error_code"], response.json["error_code"]) class TestListHosts(api.APITest): @@ -227,9 +227,7 @@ class TestCreateHost(api.APITest): def test_create_wrong_attr(self): expected = { "error_name": 400, - "error_message": "Invalid input for field/attribute name. " - "Value: '1'. Wrong type. " - "Expected '', got ''", + "error_message": "Invalid input for field/attribute name. ", "error_code": 400 } @@ -238,7 +236,10 @@ class TestCreateHost(api.APITest): expect_errors=True, headers=self.headers) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertEqual(expected, response.json) + self.assertEqual(expected["error_name"], response.json["error_name"]) + self.assertTrue(expected["error_message"] + in response.json["error_message"]) + self.assertEqual(expected["error_code"], response.json["error_code"]) def test_create_with_empty_body(self): expected = { @@ -370,15 +371,14 @@ class TestDeleteHost(api.APITest): response = self.delete(self.path, headers=self.headers) self.assertEqual(204, response.status_int) self.assertIsNone(response.content_type) - self.assertEqual('', response.body) + self.assertEqual(b'', response.body) def test_delete_not_existing_computehost(self): def fake_delete_computehost(*args, **kwargs): raise TypeError("Nah...") expected = { u'error_code': 404, - u'error_message': u"Object with {{'host_id': " - u"u'{0}'}} not found".format(self.id1), + u'error_message': u"not found", u'error_name': 404 } self.patch( @@ -388,7 +388,10 @@ class TestDeleteHost(api.APITest): headers=self.headers) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertEqual(expected, response.json) + self.assertEqual(expected["error_name"], response.json["error_name"]) + self.assertTrue(expected["error_message"] + in response.json["error_message"]) + self.assertEqual(expected["error_code"], response.json["error_code"]) def test_rpc_exception_delete(self): def fake_delete_computehost(*args, **kwargs): diff --git a/blazar/tests/api/v2/test_leases.py b/blazar/tests/api/v2/test_leases.py index 6c58955e..a6730b1d 100644 --- a/blazar/tests/api/v2/test_leases.py +++ b/blazar/tests/api/v2/test_leases.py @@ -145,15 +145,17 @@ class TestShowLease(api.APITest): def test_empty(self): expected = { u'error_code': 404, - u'error_message': u"Object with {{'lease_id': " - u"u'{0}'}} not found".format(self.id1), + u'error_message': u"not found", u'error_name': 404 } self.patch(self.rpcapi, 'get_lease').return_value = None response = self.get_json(self.path, expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertEqual(expected, response.json) + self.assertEqual(expected["error_name"], response.json["error_name"]) + self.assertTrue(expected["error_message"] + in response.json["error_message"]) + self.assertEqual(expected["error_code"], response.json["error_code"]) def test_rpc_exception_get(self): def fake_get_lease(*args, **kwargs): @@ -194,9 +196,7 @@ class TestCreateLease(api.APITest): def test_create_wrong_attr(self): expected = { "error_name": 400, - "error_message": "Invalid input for field/attribute name. " - "Value: '1'. Wrong type. " - "Expected '', got ''", + "error_message": "Invalid input for field/attribute name.", "error_code": 400 } @@ -204,7 +204,10 @@ class TestCreateLease(api.APITest): expect_errors=True) self.assertEqual(400, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertEqual(expected, response.json) + self.assertEqual(expected["error_name"], response.json["error_name"]) + self.assertTrue(expected["error_message"] + in response.json["error_message"]) + self.assertEqual(expected["error_code"], response.json["error_code"]) def test_create_with_empty_body(self): expected = { @@ -298,8 +301,7 @@ class TestUpdateLease(api.APITest): def test_empty_response(self): expected = { u'error_code': 404, - u'error_message': u"Object with {{'lease_id': " - u"u'{0}'}} not found".format(self.id1), + u'error_message': u"not found", u'error_name': 404 } self.patch(self.rpcapi, 'update_lease').return_value = None @@ -307,7 +309,10 @@ class TestUpdateLease(api.APITest): expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertEqual(expected, response.json) + self.assertEqual(expected["error_name"], response.json["error_name"]) + self.assertTrue(expected["error_message"] + in response.json["error_message"]) + self.assertEqual(expected["error_code"], response.json["error_code"]) def test_rpc_exception_update(self): def fake_update_lease(*args, **kwargs): @@ -339,15 +344,14 @@ class TestDeleteLease(api.APITest): response = self.delete(self.path) self.assertEqual(204, response.status_int) self.assertIsNone(response.content_type) - self.assertEqual('', response.body) + self.assertEqual(b'', response.body) def test_delete_not_existing_lease(self): def fake_delete_lease(*args, **kwargs): raise TypeError("Nah...") expected = { u'error_code': 404, - u'error_message': u"Object with {{'lease_id': " - u"u'{0}'}} not found".format(self.id1), + u'error_message': u"not found", u'error_name': 404 } self.patch( @@ -355,7 +359,10 @@ class TestDeleteLease(api.APITest): response = self.delete(self.path, expect_errors=True) self.assertEqual(404, response.status_int) self.assertEqual('application/json', response.content_type) - self.assertEqual(expected, response.json) + self.assertEqual(expected["error_name"], response.json["error_name"]) + self.assertTrue(expected["error_message"] + in response.json["error_message"]) + self.assertEqual(expected["error_code"], response.json["error_code"]) def test_rpc_exception_delete(self): def fake_delete_lease(*args, **kwargs):