From 32ad7095b24e378d91f7f9c480b09e0e844bf780 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Thu, 21 Jan 2021 17:00:15 +0100 Subject: [PATCH] Add tests for document root detection --- server/galaxyls/tests/unit/test_validation.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/server/galaxyls/tests/unit/test_validation.py b/server/galaxyls/tests/unit/test_validation.py index b406be8..0bd9bd0 100644 --- a/server/galaxyls/tests/unit/test_validation.py +++ b/server/galaxyls/tests/unit/test_validation.py @@ -1,6 +1,8 @@ import pytest from lxml import etree +from galaxyls.services.validation import DocumentValidator + from ...services.xsd.constants import TOOL_XSD_FILE from ...services.xsd.validation import GalaxyToolValidationService from .sample_data import ( @@ -62,3 +64,34 @@ def test_validate_macro_file_returns_diagnostics_when_syntax_error(self, xsd_sch actual = service.validate_document(xml_document) assert len(actual) == 1 + + +class TestDocumentValidatorClass: + @pytest.mark.parametrize( + "source, expected", + [ + ("", True), + (" ", True), + ("\n", True), + ("\n ", True), + (" \n ", True), + ("unexpected ", True), + (" unexpected ", True), + ("\nunexpected\n ", True), + ('', True), + ('\n', True), + ("", True), + ('\n', True), + ("", False), + (" ", False), + ("test", False), + ("", False), + ], + ) + def test_has_valid_root_returns_expected(self, source: str, expected: bool) -> None: + document = TestUtils.to_document(source) + validator = DocumentValidator() + + actual = validator.has_valid_root(document) + + assert actual == expected