Merge "Use stub_out and mock to remove mox: part 1"

This commit is contained in:
Jenkins 2016-01-14 03:11:53 +00:00 committed by Gerrit Code Review
commit 619338f6fa

View File

@ -866,7 +866,7 @@ class DbQuotaDriverTestCase(test.TestCase):
metadata_items=64, metadata_items=64,
injected_file_content_bytes=5 * 1024, injected_file_content_bytes=5 * 1024,
) )
self.stubs.Set(db, 'quota_class_get_default', fake_qcgd) self.stub_out('nova.db.quota_class_get_default', fake_qcgd)
def _stub_quota_class_get_all_by_name(self): def _stub_quota_class_get_all_by_name(self):
# Stub out quota_class_get_all_by_name # Stub out quota_class_get_all_by_name
@ -879,7 +879,7 @@ class DbQuotaDriverTestCase(test.TestCase):
metadata_items=64, metadata_items=64,
injected_file_content_bytes=5 * 1024, injected_file_content_bytes=5 * 1024,
) )
self.stubs.Set(db, 'quota_class_get_all_by_name', fake_qcgabn) self.stub_out('nova.db.quota_class_get_all_by_name', fake_qcgabn)
def test_get_class_quotas(self): def test_get_class_quotas(self):
self._stub_quota_class_get_all_by_name() self._stub_quota_class_get_all_by_name()
@ -952,9 +952,10 @@ class DbQuotaDriverTestCase(test.TestCase):
injected_file_path_bytes=dict(in_use=0, reserved=0), injected_file_path_bytes=dict(in_use=0, reserved=0),
) )
self.stubs.Set(db, 'quota_get_all_by_project_and_user', fake_qgabpau) self.stub_out('nova.db.quota_get_all_by_project_and_user',
self.stubs.Set(db, 'quota_get_all_by_project', fake_qgabp) fake_qgabpau)
self.stubs.Set(db, 'quota_usage_get_all_by_project_and_user', self.stub_out('nova.db.quota_get_all_by_project', fake_qgabp)
self.stub_out('nova.db.quota_usage_get_all_by_project_and_user',
fake_qugabpau) fake_qugabpau)
self._stub_quota_class_get_all_by_name() self._stub_quota_class_get_all_by_name()
@ -1054,7 +1055,7 @@ class DbQuotaDriverTestCase(test.TestCase):
return dict( return dict(
test_resource=dict(in_use=20, reserved=10), test_resource=dict(in_use=20, reserved=10),
) )
self.stubs.Set(db, 'quota_get', fake_quota_get) self.stub_out('nova.db.quota_get', fake_quota_get)
def test_get_by_project_and_user(self): def test_get_by_project_and_user(self):
self._stub_get_by_project_and_user_specific() self._stub_get_by_project_and_user_specific()
@ -1099,9 +1100,9 @@ class DbQuotaDriverTestCase(test.TestCase):
sqa_models.ProjectUserQuota(resource='cores', sqa_models.ProjectUserQuota(resource='cores',
hard_limit=2)] hard_limit=2)]
self.stubs.Set(db, 'quota_get_all_by_project', fake_qgabp) self.stub_out('nova.db.quota_get_all_by_project', fake_qgabp)
self.stubs.Set(db, 'quota_usage_get_all_by_project', fake_qugabp) self.stub_out('nova.db.quota_usage_get_all_by_project', fake_qugabp)
self.stubs.Set(db, 'quota_get_all', fake_quota_get_all) self.stub_out('nova.db.quota_get_all', fake_quota_get_all)
self._stub_quota_class_get_all_by_name() self._stub_quota_class_get_all_by_name()
self._stub_quota_class_get_default() self._stub_quota_class_get_default()
@ -1815,7 +1816,7 @@ class DbQuotaDriverTestCase(test.TestCase):
self.calls.append('quota_get_all_by_project') self.calls.append('quota_get_all_by_project')
return {'floating_ips': 20} return {'floating_ips': 20}
def fake_get_project_quotas(context, resources, project_id, def fake_get_project_quotas(dbdrv, context, resources, project_id,
quota_class=None, defaults=True, quota_class=None, defaults=True,
usages=True, remains=False, usages=True, remains=False,
project_quotas=None): project_quotas=None):
@ -1842,7 +1843,7 @@ class DbQuotaDriverTestCase(test.TestCase):
'reserved': reserved, 'remains': remains} 'reserved': reserved, 'remains': remains}
return result return result
def fake_process_quotas_in_get_user_quotas(context, resources, def fake_process_quotas_in_get_user_quotas(dbdrv, context, resources,
project_id, quotas, project_id, quotas,
quota_class=None, quota_class=None,
defaults=True, usages=None, defaults=True, usages=None,
@ -1866,13 +1867,13 @@ class DbQuotaDriverTestCase(test.TestCase):
self.calls.append('quota_get_all_by_project_and_user') self.calls.append('quota_get_all_by_project_and_user')
return {'instances': 2, 'cores': -1} return {'instances': 2, 'cores': -1}
self.stubs.Set(db, 'quota_get_all_by_project', self.stub_out('nova.db.quota_get_all_by_project',
fake_quota_get_all_by_project) fake_quota_get_all_by_project)
self.stubs.Set(self.driver, 'get_project_quotas', self.stub_out('nova.quota.DbQuotaDriver.get_project_quotas',
fake_get_project_quotas) fake_get_project_quotas)
self.stubs.Set(self.driver, '_process_quotas', self.stub_out('nova.quota.DbQuotaDriver._process_quotas',
fake_process_quotas_in_get_user_quotas) fake_process_quotas_in_get_user_quotas)
self.stubs.Set(db, 'quota_get_all_by_project_and_user', self.stub_out('nova.db.quota_get_all_by_project_and_user',
fake_qgabpau) fake_qgabpau)
def test_get_settable_quotas_with_user(self): def test_get_settable_quotas_with_user(self):
@ -2087,14 +2088,14 @@ class DbQuotaDriverTestCase(test.TestCase):
}) })
def _stub_get_project_quotas(self): def _stub_get_project_quotas(self):
def fake_get_project_quotas(context, resources, project_id, def fake_get_project_quotas(dbdrv, context, resources, project_id,
quota_class=None, defaults=True, quota_class=None, defaults=True,
usages=True, remains=False, usages=True, remains=False,
project_quotas=None): project_quotas=None):
self.calls.append('get_project_quotas') self.calls.append('get_project_quotas')
return {k: dict(limit=v.default) for k, v in resources.items()} return {k: dict(limit=v.default) for k, v in resources.items()}
self.stubs.Set(self.driver, 'get_project_quotas', self.stub_out('nova.quota.DbQuotaDriver.get_project_quotas',
fake_get_project_quotas) fake_get_project_quotas)
def test_get_quotas_has_sync_unknown(self): def test_get_quotas_has_sync_unknown(self):
@ -2217,7 +2218,7 @@ class DbQuotaDriverTestCase(test.TestCase):
self.calls.append(('quota_reserve', expire, until_refresh, self.calls.append(('quota_reserve', expire, until_refresh,
max_age)) max_age))
return ['resv-1', 'resv-2', 'resv-3'] return ['resv-1', 'resv-2', 'resv-3']
self.stubs.Set(db, 'quota_reserve', fake_quota_reserve) self.stub_out('nova.db.quota_reserve', fake_quota_reserve)
def test_reserve_bad_expire(self): def test_reserve_bad_expire(self):
self._stub_get_project_quotas() self._stub_get_project_quotas()
@ -2325,7 +2326,7 @@ class DbQuotaDriverTestCase(test.TestCase):
resource, kwargs)) resource, kwargs))
if resource == 'nonexist': if resource == 'nonexist':
raise exception.QuotaUsageNotFound(project_id=project_id) raise exception.QuotaUsageNotFound(project_id=project_id)
self.stubs.Set(db, 'quota_usage_update', fake_quota_usage_update) self.stub_out('nova.db.quota_usage_update', fake_quota_usage_update)
ctx = FakeContext('test_project', 'test_class') ctx = FakeContext('test_project', 'test_class')
resources = ['res1', 'res2', 'nonexist', 'res4'] resources = ['res1', 'res2', 'nonexist', 'res4']
@ -2473,11 +2474,13 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase):
return reservation_ref return reservation_ref
self.stubs.Set(sqa_api, 'get_session', fake_get_session) self.stub_out('nova.db.sqlalchemy.api.get_session', fake_get_session)
self.stubs.Set(sqa_api, '_get_project_user_quota_usages', self.stub_out('nova.db.sqlalchemy.api._get_project_user_quota_usages',
fake_get_project_user_quota_usages) fake_get_project_user_quota_usages)
self.stubs.Set(sqa_api, '_quota_usage_create', fake_quota_usage_create) self.stub_out('nova.db.sqlalchemy.api._quota_usage_create',
self.stubs.Set(sqa_api, '_reservation_create', fake_reservation_create) fake_quota_usage_create)
self.stub_out('nova.db.sqlalchemy.api._reservation_create',
fake_reservation_create)
self.useFixture(test.TimeOverride()) self.useFixture(test.TimeOverride())