from __future__ import annotations

import xml.etree.ElementTree as ET

from django.test import SimpleTestCase


def assert_xpath_text(
    case: SimpleTestCase,
    root: ET.Element,
    path: str,
    expected: str,
) -> ET.Element:
    element = root.find(path)
    case.assertIsNotNone(element, msg=f"Missing element at xpath: {path}")
    assert element is not None
    case.assertEqual(element.text, expected)
    return element


def assert_xpath_absent(case: SimpleTestCase, root: ET.Element, path: str) -> None:
    case.assertIsNone(root.find(path), msg=f"Element should be absent at xpath: {path}")
