Added goal+strategy ObjectField for AuditTemplate
In this changeset, I added the "goal" and the "strategy "ObjectField which can either be loaded by setting the new "eager" parameter as True or not loaded (as before) by setting it to False. The advantage of introducing this eager parameter is that this way, we can reduce to a minimum the overhead of DB queries whenever the related goal is not actually needed. Change-Id: I97418163f68aea2f1cda80be94e4035f0b3700ae Partially-Implements: blueprint watcher-versioned-objects
This commit is contained in:
@@ -305,6 +305,7 @@ class TestPatch(FunctionalTestWithSetup):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPatch, self).setUp()
|
||||
obj_utils.create_test_goal(self.context)
|
||||
self.audit_template = obj_utils.create_test_audit_template(
|
||||
self.context, strategy_id=None)
|
||||
|
||||
@@ -598,6 +599,7 @@ class TestDelete(api_base.FunctionalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestDelete, self).setUp()
|
||||
obj_utils.create_test_goal(self.context)
|
||||
self.audit_template = obj_utils.create_test_audit_template(
|
||||
self.context)
|
||||
|
||||
@@ -656,7 +658,7 @@ class TestDelete(api_base.FunctionalTest):
|
||||
self.assertTrue(response.json['error_message'])
|
||||
|
||||
|
||||
class TestAuaditTemplatePolicyEnforcement(api_base.FunctionalTest):
|
||||
class TestAuditTemplatePolicyEnforcement(api_base.FunctionalTest):
|
||||
|
||||
def _common_policy_check(self, rule, func, *arg, **kwarg):
|
||||
self.policy.set_rules({
|
||||
@@ -676,6 +678,7 @@ class TestAuaditTemplatePolicyEnforcement(api_base.FunctionalTest):
|
||||
expect_errors=True)
|
||||
|
||||
def test_policy_disallow_get_one(self):
|
||||
obj_utils.create_test_goal(self.context)
|
||||
audit_template = obj_utils.create_test_audit_template(self.context)
|
||||
self._common_policy_check(
|
||||
"audit_template:get", self.get_json,
|
||||
@@ -689,6 +692,7 @@ class TestAuaditTemplatePolicyEnforcement(api_base.FunctionalTest):
|
||||
expect_errors=True)
|
||||
|
||||
def test_policy_disallow_update(self):
|
||||
obj_utils.create_test_goal(self.context)
|
||||
audit_template = obj_utils.create_test_audit_template(self.context)
|
||||
self._common_policy_check(
|
||||
"audit_template:update", self.patch_json,
|
||||
@@ -713,6 +717,7 @@ class TestAuaditTemplatePolicyEnforcement(api_base.FunctionalTest):
|
||||
audit_template_dict, expect_errors=True)
|
||||
|
||||
def test_policy_disallow_delete(self):
|
||||
obj_utils.create_test_goal(self.context)
|
||||
audit_template = obj_utils.create_test_audit_template(self.context)
|
||||
self._common_policy_check(
|
||||
"audit_template:delete", self.delete,
|
||||
|
||||
@@ -78,9 +78,9 @@ class TestListAudit(api_base.FunctionalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestListAudit, self).setUp()
|
||||
obj_utils.create_test_audit_template(self.context)
|
||||
obj_utils.create_test_goal(self.context)
|
||||
obj_utils.create_test_strategy(self.context)
|
||||
obj_utils.create_test_audit_template(self.context)
|
||||
|
||||
def test_empty(self):
|
||||
response = self.get_json('/audits')
|
||||
@@ -249,6 +249,8 @@ class TestPatch(api_base.FunctionalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPatch, self).setUp()
|
||||
obj_utils.create_test_goal(self.context)
|
||||
obj_utils.create_test_strategy(self.context)
|
||||
obj_utils.create_test_audit_template(self.context)
|
||||
self.audit = obj_utils.create_test_audit(self.context, )
|
||||
p = mock.patch.object(db_api.BaseConnection, 'update_audit')
|
||||
@@ -345,9 +347,9 @@ class TestPost(api_base.FunctionalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPost, self).setUp()
|
||||
obj_utils.create_test_audit_template(self.context)
|
||||
obj_utils.create_test_goal(self.context)
|
||||
obj_utils.create_test_strategy(self.context)
|
||||
obj_utils.create_test_audit_template(self.context)
|
||||
p = mock.patch.object(db_api.BaseConnection, 'create_audit')
|
||||
self.mock_create_audit = p.start()
|
||||
self.mock_create_audit.side_effect = (
|
||||
@@ -640,6 +642,8 @@ class TestDelete(api_base.FunctionalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestDelete, self).setUp()
|
||||
obj_utils.create_test_goal(self.context)
|
||||
obj_utils.create_test_strategy(self.context)
|
||||
obj_utils.create_test_audit_template(self.context)
|
||||
self.audit = obj_utils.create_test_audit(self.context)
|
||||
p = mock.patch.object(db_api.BaseConnection, 'update_audit')
|
||||
@@ -677,7 +681,7 @@ class TestDelete(api_base.FunctionalTest):
|
||||
self.assertTrue(response.json['error_message'])
|
||||
|
||||
|
||||
class TestAuaditPolicyEnforcement(api_base.FunctionalTest):
|
||||
class TestAuditPolicyEnforcement(api_base.FunctionalTest):
|
||||
|
||||
def _common_policy_check(self, rule, func, *arg, **kwarg):
|
||||
self.policy.set_rules({
|
||||
|
||||
Reference in New Issue
Block a user