From 80d1e6c7265a787477a6f9ae06b1da0d7653991c Mon Sep 17 00:00:00 2001 From: jcamiel Date: Fri, 11 Mar 2022 14:20:18 +0100 Subject: [PATCH] Add integration tests on XPath/namespaces. --- integration/tests_ok/assert_xpath.curl | 3 ++ integration/tests_ok/assert_xpath.html | 46 +++++++++++++++++++-- integration/tests_ok/assert_xpath.hurl | 44 ++++++++++++++++++++- integration/tests_ok/assert_xpath.json | 2 +- integration/tests_ok/assert_xpath.out | 14 ++++++- integration/tests_ok/assert_xpath.py | 55 +++++++++++++++++++++++++- 6 files changed, 156 insertions(+), 8 deletions(-) diff --git a/integration/tests_ok/assert_xpath.curl b/integration/tests_ok/assert_xpath.curl index e51e6c98a..bc0539a0e 100644 --- a/integration/tests_ok/assert_xpath.curl +++ b/integration/tests_ok/assert_xpath.curl @@ -1 +1,4 @@ curl 'http://localhost:8000/assert-xpath' +curl 'http://localhost:8000/assert-xpath-simple-namespaces' +curl 'http://localhost:8000/assert-xpath-svg' +curl 'http://localhost:8000/assert-xpath-namespaces' diff --git a/integration/tests_ok/assert_xpath.html b/integration/tests_ok/assert_xpath.html index 3689196ea..c38911966 100644 --- a/integration/tests_ok/assert_xpath.html +++ b/integration/tests_ok/assert_xpath.html @@ -2,9 +2,49 @@ HTTP/1.0 200 [Asserts] -xpath "normalize-space(//data)" equals "café" -xpath "normalize-space(//data)" equals "caf\u{00e9}" +xpath "normalize-space(//data)" == "café" +xpath "normalize-space(//data)" == "caf\u{00e9}" xpath "//toto" not exists <data>café</data> - \ No newline at end of file + + +# Test XPath assert with XML namespace. +GET http://localhost:8000/assert-xpath-simple-namespaces + +HTTP/1.0 200 +[Asserts] + +xpath "string(//bk:book/bk:title)" == "Cheaper by the Dozen" +xpath "string(//*[name()='bk:book']/*[name()='bk:title'])" == "Cheaper by the Dozen" +xpath "string(//*[local-name()='book']/*[local-name()='title'])" == "Cheaper by the Dozen" + +xpath "string(//bk:book/isbn:number)" == "1568491379" +xpath "string(//*[name()='bk:book']/*[name()='isbn:number'])" == "1568491379" +xpath "string(//*[local-name()='book']/*[local-name()='number'])" == "1568491379" + + +# Test XPath assert with default XML namespace. +# _ can be used to target a default namespace. +GET http://localhost:8000/assert-xpath-svg + +HTTP/1.0 200 +[Asserts] +xpath "//_:svg/_:g/_:circle" count == 3 +xpath "//*[local-name()='svg']/*[local-name()='g']/*[local-name()='circle']" count == 3 +xpath "//*[name()='svg']/*[name()='g']/*[name()='circle']" count == 3 + + +# Test XPath assert with default and prefixed XML namespace. +# _ can be used to target a default namespace. +GET http://localhost:8000/assert-xpath-namespaces + +HTTP/1.0 200 +[Asserts] +xpath "string(//_:book/_:title)" == "Cheaper by the Dozen" +xpath "string(//_:book/isbn:number)" == "1568491379" +xpath "//*[name()='book']/*[name()='notes']" count == 1 +xpath "//*[local-name()='book']/*[local-name()='notes']" count == 1 +xpath "//_:book/_:notes/*[local-name()='p']" count == 1 + + \ No newline at end of file diff --git a/integration/tests_ok/assert_xpath.hurl b/integration/tests_ok/assert_xpath.hurl index e24a4ec0d..8320b27f2 100644 --- a/integration/tests_ok/assert_xpath.hurl +++ b/integration/tests_ok/assert_xpath.hurl @@ -2,8 +2,48 @@ GET http://localhost:8000/assert-xpath HTTP/1.0 200 [Asserts] -xpath "normalize-space(//data)" equals "café" -xpath "normalize-space(//data)" equals "caf\u{00e9}" +xpath "normalize-space(//data)" == "café" +xpath "normalize-space(//data)" == "caf\u{00e9}" xpath "//toto" not exists café + + +# Test XPath assert with XML namespace. +GET http://localhost:8000/assert-xpath-simple-namespaces + +HTTP/1.0 200 +[Asserts] + +xpath "string(//bk:book/bk:title)" == "Cheaper by the Dozen" +xpath "string(//*[name()='bk:book']/*[name()='bk:title'])" == "Cheaper by the Dozen" +xpath "string(//*[local-name()='book']/*[local-name()='title'])" == "Cheaper by the Dozen" + +xpath "string(//bk:book/isbn:number)" == "1568491379" +xpath "string(//*[name()='bk:book']/*[name()='isbn:number'])" == "1568491379" +xpath "string(//*[local-name()='book']/*[local-name()='number'])" == "1568491379" + + +# Test XPath assert with default XML namespace. +# _ can be used to target a default namespace. +GET http://localhost:8000/assert-xpath-svg + +HTTP/1.0 200 +[Asserts] +xpath "//_:svg/_:g/_:circle" count == 3 +xpath "//*[local-name()='svg']/*[local-name()='g']/*[local-name()='circle']" count == 3 +xpath "//*[name()='svg']/*[name()='g']/*[name()='circle']" count == 3 + + +# Test XPath assert with default and prefixed XML namespace. +# _ can be used to target a default namespace. +GET http://localhost:8000/assert-xpath-namespaces + +HTTP/1.0 200 +[Asserts] +xpath "string(//_:book/_:title)" == "Cheaper by the Dozen" +xpath "string(//_:book/isbn:number)" == "1568491379" +xpath "//*[name()='book']/*[name()='notes']" count == 1 +xpath "//*[local-name()='book']/*[local-name()='notes']" count == 1 +xpath "//_:book/_:notes/*[local-name()='p']" count == 1 + diff --git a/integration/tests_ok/assert_xpath.json b/integration/tests_ok/assert_xpath.json index 4d9dd9b2c..8afe2ba48 100644 --- a/integration/tests_ok/assert_xpath.json +++ b/integration/tests_ok/assert_xpath.json @@ -1 +1 @@ -{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/assert-xpath"},"response":{"version":"HTTP/1.0","status":200,"asserts":[{"query":{"type":"xpath","expr":"normalize-space(//data)"},"predicate":{"type":"equal","value":"café"}},{"query":{"type":"xpath","expr":"normalize-space(//data)"},"predicate":{"type":"equal","value":"café"}},{"query":{"type":"xpath","expr":"//toto"},"predicate":{"not":true,"type":"exist"}}],"body":{"type":"xml","value":"café"}}}]} +{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/assert-xpath"},"response":{"version":"HTTP/1.0","status":200,"asserts":[{"query":{"type":"xpath","expr":"normalize-space(//data)"},"predicate":{"type":"equal","value":"café"}},{"query":{"type":"xpath","expr":"normalize-space(//data)"},"predicate":{"type":"equal","value":"café"}},{"query":{"type":"xpath","expr":"//toto"},"predicate":{"not":true,"type":"exist"}}],"body":{"type":"xml","value":"café"}}},{"request":{"method":"GET","url":"http://localhost:8000/assert-xpath-simple-namespaces"},"response":{"version":"HTTP/1.0","status":200,"asserts":[{"query":{"type":"xpath","expr":"string(//bk:book/bk:title)"},"predicate":{"type":"equal","value":"Cheaper by the Dozen"}},{"query":{"type":"xpath","expr":"string(//*[name()='bk:book']/*[name()='bk:title'])"},"predicate":{"type":"equal","value":"Cheaper by the Dozen"}},{"query":{"type":"xpath","expr":"string(//*[local-name()='book']/*[local-name()='title'])"},"predicate":{"type":"equal","value":"Cheaper by the Dozen"}},{"query":{"type":"xpath","expr":"string(//bk:book/isbn:number)"},"predicate":{"type":"equal","value":"1568491379"}},{"query":{"type":"xpath","expr":"string(//*[name()='bk:book']/*[name()='isbn:number'])"},"predicate":{"type":"equal","value":"1568491379"}},{"query":{"type":"xpath","expr":"string(//*[local-name()='book']/*[local-name()='number'])"},"predicate":{"type":"equal","value":"1568491379"}}]}},{"request":{"method":"GET","url":"http://localhost:8000/assert-xpath-svg"},"response":{"version":"HTTP/1.0","status":200,"asserts":[{"query":{"type":"xpath","expr":"//_:svg/_:g/_:circle","subquery":{"type":"count"}},"predicate":{"type":"equal","value":3}},{"query":{"type":"xpath","expr":"//*[local-name()='svg']/*[local-name()='g']/*[local-name()='circle']","subquery":{"type":"count"}},"predicate":{"type":"equal","value":3}},{"query":{"type":"xpath","expr":"//*[name()='svg']/*[name()='g']/*[name()='circle']","subquery":{"type":"count"}},"predicate":{"type":"equal","value":3}}]}},{"request":{"method":"GET","url":"http://localhost:8000/assert-xpath-namespaces"},"response":{"version":"HTTP/1.0","status":200,"asserts":[{"query":{"type":"xpath","expr":"string(//_:book/_:title)"},"predicate":{"type":"equal","value":"Cheaper by the Dozen"}},{"query":{"type":"xpath","expr":"string(//_:book/isbn:number)"},"predicate":{"type":"equal","value":"1568491379"}},{"query":{"type":"xpath","expr":"//*[name()='book']/*[name()='notes']","subquery":{"type":"count"}},"predicate":{"type":"equal","value":1}},{"query":{"type":"xpath","expr":"//*[local-name()='book']/*[local-name()='notes']","subquery":{"type":"count"}},"predicate":{"type":"equal","value":1}},{"query":{"type":"xpath","expr":"//_:book/_:notes/*[local-name()='p']","subquery":{"type":"count"}},"predicate":{"type":"equal","value":1}}]}}]} \ No newline at end of file diff --git a/integration/tests_ok/assert_xpath.out b/integration/tests_ok/assert_xpath.out index ba2c18b37..d48e7a126 100644 --- a/integration/tests_ok/assert_xpath.out +++ b/integration/tests_ok/assert_xpath.out @@ -1 +1,13 @@ -café \ No newline at end of file + + + + Cheaper by the Dozen + 1568491379 + + +

+ This is a funny book! +

+
+
diff --git a/integration/tests_ok/assert_xpath.py b/integration/tests_ok/assert_xpath.py index f1d77896f..41e4704bc 100644 --- a/integration/tests_ok/assert_xpath.py +++ b/integration/tests_ok/assert_xpath.py @@ -1,7 +1,60 @@ # coding=utf-8 +from flask import Response from app import app @app.route("/assert-xpath") def assert_xpath(): - return "café" + body = "café" + return Response(body, mimetype="text/xml") + + +@app.route("/assert-xpath-svg") +def assert_xpath_svg(): + body = """ + + + + + + + + + +""" + return Response(body, mimetype="text/xml") + + +@app.route("/assert-xpath-simple-namespaces") +def assert_xpath_simple_ns(): + body = """ + + + Cheaper by the Dozen + 1568491379 + +""" + return Response(body, mimetype="text/xml") + + +@app.route("/assert-xpath-namespaces") +def assert_xpath_ns(): + body = """ + + + Cheaper by the Dozen + 1568491379 + + +

+ This is a funny book! +

+
+
+""" + return Response(body, mimetype="text/xml")