web/test/unittest_views_embeding.py
author sylvain.thenault@logilab.fr
Tue, 28 Apr 2009 11:22:31 +0200
branchtls-sprint
changeset 1498 2c6eec0b46b9
parent 0 b97547f5f1fa
child 1977 606923dff11b
permissions -rw-r--r--
fix imports, cleanup, repair some ajax calls


from logilab.common.testlib import TestCase, unittest_main

from cubicweb.web.views.embedding import prefix_links

class UILIBTC(TestCase):


    def test_prefix_links(self):
        """suppose we are embedding http://embedded.com/page1.html"""
        orig = ['<a href="http://www.perdu.com">perdu ?</a>',
        '<a href="http://embedded.com/page1.html">perdu ?</a>',
        '<a href="/page2.html">perdu ?</a>',
        '<a href="page3.html">perdu ?</a>',
        '<img src="http://www.perdu.com/img.png"/>',
        '<img src="/img.png"/>',
        '<img src="img.png"/>',
        ]
        expected = ['<a href="PREFIXhttp%3A%2F%2Fwww.perdu.com">perdu ?</a>',
        '<a href="PREFIXhttp%3A%2F%2Fembedded.com%2Fpage1.html">perdu ?</a>',
        '<a href="PREFIXhttp%3A%2F%2Fembedded.com%2Fpage2.html">perdu ?</a>',
        '<a href="PREFIXhttp%3A%2F%2Fembedded.com%2Fpage3.html">perdu ?</a>',
        '<img src="http://www.perdu.com/img.png"/>',
        '<img src="http://embedded.com/img.png"/>',
        '<img src="http://embedded.com/img.png"/>',
        ]
        for orig_a, expected_a in zip(orig, expected):
            got = prefix_links(orig_a, 'PREFIX', 'http://embedded.com/page1.html')
            self.assertEquals(got, expected_a)

if __name__ == '__main__':
    unittest_main()