mirror of
https://github.com/PostHog/posthog.git
synced 2024-12-01 04:12:23 +01:00
80d20e385b
* Clickhouse use elements chain * Fix stuff * Add action tests and start regex * Progress * Progress part deux * Fix everything * Add tag name filtering * Fix funnels * Fix tag name regex * Fix ordering * Fix type issues * Fix empty nth-child * Remove commented code * Split with semicolon and escaped quotes * Specify all select columns
53 lines
2.2 KiB
Python
53 lines
2.2 KiB
Python
from ee.clickhouse.client import sync_execute
|
|
from ee.clickhouse.models.element import chain_to_elements, elements_to_string
|
|
from ee.clickhouse.util import ClickhouseTestMixin
|
|
from posthog.api.test.base import BaseTest
|
|
from posthog.models import Element
|
|
from posthog.models.utils import UUIDT
|
|
|
|
|
|
class TestClickhouseElement(ClickhouseTestMixin, BaseTest):
|
|
def test_elements_to_string(self) -> None:
|
|
self.maxDiff = None
|
|
elements_string = elements_to_string(
|
|
elements=[
|
|
Element(
|
|
tag_name="a",
|
|
href="/a-url",
|
|
attr_class=["small"],
|
|
text="bla bla",
|
|
attributes={"prop": "value", "number": 33, "data-attr": 'something " that; could mess up'},
|
|
nth_child=1,
|
|
nth_of_type=0,
|
|
),
|
|
Element(tag_name="button", attr_class=["btn", "btn-primary"], nth_child=0, nth_of_type=0),
|
|
Element(tag_name="div", nth_child=0, nth_of_type=0),
|
|
Element(tag_name="div", nth_child=0, nth_of_type=0, attr_id="nested",),
|
|
],
|
|
)
|
|
|
|
self.assertEqual(
|
|
elements_string,
|
|
";".join(
|
|
[
|
|
r'a.small:data-attr="something \" that; could mess up"href="/a-url"nth-child="1"nth-of-type="0"number="33"prop="value"text="bla bla"',
|
|
'button.btn.btn-primary:nth-child="0"nth-of-type="0"',
|
|
'div:nth-child="0"nth-of-type="0"',
|
|
'div:attr_id="nested"nth-child="0"nth-of-type="0"',
|
|
]
|
|
),
|
|
)
|
|
|
|
elements = chain_to_elements(elements_string)
|
|
self.assertEqual(elements[0].tag_name, "a")
|
|
self.assertEqual(elements[0].href, "/a-url")
|
|
self.assertEqual(elements[0].attr_class, ["small"])
|
|
self.assertDictEqual(
|
|
elements[0].attributes, {"prop": "value", "number": "33", "data-attr": r"something \" that; could mess up"}
|
|
)
|
|
self.assertEqual(elements[0].nth_child, 1)
|
|
self.assertEqual(elements[0].nth_of_type, 0)
|
|
|
|
self.assertEqual(elements[1].attr_class, ["btn", "btn-primary"])
|
|
self.assertEqual(elements[3].attr_id, "nested")
|