Fix document is_control method

The document.py `is_control` method incorrectly checks if a document
is a Control document. Per the documentation [0], Control documents
have `metadata.schema` of `metadata/Control/v1`. This commit updates
the `is_control` method to correctly check for Control documents.

[0] 1d4cc81dfa/doc/source/users/document-types.rst (control-documents)

Change-Id: I60ca8f31a61987b4e756784fce0f5a751639ae9e
This commit is contained in:
Rick Bartra 2018-10-21 21:24:41 -04:00
parent 464d2c0ea5
commit 88fe773cd7
2 changed files with 7 additions and 19 deletions

View File

@ -75,7 +75,7 @@ class DocumentDict(dict):
@property @property
def is_control(self): def is_control(self):
return self.schema.startswith('deckhand/Control') return self.metadata.get('schema', '').startswith('metadata/Control')
@property @property
def layering_definition(self): def layering_definition(self):

View File

@ -221,31 +221,19 @@ class TestDocumentLayeringNegative(
self.assertRaises( self.assertRaises(
errors.InvalidDocumentParent, self._test_layering, documents) errors.InvalidDocumentParent, self._test_layering, documents)
def test_layering_invalid_layer_order_raises_exc(self): def test_layering_empty_layer_order_raises_exc(self):
"""Validate that an invalid layerOrder (which means that the document """Validate that an empty layerOrder (which means that the document
layer won't be found in the layerOrder) raises an exception. layer won't be found in the layerOrder) raises an exception.
""" """
doc_factory = factories.DocumentFactory(1, [1]) doc_factory = factories.DocumentFactory(1, [1])
lp_template, document = doc_factory.gen_test({ layering_policy, document = doc_factory.gen_test(
"_GLOBAL_SUBSTITUTIONS_1_": [{ {}, global_abstract=False)
"dest": {
"path": ".c"
},
"src": {
"schema": "deckhand/Certificate/v1",
"name": "global-cert",
"path": "."
}
}], layering_policy['data']['layerOrder'] = []
}, global_abstract=False)
layering_policy = copy.deepcopy(lp_template)
del layering_policy['data']['layerOrder']
error_re = "layer \'global\' .* was not found in layerOrder.*" error_re = "layer \'global\' .* was not found in layerOrder.*"
self.assertRaisesRegexp( self.assertRaisesRegexp(
errors.InvalidDocumentLayer, error_re, self._test_layering, errors.InvalidDocumentLayer, error_re, self._test_layering,
[layering_policy, document], validate=True) [layering_policy, document])
class TestDocumentLayeringValidationNegative( class TestDocumentLayeringValidationNegative(