from django.test import SimpleTestCase from netbox_utilities.svg_export import strip_svg_hyperlinks class StripSvgHyperlinksTest(SimpleTestCase): def test_unwraps_anchor_elements_keeping_children(self): svg = ( '' '' '' "" "" ) result = strip_svg_hyperlinks(svg) self.assertNotIn("' '' "" ) result = strip_svg_hyperlinks(svg) self.assertNotIn("href", result) self.assertIn("' '' "" ) result = strip_svg_hyperlinks(svg) self.assertIn("/media/devicetype-images/example.png", result) def test_replaces_image_href_with_data_uri_from_loader(self): svg = ( '' '' "" ) result = strip_svg_hyperlinks(svg, image_loader=lambda href: "data:image/png;base64,AAAA") self.assertIn("data:image/png;base64,AAAA", result) self.assertNotIn("/media/devicetype-images/example.png", result) def test_drops_image_href_when_loader_cannot_resolve_it(self): svg = ( '' '' "" ) result = strip_svg_hyperlinks(svg, image_loader=lambda href: None) self.assertNotIn("href", result) self.assertIn("' '' '' '' "" ) result = strip_svg_hyperlinks(svg) self.assertLess(result.index('id="before"'), result.index('id="linked"')) self.assertLess(result.index('id="linked"'), result.index('id="after"')) def test_leaves_svg_without_links_unchanged_in_content(self): svg = '' result = strip_svg_hyperlinks(svg) self.assertIn("