Use FakeEtcdResult and FakeEtcdMultipleResult from utils
FakeEtcdResult and FakeEtcdMultipleResult have already been defined in zun/tests/unit/db/utils.py[1], so the definition in zun/tests/unit/db/test_container.py[2] is duplicated.We should use those from utils instead. [1]https://github.com/openstack/zun/blob/master/zun/tests/unit/db/utils.py#L242-L255 [2]https://github.com/openstack/zun/blob/master/zun/tests/unit/db/test_container.py#L234-L247 Change-Id: I166661df3ea41cea2cb7cd56473d61314ce7994e
This commit is contained in:
parent
4c279c67e0
commit
a4464b2829
@ -26,6 +26,8 @@ from zun.db import api as dbapi
|
|||||||
from zun.db.etcd.api import EtcdAPI as etcd_api
|
from zun.db.etcd.api import EtcdAPI as etcd_api
|
||||||
from zun.tests.unit.db import base
|
from zun.tests.unit.db import base
|
||||||
from zun.tests.unit.db import utils
|
from zun.tests.unit.db import utils
|
||||||
|
from zun.tests.unit.db.utils import FakeEtcdMultipleResult
|
||||||
|
from zun.tests.unit.db.utils import FakeEtcdResult
|
||||||
|
|
||||||
CONF = zun.conf.CONF
|
CONF = zun.conf.CONF
|
||||||
|
|
||||||
@ -231,22 +233,6 @@ class DbContainerTestCase(base.DbTestCase):
|
|||||||
container.id, {'uuid': ''})
|
container.id, {'uuid': ''})
|
||||||
|
|
||||||
|
|
||||||
class FakeEtcdMutlipleResult(object):
|
|
||||||
|
|
||||||
def __init__(self, value):
|
|
||||||
self.children = []
|
|
||||||
for v in value:
|
|
||||||
res = mock.MagicMock()
|
|
||||||
res.value = json.dumps(v)
|
|
||||||
self.children.append(res)
|
|
||||||
|
|
||||||
|
|
||||||
class FakeEtcdResult(object):
|
|
||||||
|
|
||||||
def __init__(self, value):
|
|
||||||
self.value = json.dumps(value)
|
|
||||||
|
|
||||||
|
|
||||||
class EtcdDbContainerTestCase(base.DbTestCase):
|
class EtcdDbContainerTestCase(base.DbTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -289,7 +275,7 @@ class EtcdDbContainerTestCase(base.DbTestCase):
|
|||||||
def test_get_container_by_name(self, mock_write, mock_read):
|
def test_get_container_by_name(self, mock_write, mock_read):
|
||||||
mock_read.side_effect = etcd.EtcdKeyNotFound
|
mock_read.side_effect = etcd.EtcdKeyNotFound
|
||||||
container = utils.create_test_container(context=self.context)
|
container = utils.create_test_container(context=self.context)
|
||||||
mock_read.side_effect = lambda *args: FakeEtcdMutlipleResult(
|
mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
|
||||||
[container.as_dict()])
|
[container.as_dict()])
|
||||||
res = dbapi.get_container_by_name(
|
res = dbapi.get_container_by_name(
|
||||||
self.context, container.name)
|
self.context, container.name)
|
||||||
@ -317,7 +303,7 @@ class EtcdDbContainerTestCase(base.DbTestCase):
|
|||||||
name='cont' + str(i))
|
name='cont' + str(i))
|
||||||
containers.append(container.as_dict())
|
containers.append(container.as_dict())
|
||||||
uuids.append(six.text_type(container['uuid']))
|
uuids.append(six.text_type(container['uuid']))
|
||||||
mock_read.side_effect = lambda *args: FakeEtcdMutlipleResult(
|
mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
|
||||||
containers)
|
containers)
|
||||||
res = dbapi.list_containers(self.context)
|
res = dbapi.list_containers(self.context)
|
||||||
res_uuids = [r.uuid for r in res]
|
res_uuids = [r.uuid for r in res]
|
||||||
@ -336,7 +322,7 @@ class EtcdDbContainerTestCase(base.DbTestCase):
|
|||||||
name='cont' + str(i))
|
name='cont' + str(i))
|
||||||
containers.append(container.as_dict())
|
containers.append(container.as_dict())
|
||||||
uuids.append(six.text_type(container.uuid))
|
uuids.append(six.text_type(container.uuid))
|
||||||
mock_read.side_effect = lambda *args: FakeEtcdMutlipleResult(
|
mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
|
||||||
containers)
|
containers)
|
||||||
res = dbapi.list_containers(self.context, sort_key='uuid')
|
res = dbapi.list_containers(self.context, sort_key='uuid')
|
||||||
res_uuids = [r.uuid for r in res]
|
res_uuids = [r.uuid for r in res]
|
||||||
@ -361,7 +347,7 @@ class EtcdDbContainerTestCase(base.DbTestCase):
|
|||||||
uuid=uuidutils.generate_uuid(),
|
uuid=uuidutils.generate_uuid(),
|
||||||
context=self.context)
|
context=self.context)
|
||||||
|
|
||||||
mock_read.side_effect = lambda *args: FakeEtcdMutlipleResult(
|
mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
|
||||||
[container1.as_dict(), container2.as_dict()])
|
[container1.as_dict(), container2.as_dict()])
|
||||||
|
|
||||||
res = dbapi.list_containers(
|
res = dbapi.list_containers(
|
||||||
@ -441,7 +427,7 @@ class EtcdDbContainerTestCase(base.DbTestCase):
|
|||||||
uuid=uuidutils.generate_uuid(),
|
uuid=uuidutils.generate_uuid(),
|
||||||
context=self.context)
|
context=self.context)
|
||||||
|
|
||||||
mock_read.side_effect = lambda *args: FakeEtcdMutlipleResult(
|
mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
|
||||||
[container1.as_dict(), container2.as_dict()])
|
[container1.as_dict(), container2.as_dict()])
|
||||||
self.assertRaises(exception.ContainerAlreadyExists,
|
self.assertRaises(exception.ContainerAlreadyExists,
|
||||||
dbapi.update_container, self.context,
|
dbapi.update_container, self.context,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user