Updated tests on bug, when get list returns deleted items
In I4d2f44fa149aee564c62a69822c6ad79de5bba8a we introduced new _get_model_list method that introduces unify way for retrieving models from db. This commit adds tests that do checks on bug 1761956, when selecting with filter() method could return deleted entites. Change-Id: I12df4af70bcc25654a0fb276ea7145d772d891e2 Related-Bug: 1761956
This commit is contained in:
parent
93a8ba804f
commit
d23e7f0f8c
|
@ -326,6 +326,9 @@ class Connection(api.BaseConnection):
|
|||
return _paginate_query(model, limit, marker,
|
||||
sort_key, sort_dir, query)
|
||||
|
||||
# NOTE(erakli): _add_..._filters methods should be refactored to have same
|
||||
# content. join_fieldmap should be filled with JoinMap instead of dict
|
||||
|
||||
def _add_goals_filters(self, query, filters):
|
||||
if filters is None:
|
||||
filters = {}
|
||||
|
|
|
@ -273,7 +273,7 @@ class DbActionTestCase(base.DbTestCase):
|
|||
|
||||
action1 = utils.create_test_action(
|
||||
id=1,
|
||||
action_plan_id=1,
|
||||
action_plan_id=action_plan['id'],
|
||||
description='description action 1',
|
||||
uuid=w_utils.generate_uuid(),
|
||||
parents=None,
|
||||
|
@ -287,11 +287,20 @@ class DbActionTestCase(base.DbTestCase):
|
|||
state=objects.action_plan.State.PENDING)
|
||||
action3 = utils.create_test_action(
|
||||
id=3,
|
||||
action_plan_id=1,
|
||||
action_plan_id=action_plan['id'],
|
||||
description='description action 3',
|
||||
uuid=w_utils.generate_uuid(),
|
||||
parents=[action2['uuid']],
|
||||
state=objects.action_plan.State.ONGOING)
|
||||
action4 = utils.create_test_action(
|
||||
id=4,
|
||||
action_plan_id=action_plan['id'],
|
||||
description='description action 4',
|
||||
uuid=w_utils.generate_uuid(),
|
||||
parents=None,
|
||||
state=objects.action_plan.State.ONGOING)
|
||||
|
||||
self.dbapi.soft_delete_action(action4['uuid'])
|
||||
|
||||
res = self.dbapi.get_action_list(
|
||||
self.context,
|
||||
|
@ -314,6 +323,15 @@ class DbActionTestCase(base.DbTestCase):
|
|||
sorted([action1['id'], action3['id']]),
|
||||
sorted([r.id for r in res]))
|
||||
|
||||
temp_context = self.context
|
||||
temp_context.show_deleted = True
|
||||
res = self.dbapi.get_action_list(
|
||||
temp_context,
|
||||
filters={'action_plan_uuid': action_plan['uuid']})
|
||||
self.assertEqual(
|
||||
sorted([action1['id'], action3['id'], action4['id']]),
|
||||
sorted([r.id for r in res]))
|
||||
|
||||
res = self.dbapi.get_action_list(
|
||||
self.context,
|
||||
filters={'audit_uuid': audit.uuid})
|
||||
|
|
|
@ -269,6 +269,7 @@ class DbActionPlanTestCase(base.DbTestCase):
|
|||
audit_type='ONESHOT',
|
||||
uuid=w_utils.generate_uuid(),
|
||||
state=ap_objects.State.ONGOING)
|
||||
|
||||
action_plan1 = utils.create_test_action_plan(
|
||||
id=1,
|
||||
uuid=w_utils.generate_uuid(),
|
||||
|
@ -279,6 +280,14 @@ class DbActionPlanTestCase(base.DbTestCase):
|
|||
uuid=w_utils.generate_uuid(),
|
||||
audit_id=audit['id'],
|
||||
state=ap_objects.State.ONGOING)
|
||||
action_plan3 = utils.create_test_action_plan(
|
||||
id=3,
|
||||
uuid=w_utils.generate_uuid(),
|
||||
audit_id=audit['id'],
|
||||
state=ap_objects.State.RECOMMENDED)
|
||||
|
||||
# check on bug 1761956
|
||||
self.dbapi.soft_delete_action_plan(action_plan3['uuid'])
|
||||
|
||||
res = self.dbapi.get_action_plan_list(
|
||||
self.context,
|
||||
|
@ -293,7 +302,9 @@ class DbActionPlanTestCase(base.DbTestCase):
|
|||
res = self.dbapi.get_action_plan_list(
|
||||
self.context,
|
||||
filters={'audit_uuid': audit['uuid']})
|
||||
|
||||
self.assertEqual(
|
||||
sorted([action_plan1['id'], action_plan2['id']]),
|
||||
sorted([r.id for r in res]))
|
||||
for r in res:
|
||||
self.assertEqual(audit['id'], r.audit_id)
|
||||
|
||||
|
|
|
@ -299,24 +299,39 @@ class DbAuditTestCase(base.DbTestCase):
|
|||
self.assertEqual(strategy.as_dict(), eager_audit.strategy.as_dict())
|
||||
|
||||
def test_get_audit_list_with_filters(self):
|
||||
goal = utils.create_test_goal(name='DUMMY')
|
||||
|
||||
audit1 = utils.create_test_audit(
|
||||
id=1,
|
||||
audit_type=objects.audit.AuditType.ONESHOT.value,
|
||||
uuid=w_utils.generate_uuid(),
|
||||
name='My Audit {0}'.format(1),
|
||||
state=objects.audit.State.ONGOING)
|
||||
state=objects.audit.State.ONGOING,
|
||||
goal_id=goal['id'])
|
||||
audit2 = utils.create_test_audit(
|
||||
id=2,
|
||||
audit_type='CONTINUOUS',
|
||||
audit_type=objects.audit.AuditType.CONTINUOUS.value,
|
||||
uuid=w_utils.generate_uuid(),
|
||||
state=objects.audit.State.PENDING)
|
||||
name='My Audit {0}'.format(2),
|
||||
state=objects.audit.State.PENDING,
|
||||
goal_id=goal['id'])
|
||||
audit3 = utils.create_test_audit(
|
||||
id=3,
|
||||
audit_type=objects.audit.AuditType.CONTINUOUS.value,
|
||||
uuid=w_utils.generate_uuid(),
|
||||
name='My Audit {0}'.format(3),
|
||||
state=objects.audit.State.ONGOING,
|
||||
goal_id=goal['id'])
|
||||
|
||||
self.dbapi.soft_delete_audit(audit3['uuid'])
|
||||
|
||||
res = self.dbapi.get_audit_list(
|
||||
self.context,
|
||||
filters={'audit_type': objects.audit.AuditType.ONESHOT.value})
|
||||
self.assertEqual([audit1['id']], [r.id for r in res])
|
||||
|
||||
res = self.dbapi.get_audit_list(self.context,
|
||||
res = self.dbapi.get_audit_list(
|
||||
self.context,
|
||||
filters={'audit_type': 'bad-type'})
|
||||
self.assertEqual([], [r.id for r in res])
|
||||
|
||||
|
@ -330,6 +345,20 @@ class DbAuditTestCase(base.DbTestCase):
|
|||
filters={'state': objects.audit.State.PENDING})
|
||||
self.assertEqual([audit2['id']], [r.id for r in res])
|
||||
|
||||
res = self.dbapi.get_audit_list(
|
||||
self.context,
|
||||
filters={'goal_name': 'DUMMY'})
|
||||
self.assertEqual(sorted([audit1['id'], audit2['id']]),
|
||||
sorted([r.id for r in res]))
|
||||
|
||||
temp_context = self.context
|
||||
temp_context.show_deleted = True
|
||||
res = self.dbapi.get_audit_list(
|
||||
temp_context,
|
||||
filters={'goal_name': 'DUMMY'})
|
||||
self.assertEqual(sorted([audit1['id'], audit2['id'], audit3['id']]),
|
||||
sorted([r.id for r in res]))
|
||||
|
||||
def test_get_audit_list_with_filter_by_uuid(self):
|
||||
audit = utils.create_test_audit()
|
||||
res = self.dbapi.get_audit_list(
|
||||
|
|
|
@ -264,6 +264,7 @@ class DbAuditTemplateTestCase(base.DbTestCase):
|
|||
|
||||
def test_get_audit_template_list_with_filters(self):
|
||||
goal = utils.create_test_goal(name='DUMMY')
|
||||
|
||||
audit_template1 = utils.create_test_audit_template(
|
||||
id=1,
|
||||
uuid=w_utils.generate_uuid(),
|
||||
|
@ -276,20 +277,41 @@ class DbAuditTemplateTestCase(base.DbTestCase):
|
|||
name='My Audit Template 2',
|
||||
description='Description of my audit template 2',
|
||||
goal_id=goal['id'])
|
||||
audit_template3 = utils.create_test_audit_template(
|
||||
id=3,
|
||||
uuid=w_utils.generate_uuid(),
|
||||
name='My Audit Template 3',
|
||||
description='Description of my audit template 3',
|
||||
goal_id=goal['id'])
|
||||
|
||||
self.dbapi.soft_delete_audit_template(audit_template3['uuid'])
|
||||
|
||||
res = self.dbapi.get_audit_template_list(
|
||||
self.context, filters={'name': 'My Audit Template 1'})
|
||||
self.context,
|
||||
filters={'name': 'My Audit Template 1'})
|
||||
self.assertEqual([audit_template1['id']], [r.id for r in res])
|
||||
|
||||
res = self.dbapi.get_audit_template_list(
|
||||
self.context, filters={'name': 'Does not exist'})
|
||||
self.context,
|
||||
filters={'name': 'Does not exist'})
|
||||
self.assertEqual([], [r.id for r in res])
|
||||
|
||||
res = self.dbapi.get_audit_template_list(
|
||||
self.context,
|
||||
filters={'goal': 'DUMMY'})
|
||||
self.assertEqual([audit_template1['id'], audit_template2['id']],
|
||||
[r.id for r in res])
|
||||
filters={'goal_name': 'DUMMY'})
|
||||
self.assertEqual(
|
||||
sorted([audit_template1['id'], audit_template2['id']]),
|
||||
sorted([r.id for r in res]))
|
||||
|
||||
temp_context = self.context
|
||||
temp_context.show_deleted = True
|
||||
res = self.dbapi.get_audit_template_list(
|
||||
temp_context,
|
||||
filters={'goal_name': 'DUMMY'})
|
||||
self.assertEqual(
|
||||
sorted([audit_template1['id'], audit_template2['id'],
|
||||
audit_template3['id']]),
|
||||
sorted([r.id for r in res]))
|
||||
|
||||
res = self.dbapi.get_audit_template_list(
|
||||
self.context,
|
||||
|
|
|
@ -285,11 +285,12 @@ class DbEfficacyIndicatorTestCase(base.DbTestCase):
|
|||
audit_id=audit.id,
|
||||
first_efficacy_indicator_id=None,
|
||||
state=objects.action_plan.State.RECOMMENDED)
|
||||
|
||||
efficacy_indicator1 = utils.create_test_efficacy_indicator(
|
||||
id=1,
|
||||
name='indicator_1',
|
||||
uuid=w_utils.generate_uuid(),
|
||||
action_plan_id=1,
|
||||
action_plan_id=action_plan['id'],
|
||||
description='Description efficacy indicator 1',
|
||||
unit='%')
|
||||
efficacy_indicator2 = utils.create_test_efficacy_indicator(
|
||||
|
@ -303,15 +304,27 @@ class DbEfficacyIndicatorTestCase(base.DbTestCase):
|
|||
id=3,
|
||||
name='indicator_3',
|
||||
uuid=w_utils.generate_uuid(),
|
||||
action_plan_id=1,
|
||||
action_plan_id=action_plan['id'],
|
||||
description='Description efficacy indicator 3',
|
||||
unit='%')
|
||||
efficacy_indicator4 = utils.create_test_efficacy_indicator(
|
||||
id=4,
|
||||
name='indicator_4',
|
||||
uuid=w_utils.generate_uuid(),
|
||||
action_plan_id=action_plan['id'],
|
||||
description='Description efficacy indicator 4',
|
||||
unit='%')
|
||||
|
||||
self.dbapi.soft_delete_efficacy_indicator(efficacy_indicator4['uuid'])
|
||||
|
||||
res = self.dbapi.get_efficacy_indicator_list(
|
||||
self.context, filters={'name': 'indicator_3'})
|
||||
self.context,
|
||||
filters={'name': 'indicator_3'})
|
||||
self.assertEqual([efficacy_indicator3['id']], [r.id for r in res])
|
||||
|
||||
res = self.dbapi.get_efficacy_indicator_list(
|
||||
self.context, filters={'unit': 'kWh'})
|
||||
self.context,
|
||||
filters={'unit': 'kWh'})
|
||||
self.assertEqual([], [r.id for r in res])
|
||||
|
||||
res = self.dbapi.get_efficacy_indicator_list(
|
||||
|
|
|
@ -249,13 +249,21 @@ class DbGoalTestCase(base.DbTestCase):
|
|||
name="GOAL_2",
|
||||
display_name='Goal 2',
|
||||
)
|
||||
goal3 = utils.create_test_goal(
|
||||
id=3,
|
||||
uuid=w_utils.generate_uuid(),
|
||||
name="GOAL_3",
|
||||
display_name='Goal 3',
|
||||
)
|
||||
|
||||
res = self.dbapi.get_goal_list(self.context,
|
||||
filters={'display_name': 'Goal 1'})
|
||||
self.dbapi.soft_delete_goal(goal3['uuid'])
|
||||
|
||||
res = self.dbapi.get_goal_list(
|
||||
self.context, filters={'display_name': 'Goal 1'})
|
||||
self.assertEqual([goal1['uuid']], [r.uuid for r in res])
|
||||
|
||||
res = self.dbapi.get_goal_list(self.context,
|
||||
filters={'display_name': 'Goal 3'})
|
||||
res = self.dbapi.get_goal_list(
|
||||
self.context, filters={'display_name': 'Goal 3'})
|
||||
self.assertEqual([], [r.uuid for r in res])
|
||||
|
||||
res = self.dbapi.get_goal_list(
|
||||
|
@ -263,10 +271,13 @@ class DbGoalTestCase(base.DbTestCase):
|
|||
self.assertEqual([goal1['uuid']], [r.uuid for r in res])
|
||||
|
||||
res = self.dbapi.get_goal_list(
|
||||
self.context,
|
||||
filters={'display_name': 'Goal 2'})
|
||||
self.context, filters={'display_name': 'Goal 2'})
|
||||
self.assertEqual([goal2['uuid']], [r.uuid for r in res])
|
||||
|
||||
res = self.dbapi.get_goal_list(
|
||||
self.context, filters={'uuid': goal3['uuid']})
|
||||
self.assertEqual([], [r.uuid for r in res])
|
||||
|
||||
def test_get_goal_by_uuid(self):
|
||||
efficacy_spec = [{"unit": "%", "name": "dummy",
|
||||
"schema": "Range(min=0, max=100, min_included=True, "
|
||||
|
|
|
@ -257,6 +257,15 @@ class DbScoringEngineTestCase(base.DbTestCase):
|
|||
description='ScoringEngine 2',
|
||||
metainfo="a2=b2",
|
||||
)
|
||||
scoring_engine3 = utils.create_test_scoring_engine(
|
||||
id=3,
|
||||
uuid=w_utils.generate_uuid(),
|
||||
name="SE_ID_3",
|
||||
description='ScoringEngine 3',
|
||||
metainfo="a3=b3",
|
||||
)
|
||||
|
||||
self.dbapi.soft_delete_scoring_engine(scoring_engine3['uuid'])
|
||||
|
||||
res = self.dbapi.get_scoring_engine_list(
|
||||
self.context, filters={'description': 'ScoringEngine 1'})
|
||||
|
@ -267,8 +276,7 @@ class DbScoringEngineTestCase(base.DbTestCase):
|
|||
self.assertEqual([], [r.name for r in res])
|
||||
|
||||
res = self.dbapi.get_scoring_engine_list(
|
||||
self.context,
|
||||
filters={'description': 'ScoringEngine 2'})
|
||||
self.context, filters={'description': 'ScoringEngine 2'})
|
||||
self.assertEqual([scoring_engine2['name']], [r.name for r in res])
|
||||
|
||||
def test_get_scoring_engine_by_id(self):
|
||||
|
|
|
@ -252,6 +252,13 @@ class DbServiceTestCase(base.DbTestCase):
|
|||
name="SERVICE_ID_2",
|
||||
host="controller_2",
|
||||
)
|
||||
service3 = utils.create_test_service(
|
||||
id=3,
|
||||
name="SERVICE_ID_3",
|
||||
host="controller_3",
|
||||
)
|
||||
|
||||
self.dbapi.soft_delete_service(service3['id'])
|
||||
|
||||
res = self.dbapi.get_service_list(
|
||||
self.context, filters={'host': 'controller_1'})
|
||||
|
@ -262,8 +269,7 @@ class DbServiceTestCase(base.DbTestCase):
|
|||
self.assertEqual([], [r.id for r in res])
|
||||
|
||||
res = self.dbapi.get_service_list(
|
||||
self.context,
|
||||
filters={'host': 'controller_2'})
|
||||
self.context, filters={'host': 'controller_2'})
|
||||
self.assertEqual([service2['id']], [r.id for r in res])
|
||||
|
||||
def test_get_service_by_name(self):
|
||||
|
|
|
@ -273,6 +273,9 @@ class DbStrategyTestCase(base.DbTestCase):
|
|||
self.assertEqual(goal.as_dict(), eager_strategy.goal.as_dict())
|
||||
|
||||
def test_get_strategy_list_with_filters(self):
|
||||
# NOTE(erakli): we don't create goal in database but links to
|
||||
# goal_id = 1. There is no error in dbapi.create_strategy() method.
|
||||
# Is it right behaviour?
|
||||
strategy1 = utils.create_test_strategy(
|
||||
id=1,
|
||||
uuid=w_utils.generate_uuid(),
|
||||
|
@ -285,6 +288,14 @@ class DbStrategyTestCase(base.DbTestCase):
|
|||
name="STRATEGY_ID_2",
|
||||
display_name='Strategy 2',
|
||||
)
|
||||
strategy3 = utils.create_test_strategy(
|
||||
id=3,
|
||||
uuid=w_utils.generate_uuid(),
|
||||
name="STRATEGY_ID_3",
|
||||
display_name='Strategy 3',
|
||||
)
|
||||
|
||||
self.dbapi.soft_delete_strategy(strategy3['uuid'])
|
||||
|
||||
res = self.dbapi.get_strategy_list(
|
||||
self.context, filters={'display_name': 'Strategy 1'})
|
||||
|
@ -295,14 +306,12 @@ class DbStrategyTestCase(base.DbTestCase):
|
|||
self.assertEqual([], [r.uuid for r in res])
|
||||
|
||||
res = self.dbapi.get_strategy_list(
|
||||
self.context,
|
||||
filters={'goal_id': 1})
|
||||
self.context, filters={'goal_id': 1})
|
||||
self.assertEqual([strategy1['uuid'], strategy2['uuid']],
|
||||
[r.uuid for r in res])
|
||||
|
||||
res = self.dbapi.get_strategy_list(
|
||||
self.context,
|
||||
filters={'display_name': 'Strategy 2'})
|
||||
self.context, filters={'display_name': 'Strategy 2'})
|
||||
self.assertEqual([strategy2['uuid']], [r.uuid for r in res])
|
||||
|
||||
def test_get_strategy_by_uuid(self):
|
||||
|
|
Loading…
Reference in New Issue