Esempio n. 1
0
    def test_resolvePath_attrMissing_returnOrigin(self):
        html = '<img/>'
        res = Parser.resolve_path(html, config.HOST)
        print(res)
        self.assertEqual(res, html)

        html = '<a></a>'
        res = Parser.resolve_path(html, config.HOST)
        print(res)
        self.assertEqual(res, html)
Esempio n. 2
0
    def test_resolvePath_hrefAttrElements_returnFullPath(self):
        html = '<a href="/testing"></a>'
        res = Parser.resolve_path(html, config.HOST)
        print(res)
        self.assertEqual(res, f'<a href="{config.HOST}/testing"></a>')

        html = '<link href="/testing"/>'
        res = Parser.resolve_path(html, config.HOST)
        print(res)
        self.assertEqual(res, f'<link href="{config.HOST}/testing"/>')
Esempio n. 3
0
    def test_resolvePath_srcAttrElements_returnFullPath(self):
        html = '<img src="/testing"/>'
        res = Parser.resolve_path(html, config.HOST)
        print(res)
        self.assertEqual(res, f'<img src="{config.HOST}/testing"/>')

        html = '<iframe src="/testing"></iframe>'
        res = Parser.resolve_path(html, config.HOST)
        print(res)
        self.assertEqual(res, f'<iframe src="{config.HOST}/testing"></iframe>')
Esempio n. 4
0
    def parse(self, entrypoint):
        """ Parse the entry point

            Args:
                entrypoint (str): url of any readable tutorial from HOST

        """

        if not is_valid_hostname(entrypoint):
            raise HostNameError(f'{entrypoint} is not a valid host name')

        meta = Parser.resolve_path(
            Parser.parse(url=entrypoint, section=Section.META), config.HOST)
        table_contents = Parser.resolve_path(
            Parser.parse(url=entrypoint, section=Section.TABLE_CONTENTS),
            config.HOST)

        name = self.__parse_tutorial_name(entrypoint)

        return Tutorial(name, meta, table_contents)
Esempio n. 5
0
    def render(self, tutorial):
        """ Render a single HTML document of tutorial

            Args:
                tutorial (document.Tutorial): tutorial object
            Returns:
                (str): Html document
        """

        if not isinstance(tutorial, Tutorial):
            return

        doc = Renderer.render(document=tutorial)
        doc = Parser.filter(doc)
        doc = Parser.resolve_path(doc, config.HOST)
        return doc
Esempio n. 6
0
 def test_resolvePath_emptyAttr_returnOrigin(self):
     html = '<a href=""></a>'
     res = Parser.resolve_path(html, config.HOST)
     print(res)
     self.assertEqual(res, html)
Esempio n. 7
0
 def test_resolvePath_emptyArg_returnOrigin(self):
     html = ''
     res = Parser.resolve_path(html, '')
     print(res)
     self.assertEqual(res, html)