Merge "ut updates for extending sub-resources"
This commit is contained in:
commit
335098da60
|
@ -89,3 +89,21 @@ The following are the defined keys for attribute maps:
|
||||||
``enforce_policy`` the attribute is actively part of the policy enforcing mechanism, ie: there might be rules which refer to this attribute
|
``enforce_policy`` the attribute is actively part of the policy enforcing mechanism, ie: there might be rules which refer to this attribute
|
||||||
``primary_key`` Mark the attribute as a unique key.
|
``primary_key`` Mark the attribute as a unique key.
|
||||||
====================== ======
|
====================== ======
|
||||||
|
|
||||||
|
When extending existing sub-resources, the sub-attribute map must define all
|
||||||
|
extension attributes under the ``parameters`` object. This instructs the API
|
||||||
|
internals to add the attributes to the existing sub-resource rather than
|
||||||
|
overwrite its existing definition. For example:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
SUB_RESOURCE_ATTRIBUTE_MAP = {
|
||||||
|
'existing_subresource_to_extend': {
|
||||||
|
'parameters': {
|
||||||
|
'new_attr1': {
|
||||||
|
'allow_post': False,
|
||||||
|
# etc..
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -72,7 +72,10 @@ RESOURCE_ATTRIBUTE_MAP = {
|
||||||
# The subresource attribute map for the extension. It adds child resources
|
# The subresource attribute map for the extension. It adds child resources
|
||||||
# to main extension's resource. The subresource map must have a parent and
|
# to main extension's resource. The subresource map must have a parent and
|
||||||
# a parameters entry. If an extension does not need such a map, None can
|
# a parameters entry. If an extension does not need such a map, None can
|
||||||
# be specified (mandatory). For example:
|
# be specified (mandatory).
|
||||||
|
# Note that if an existing sub-resource is being extended, the
|
||||||
|
# existing resources to extend the new extension attributes must be
|
||||||
|
# defined under the 'parameters' key.
|
||||||
SUB_RESOURCE_ATTRIBUTE_MAP = {
|
SUB_RESOURCE_ATTRIBUTE_MAP = {
|
||||||
'subfoo': {
|
'subfoo': {
|
||||||
'parent': {
|
'parent': {
|
||||||
|
|
|
@ -132,23 +132,36 @@ class DefinitionBaseTestCase(test_base.BaseTestCase):
|
||||||
resource[attribute],
|
resource[attribute],
|
||||||
keyword, value)
|
keyword, value)
|
||||||
|
|
||||||
|
def _assert_subresource(self, subresource):
|
||||||
|
self.assertIn(
|
||||||
|
self.subresource_map[subresource]['parent']['collection_name'],
|
||||||
|
base.KNOWN_RESOURCES + self.extension_resources,
|
||||||
|
'Sub-resource parent is unknown, check for typos.')
|
||||||
|
self.assertIn('member_name',
|
||||||
|
self.subresource_map[subresource]['parent'],
|
||||||
|
'Incorrect parent definition, check for typos.')
|
||||||
|
self.assertParams(self.subresource_map[subresource]['parameters'])
|
||||||
|
|
||||||
def test_subresource_map(self):
|
def test_subresource_map(self):
|
||||||
if not self.subresource_map:
|
if not self.subresource_map:
|
||||||
self.skipTest('API extension has no subresource map.')
|
self.skipTest('API extension has no subresource map.')
|
||||||
for subresource in self.subresource_map:
|
for subresource in self.subresource_map:
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
subresource, self.extension_subresources,
|
subresource,
|
||||||
|
self.extension_subresources + base.KNOWN_RESOURCES,
|
||||||
'Sub-resource is unknown, check for typos.')
|
'Sub-resource is unknown, check for typos.')
|
||||||
for attribute in self.subresource_map[subresource]:
|
sub_attrmap = self.subresource_map[subresource]
|
||||||
self.assertIn(attribute, ('parent', 'parameters'))
|
if 'parent' in sub_attrmap:
|
||||||
self.assertIn(
|
self.assertEqual(2, len(sub_attrmap.keys()))
|
||||||
self.subresource_map[subresource]['parent']['collection_name'],
|
self.assertIn('parent', sub_attrmap)
|
||||||
base.KNOWN_RESOURCES + self.extension_resources,
|
self.assertIn('parameters', sub_attrmap)
|
||||||
'Sub-resource parent is unknown, check for typos.')
|
self._assert_subresource(subresource)
|
||||||
self.assertIn('member_name',
|
else:
|
||||||
self.subresource_map[subresource]['parent'],
|
self.assertEqual(
|
||||||
'Incorrect parent definition, check for typos.')
|
['parameters'], [p for p in sub_attrmap.keys()],
|
||||||
self.assertParams(self.subresource_map[subresource]['parameters'])
|
'When extending sub-resources only use the parameters '
|
||||||
|
'keyword')
|
||||||
|
self.assertParams(sub_attrmap['parameters'])
|
||||||
|
|
||||||
def test_action_map(self):
|
def test_action_map(self):
|
||||||
self.assertIsInstance(self.action_map, dict)
|
self.assertIsInstance(self.action_map, dict)
|
||||||
|
|
Loading…
Reference in New Issue