From 0177095b2270bbb7648f272f0cb7505276108f16 Mon Sep 17 00:00:00 2001 From: thomasht86 Date: Wed, 16 Oct 2024 14:01:02 +0200 Subject: [PATCH] add unit test with underscore --- tests/unit/test_configuration.py | 125 ++++++++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 4 deletions(-) diff --git a/tests/unit/test_configuration.py b/tests/unit/test_configuration.py index fabbceb1..f36393c3 100644 --- a/tests/unit/test_configuration.py +++ b/tests/unit/test_configuration.py @@ -18,11 +18,19 @@ class TestVT(unittest.TestCase): def test_sanitize_tag_name(self): self.assertEqual(VT.sanitize_tag_name("content-node"), "content_node") - self.assertEqual(VT.sanitize_tag_name("search-engine"), "search_engine") + self.assertEqual(VT.sanitize_tag_name("from"), "from_") def test_restore_tag_name(self): - self.assertEqual(VT.restore_tag_name("content_node"), "content-node") - self.assertEqual(VT.restore_tag_name("search_engine"), "search-engine") + self.assertEqual(vt("content_node").restore_tag_name(), "content-node") + self.assertEqual(vt("search_engine").restore_tag_name(), "search-engine") + + def test_restore_with_underscores(self): + self.assertEqual( + vt("content_node", replace_underscores=False).tag, "content_node" + ) + self.assertEqual( + vt("search_engine", replace_underscores=False).tag, "search_engine" + ) def test_attrmap(self): self.assertEqual(attrmap("_max_memory"), "max-memory") @@ -39,7 +47,7 @@ def test_single_tag(self): self.assertEqual(str(xml_output), '') def test_nested_tags(self): - nested_tag = VT("content", (VT("document", ()),), {"attr": "value"}) + nested_tag = vt("content", attr="value")(vt("document")) xml_output = to_xml(nested_tag, indent=False) # Expecting nested tags with proper newlines and indentation expected_output = '' @@ -705,5 +713,114 @@ def test_document_expiry(self): self.assertTrue(compare_xml(self.xml_schema, str(generated_xml))) +class TestUnderscoreAttributes(unittest.TestCase): + def setUp(self): + self.xml_schema = """ + + + + + + + + + + + + + + + + + + + <strong> + </strong> + + ... + + + + + 1 + + + + + + + + 2 + 1000 + 500 + 300 + + + +""" + + def test_valid_config_from_string(self): + self.assertTrue(validate_services(self.xml_schema)) + + def test_generate_schema(self): + generated = services( + container( + search(), + document_api(), + document_processing(), + clients( + client( + certificate(file="security/clients.pem"), + id="mtls", + permissions="read,write", + ), + client( + token(id="colpalidemo_write"), + id="token_write", + permissions="read,write", + ), + client( + token(id="colpalidemo_read"), + id="token_read", + permissions="read", + ), + ), + config( + vt("tag")( + vt("bold")( + vt("open", ""), + vt("close", ""), + ), + vt("separator", "..."), + ), + name="container.qr-searchers", + ), + id="colpalidemo_container", + version="1.0", + ), + content( + redundancy("1"), + documents(document(type="pdf_page", mode="index")), + nodes(node(distribution_key="0", hostalias="node1")), + config( + vt("max_matches", "2", replace_underscores=False), + vt("length", "1000"), + vt("surround_max", "500", replace_underscores=False), + vt("min_length", "300", replace_underscores=False), + name="vespa.config.search.summary.juniperrc", + ), + id="colpalidemo_content", + version="1.0", + ), + version="1.0", + ) + generated_xml = generated.to_xml() + # Validate against relaxng + print(self.xml_schema) + print(generated_xml) + self.assertTrue(validate_services(str(generated_xml))) + self.assertTrue(compare_xml(self.xml_schema, str(generated_xml))) + + if __name__ == "__main__": unittest.main()