Browse Source

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
changes/88/613688/5
Rick Bartra 9 months ago
parent
commit
88fe773cd7

+ 1
- 1
deckhand/common/document.py View File

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

+ 6
- 18
deckhand/tests/unit/engine/test_document_layering_negative.py View File

@@ -221,31 +221,19 @@ class TestDocumentLayeringNegative(
221 221
         self.assertRaises(
222 222
             errors.InvalidDocumentParent, self._test_layering, documents)
223 223
 
224
-    def test_layering_invalid_layer_order_raises_exc(self):
225
-        """Validate that an invalid layerOrder (which means that the document
224
+    def test_layering_empty_layer_order_raises_exc(self):
225
+        """Validate that an empty layerOrder (which means that the document
226 226
         layer won't be found in the layerOrder) raises an exception.
227 227
         """
228 228
         doc_factory = factories.DocumentFactory(1, [1])
229
-        lp_template, document = doc_factory.gen_test({
230
-            "_GLOBAL_SUBSTITUTIONS_1_": [{
231
-                "dest": {
232
-                    "path": ".c"
233
-                },
234
-                "src": {
235
-                    "schema": "deckhand/Certificate/v1",
236
-                    "name": "global-cert",
237
-                    "path": "."
238
-                }
239
-
240
-            }],
241
-        }, global_abstract=False)
229
+        layering_policy, document = doc_factory.gen_test(
230
+            {}, global_abstract=False)
242 231
 
243
-        layering_policy = copy.deepcopy(lp_template)
244
-        del layering_policy['data']['layerOrder']
232
+        layering_policy['data']['layerOrder'] = []
245 233
         error_re = "layer \'global\' .* was not found in layerOrder.*"
246 234
         self.assertRaisesRegexp(
247 235
             errors.InvalidDocumentLayer, error_re, self._test_layering,
248
-            [layering_policy, document], validate=True)
236
+            [layering_policy, document])
249 237
 
250 238
 
251 239
 class TestDocumentLayeringValidationNegative(

Loading…
Cancel
Save