Add a method to the client unit test that checks for equivalence
and remove the __eq__() and __ne__() methods of secrets and orders
This commit is contained in:
@@ -203,9 +203,9 @@ class Connection(object):
|
||||
|
||||
def create_order(self,
|
||||
mime_type,
|
||||
name=None,
|
||||
algorithm=None,
|
||||
bit_length=None,
|
||||
name=None,
|
||||
cypher_type=None):
|
||||
LOG.debug(_("Creating order of mime_type {0}").format(mime_type))
|
||||
href = "{0}/{1}".format(self._tenant, self.ORDERS_PATH)
|
||||
|
||||
@@ -37,9 +37,3 @@ class Order(object):
|
||||
|
||||
def __str__(self):
|
||||
return "<Order %s>" % self.id
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, Order) and self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
@@ -40,9 +40,3 @@ class Secret(object):
|
||||
|
||||
def __str__(self):
|
||||
return "<Secret %s>" % self.id
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, Secret) and self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
@@ -18,8 +18,8 @@ import unittest
|
||||
|
||||
from mock import MagicMock
|
||||
|
||||
from barbicanclient import client
|
||||
from barbicanclient.common.exceptions import ClientException
|
||||
import barbicanclient.client as client
|
||||
|
||||
|
||||
def suite():
|
||||
@@ -113,7 +113,7 @@ class WhenTestingConnection(unittest.TestCase):
|
||||
bit_length=None,
|
||||
cypher_type=None,
|
||||
expiration=None)
|
||||
self.assertEqual(secret, created)
|
||||
self.assertTrue(self._are_equivalent(secret, created))
|
||||
|
||||
def test_should_create_order(self):
|
||||
body = {"status": "ACTIVE",
|
||||
@@ -140,13 +140,14 @@ class WhenTestingConnection(unittest.TestCase):
|
||||
bit_length=256,
|
||||
algorithm='aes',
|
||||
cypher_type='CDC')
|
||||
self.assertEqual(order, created)
|
||||
self.assertTrue(self._are_equivalent(order, created))
|
||||
|
||||
def test_list_no_secrets(self):
|
||||
body0 = {'secrets': []}
|
||||
secrets = []
|
||||
self.request.return_value.content = json.dumps(body0)
|
||||
self.assertEquals(secrets, self.connection.list_secrets())
|
||||
self.assertTrue(self._are_equivalent(secrets,
|
||||
self.connection.list_secrets()))
|
||||
|
||||
def test_list_single_secret(self):
|
||||
body1 = {'secrets': [{'status': 'ACTIVE',
|
||||
@@ -164,7 +165,8 @@ class WhenTestingConnection(unittest.TestCase):
|
||||
'mime_type': 'text/plain'}]}
|
||||
secrets = [client.Secret(self.connection, body1['secrets'][0])]
|
||||
self.request.return_value.content = json.dumps(body1)
|
||||
self.assertEquals(secrets, self.connection.list_secrets())
|
||||
self.assertTrue(self._are_equivalent(secrets,
|
||||
self.connection.list_secrets()))
|
||||
|
||||
def test_list_multiple_secrets(self):
|
||||
body1 = {'secrets': [{'status': 'ACTIVE',
|
||||
@@ -191,13 +193,15 @@ class WhenTestingConnection(unittest.TestCase):
|
||||
for b in (body1, body2)]
|
||||
body2['secrets'].insert(0, body1['secrets'][0])
|
||||
self.request.return_value.content = json.dumps(body2)
|
||||
self.assertEquals(secrets, self.connection.list_secrets())
|
||||
self.assertTrue(self._are_equivalent(secrets,
|
||||
self.connection.list_secrets()))
|
||||
|
||||
def test_list_no_orders(self):
|
||||
body0 = {'orders': []}
|
||||
orders = []
|
||||
self.request.return_value.content = json.dumps(body0)
|
||||
self.assertEquals(orders, self.connection.list_orders())
|
||||
self.assertTrue(self._are_equivalent(orders,
|
||||
self.connection.list_orders()))
|
||||
|
||||
def test_list_single_order(self):
|
||||
body1 = {'orders': [{'status': 'PENDING',
|
||||
@@ -216,7 +220,8 @@ class WhenTestingConnection(unittest.TestCase):
|
||||
'mime_type': 'text/plain'}}]}
|
||||
orders = [client.Order(self.connection, body1['orders'][0])]
|
||||
self.request.return_value.content = json.dumps(body1)
|
||||
self.assertEquals(orders, self.connection.list_orders())
|
||||
self.assertTrue(self._are_equivalent(orders,
|
||||
self.connection.list_orders()))
|
||||
|
||||
def test_list_multiple_orders(self):
|
||||
body1 = {'orders': [{'status': 'PENDING',
|
||||
@@ -243,7 +248,8 @@ class WhenTestingConnection(unittest.TestCase):
|
||||
for b in (body1, body2)]
|
||||
body2['orders'].insert(0, body1['orders'][0])
|
||||
self.request.return_value.content = json.dumps(body2)
|
||||
self.assertEquals(orders, self.connection.list_orders())
|
||||
self.assertTrue(self._are_equivalent(orders,
|
||||
self.connection.list_orders()))
|
||||
|
||||
def test_should_get_response(self):
|
||||
self._setup_request()
|
||||
@@ -274,6 +280,12 @@ class WhenTestingConnection(unittest.TestCase):
|
||||
self.request.return_value.content = '{"test": "response"}'
|
||||
self.href = 'http://localhost:9311/v1/12345/orders'
|
||||
|
||||
def _are_equivalent(self, a, b):
|
||||
if isinstance(a, list) and isinstance(b, list):
|
||||
return all([self._are_equivalent(x, y) for x, y in zip(a, b)])
|
||||
else:
|
||||
return (a.__dict__ == b.__dict__)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user