Do not use namedtuple to mock objects
Change-Id: I443ddecc181ed54528c9ffa59f8bc9b91a2a93f3
This commit is contained in:
parent
a3e52b6402
commit
94f8e9644a
|
@ -12,7 +12,6 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import collections
|
||||
import uuid
|
||||
|
||||
from boto import exception as boto_exception
|
||||
|
@ -34,10 +33,6 @@ from ec2api import wsgi
|
|||
|
||||
class ApiInitTestCase(test_base.BaseTestCase):
|
||||
|
||||
fake_context_class = collections.namedtuple('FakeRequestContext',
|
||||
['request_id'])
|
||||
setattr(fake_context_class, 'to_dict', fake_context_class._asdict)
|
||||
|
||||
def setUp(self):
|
||||
super(ApiInitTestCase, self).setUp()
|
||||
|
||||
|
@ -46,7 +41,7 @@ class ApiInitTestCase(test_base.BaseTestCase):
|
|||
self.controller = self.controller_class.return_value
|
||||
self.addCleanup(controller_patcher.stop)
|
||||
|
||||
self.fake_context = self.fake_context_class(str(uuid.uuid4()))
|
||||
self.fake_context = mock.NonCallableMock(request_id=str(uuid.uuid4()))
|
||||
|
||||
ec2_request = apirequest.APIRequest('FakeAction', 'fake_v1',
|
||||
{'Param': 'fake_param'})
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import collections
|
||||
import uuid
|
||||
|
||||
from lxml import etree
|
||||
|
@ -28,11 +27,6 @@ from ec2api.tests.unit import tools
|
|||
|
||||
class EC2RequesterTestCase(test_base.BaseTestCase):
|
||||
|
||||
fake_context_class = collections.namedtuple('FakeContext',
|
||||
['request_id'])
|
||||
fake_request_class = collections.namedtuple('FakeRequest',
|
||||
['params', 'environ'])
|
||||
|
||||
def setUp(self):
|
||||
super(EC2RequesterTestCase, self).setUp()
|
||||
|
||||
|
@ -40,7 +34,7 @@ class EC2RequesterTestCase(test_base.BaseTestCase):
|
|||
self.controller = controller_patcher.start().return_value
|
||||
self.addCleanup(controller_patcher.stop)
|
||||
|
||||
self.fake_context = self.fake_context_class(str(uuid.uuid4()))
|
||||
self.fake_context = mock.NonCallableMock(request_id=str(uuid.uuid4()))
|
||||
|
||||
def test_invoke_returns_data(self):
|
||||
self.controller.fake_action.return_value = fakes.DICT_FAKE_RESULT_DATA
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import collections
|
||||
import copy
|
||||
|
||||
import mock
|
||||
|
@ -581,8 +580,8 @@ class RouteTableTestCase(base.ApiTestCase):
|
|||
fakes.DB_VPC_1, fakes.DB_VPC_2, fakes.DB_IGW_1, fakes.DB_IGW_2,
|
||||
fakes.DB_NETWORK_INTERFACE_1, fakes.DB_NETWORK_INTERFACE_2,
|
||||
fakes.DB_INSTANCE_1)
|
||||
fake_server_class = collections.namedtuple('FakeServer', ['status'])
|
||||
self.nova.servers.get.return_value = fake_server_class('ACTIVE')
|
||||
self.nova.servers.get.return_value = (
|
||||
mock.NonCallableMock(status='ACTIVE'))
|
||||
|
||||
resp = self.execute('DescribeRouteTables', {})
|
||||
self.assertEqual(200, resp['http_status_code'])
|
||||
|
@ -647,8 +646,8 @@ class RouteTableTestCase(base.ApiTestCase):
|
|||
route_table_1, route_table_2, fakes.DB_VPC_1, fakes.DB_VPC_2,
|
||||
igw_1, igw_2, subnet_1, subnet_2,
|
||||
fakes.DB_NETWORK_INTERFACE_1, fakes.DB_NETWORK_INTERFACE_2)
|
||||
fake_server_class = collections.namedtuple('FakeServer', ['status'])
|
||||
self.nova.servers.get.return_value = fake_server_class('DOWN')
|
||||
self.nova.servers.get.return_value = (
|
||||
mock.NonCallableMock(status='DOWN'))
|
||||
resp = self.execute('DescribeRouteTables', {})
|
||||
self.assertEqual(200, resp['http_status_code'])
|
||||
ec2_route_table_1 = copy.deepcopy(fakes.EC2_ROUTE_TABLE_1)
|
||||
|
|
Loading…
Reference in New Issue