def test_recursive_extend_schema(self): """ Given - A dict that represents a schema with sub-playbooks When - Run recursive_extend_schema on that schema Then - Ensure The reference is gone from the modified schema - Ensure the 'include' syntax has been replaced by the sub playbook itself """ schema = { 'mapping': { 'inputs': { 'sequence': [{'include': 'input_schema'}], 'type': 'seq'} }, 'some-other-key': 'some-other-value' } sub_schema = { 'mapping': { 'required': {'type': 'bool'}, 'value': {'type': 'any'} }, 'type': 'map'} schema.update({'schema;input_schema': sub_schema}) modified_schema = BaseUpdate.recursive_extend_schema(schema, schema) # Asserting the reference to the sub-playbook no longer exist in the modified schema assert 'schema;input_schema' not in modified_schema # Asserting the sub-playbook has replaced the reference assert modified_schema['mapping']['inputs']['sequence'][0] == sub_schema # Asserting some non related keys are not being deleted assert 'some-other-key' in modified_schema
def test_recursive_extend_schema_prints_warning(self, mocker): """ Given - A dict that represents a schema with sub-schema reference that has no actual sub-schema When - Run recursive_extend_schema on that schema Then - Ensure a warning about the missing sub-schema is printed """ schema = { 'mapping': { 'inputs': { 'sequence': [{'include': 'input_schema'}], 'type': 'seq'} }, } mocker.patch('click.echo') BaseUpdate.recursive_extend_schema(schema, schema) click.echo.assert_called_once_with('Could not find sub-schema for input_schema', LOG_COLORS.YELLOW)