def test_lint_warns_P003(*args): warn_lint = ['P003'] config.set_primary_repo('../pegleg/site_yamls/') with mock.patch.object(lint, '_verify_no_unexpected_files') as mock_method: lint.full(False, [], warn_lint) mock_method.assert_called()
def test_lint_warns_P002(*args): warn_lint = ['P002'] config.set_primary_repo('../pegleg/site_yamls/') with mock.patch.object(lint, '_verify_deckhand_render') as mock_method: lint.full(False, [], warn_lint) mock_method.assert_called()
def test_lint_excludes_P003(*args): exclude_lint = ['P003'] with mock.patch.object(lint, '_verify_no_unexpected_files', return_value=[('P003', 'test message') ]) as mock_method: lint.full(False, exclude_lint, []) mock_method.assert_called()
def test_lint_excludes_P002(*args): exclude_lint = ['P002'] config.set_primary_repo('../pegleg/site_yamls/') with mock.patch.object(lint, '_verify_deckhand_render', return_value=[('P002', 'test message') ]) as mock_method: lint.full(False, exclude_lint, []) mock_method.assert_called()
def test_lint_warns_P005(self, mock_layering): """Test warn flag for P005 - Deckhand rendering exception.""" # Make Deckhand render expected exception to trigger error code. mock_layering.DocumentLayering.return_value.render.side_effect = ( dh_errors.DeckhandException) exclude_lint = self._exclude_all(except_code='P005') warn_lint = ['P005'] config.set_site_repo(self.site_yaml_path) documents = { mock.sentinel.site: [ { "schema": "deckhand/DataSchema/v1", "metadata": { "name": mock.sentinel.document_name }, "data": {} } ] } with mock.patch( 'pegleg.engine.util.definition.documents_for_each_site', autospec=True, return_value=documents): result = lint.full( False, exclude_lint=exclude_lint, warn_lint=warn_lint) assert len(result) == 1 assert result[0].startswith(warn_lint[0])
def test_lint_warns_P004(self, mock_layering): """Test warn flag for P004 - Duplicate Deckhand DataSchema document detected. """ # Stub out Deckhand render logic. mock_layering.DocumentLayering.return_value.render.return_value = [] exclude_lint = self._exclude_all(except_code='P004') warn_lint = ['P004'] config.set_site_repo(self.site_yaml_path) documents = { mock.sentinel.site: [ { # Create 2 duplicate DataSchema documents. "schema": "deckhand/DataSchema/v1", "metadata": { "name": mock.sentinel.document_name }, "data": {} } ] * 2 } with mock.patch( 'pegleg.engine.util.definition.documents_for_each_site', autospec=True, return_value=documents): result = lint.full( False, exclude_lint=exclude_lint, warn_lint=warn_lint) assert len(result) == 1 assert result[0].startswith(warn_lint[0])
def test_lint_warns_P001(*args): warn_lint = ['P001'] config.set_primary_repo('../pegleg/site_yamls/') code_1 = 'X001' msg_1 = 'is a secret, but has unexpected storagePolicy: "cleartext"' code_2 = 'X002' msg_2 = 'test msg' msgs = [(code_1, msg_1), (code_2, msg_2)] with mock.patch.object(lint, '_verify_file_contents', return_value=msgs) as mock_methed: with pytest.raises(click.ClickException) as expected_exc: lint.full(False, [], warn_lint) assert msg_1 not in expected_exc assert msg_2 in expected_exc
def test_lint_excludes_P001(self, *args): """Test exclude flag for P001 - Document has storagePolicy cleartext (expected is encrypted) yet its schema is a mandatory encrypted type. """ exclude_lint = ['P001'] config.set_site_repo(self.site_yaml_path) code_1 = 'X001' msg_1 = 'is a secret, but has unexpected storagePolicy: "cleartext"' code_2 = 'X002' msg_2 = 'test msg' msgs = [(code_1, msg_1), (code_2, msg_2)] with mock.patch.object(lint, '_verify_file_contents', return_value=msgs) as mock_methed: with pytest.raises(click.ClickException) as expected_exc: lint.full(False, exclude_lint, []) assert msg_1 in expected_exc assert msg_2 in expected_exc
def test_lint_excludes_P003(self, *args): """Test exclude flag for P003 - All repos contain expected directories. """ exclude_lint = ['P003'] with mock.patch.object(lint, '_verify_no_unexpected_files', return_value=[('P003', 'test message') ]) as mock_method: result = lint.full(False, exclude_lint, []) mock_method.assert_called() assert not result # Exclude doesn't return anything.
def test_lint_warns_P003(self, *args): """Test warn flag for P003 - All repos contain expected directories.""" exclude_lint = self._exclude_all(except_code='P003') warn_lint = ['P003'] config.set_site_repo(self.site_yaml_path) with mock.patch.object(lint, '_verify_no_unexpected_files') as mock_method: result = lint.full( False, exclude_lint=exclude_lint, warn_lint=warn_lint) mock_method.assert_called() assert len(result) == 1 assert result[0].startswith(warn_lint[0])
def test_lint_warns_P006(self, tmpdir): """Test warn flag for P006 - YAML file missing document header.""" exclude_lint = self._exclude_all(except_code='P006') warn_lint = ['P006'] config.set_site_repo(self.site_yaml_path) p = tmpdir.mkdir(self.__class__.__name__).join("test.yaml") p.write("foo: bar") with mock.patch('pegleg.engine.util.files.all', autospec=True, return_value=[p.strpath]): result = lint.full( False, exclude_lint=exclude_lint, warn_lint=warn_lint) assert len(result) == 1 assert result[0].startswith(warn_lint[0])
def test_lint_warns_P007(self, tmpdir): """Test warn flag for P007 - YAML file is not valid YAML.""" exclude_lint = self._exclude_all(except_code='P007') warn_lint = ['P007'] config.set_site_repo(self.site_yaml_path) p = tmpdir.mkdir(self.__class__.__name__).join("test.yaml") # Invalid YAML - will trigger error. p.write("---\nfoo: bar: baz") with mock.patch('pegleg.engine.util.files.all', autospec=True, return_value=[p.strpath]): result = lint.full( False, exclude_lint=exclude_lint, warn_lint=warn_lint) assert len(result) == 1 assert result[0].startswith(warn_lint[0])