Ejemplo n.º 1
0
 def test_meta(self):
     """Test the adding of meta tag to the beginning of the head element.
     This looks like: <meta charset="UTF-8" />"""
     meta_class = hr.Meta(charset="UTF-8")
     file_contents = render_result(meta_class).strip()
     assert "<meta charset=\"UTF-8\"/>" in file_contents
     print(file_contents)
def step8and9():
    """ Steps 8 and 9 """

    page = hr.Html()
    head = hr.Head()
    head.append(hr.Meta(charset="UTF-8"))
    head.append(hr.Title("PythonClass = Revision 1087:"))
    page.append(head)
    body = hr.Body()
    body.append(hr.H(2, "PythonClass - Class 6 example"))
    body.append(
        hr.P(
            "Here is a paragraph of text -- there could be more of them, "
            "but this is enough to show that we can do some text",
            style="text-align: center; font-style: oblique;"))
    body.append(hr.Hr())
    list = hr.Ul(id="TheList", style="line-height:200%")
    list.append(hr.Li("The first item in a list"))
    list.append(hr.Li("This is the second item", style="color: red"))
    item = hr.Li()
    item.append("And this is a")
    item.append(hr.A("http://google.com", "link"))
    item.append("to google")
    list.append(item)
    body.append(list)
    page.append(body)

    render_page(page, "test_html_output8.html")
    render_page(page, "test_html_output9.html", "    ")
def test_Meta():
    eval = html_render.Meta(charset="TESTING")
    f = StringIO()
    eval.render(f)
    actual = f.getvalue()
    expected = '<meta charset="TESTING" />\n'
    assert actual == expected
Ejemplo n.º 4
0
    def setUp(self):
        self.test = hr.Meta()
        self.f = StringIO()

        def test_meta(self):
            self.assertEqual(self.test.render(self.f, cur_ind=''),
                             '<meta charset=UTF-8 />')
def test_meta_element():
    f = StringIO()
    test_meta = h.Meta()
    test_meta.render(f)
    page = f.getvalue()
    expected_page = '<meta />\n'
    assert page == expected_page
Ejemplo n.º 6
0
def test_Meta():
    e = hr.Meta(charset="UTF-8")
    f = StringIO()
    e.render(f)
    f.seek(0)
    text = f.read().strip()
    assert text == '<meta charset="UTF-8" />'
Ejemplo n.º 7
0
def test_SelfClosing_Meta():
    e = hr.Meta()
    f = StringIO()
    e.render(f)
    f.seek(0)
    text = f.read().strip()
    assert text.startswith('<meta charset="UTF-8" />')
def test_Html_Head_Meta_Title_Body_H_P_Hr_Ul_Li_A_real_Content_charset_style_id(
):
    page = hr.Html()
    head = hr.Head()
    head.append(hr.Meta(charset="UTF-8"))
    head.append(hr.Title("PythonClass = Revision 1087:"))
    page.append(head)
    body = hr.Body()
    body.append(hr.H(2, "PythonClass - Example"))
    body.append(
        hr.P(
            "Here is a paragraph of text -- there could be more of them, "
            "but this is enough  to show that we can do some text",
            style="text-align: center; font-style: oblique;"))
    body.append(hr.Hr())
    list = hr.Ul(id="TheList", style="line-height:200%")
    list.append(hr.Li("The first item in a list"))
    list.append(hr.Li("This is the second item", style="color: red"))
    item = hr.Li()
    item.append("And this is a ")
    item.append(hr.A("http://google.com", "link"))
    item.append("to google")
    list.append(item)
    body.append(list)
    page.append(body)
    render_page(page, "page.html")
    testdata = open("page.html").read()
    assert testdata == "<html>\n    <head>\n        <meta charset=\"UTF-8\" />\n        <title>PythonClass = Revision 1087:</title>\n    </head>\n    <body>\n        <h2>PythonClass - Example</h2>\n        <p style=\"text-align: center; font-style: oblique;\">\n            Here is a paragraph of text -- there could be more of them, but this is enough  to show that we can do some text\n        </p>\n        <hr />\n        <ul id=\"TheList\" style=\"line-height:200%\">\n            <li>\n                The first item in a list\n            </li>\n            <li style=\"color: red\">\n                This is the second item\n            </li>\n            <li>\n                And this is a \n                <a href=\"http://google.com\">link</a>\n                to google\n            </li>\n        </ul>\n    </body>\n</html>"
Ejemplo n.º 9
0
 def test_8_Meta(self):
     f = StringIO()
     h = hr.Meta(charset="UTF-8")
     h.render(f)
     actual = f.getvalue()
     expected = '<meta charset="UTF-8" />\n'
     self.assertEqual(actual, expected)
Ejemplo n.º 10
0
 def test_meta(self):
     object = hr.Meta(charset="UTF-8")
     with open("outfile3.html", "w") as outfile:
         object.render(outfile, cur_ind="")
     with open("outfile3.html", "r") as infile:
         content = infile.read()
         assert content == '<meta charset="UTF-8">\n'
def test_meta():
    """Test that the meta tag is constructed and renders"""
    meta = h.Meta(charset="UTF-8")
    f = cStringIO.StringIO()
    meta.render(f)
    f.reset()
    assert f.read() == '<meta charset="UTF-8" />\n'
 def test_Html_with_doctype_100(self):
     import html_render as hr  # This repeated statement shouldn't
     # be needed, but I keep getting errors
     # without it here
     meta = hr.Meta(charset="\t    UTF-8   \n")
     title = hr.Title("\n\nRandom  \t   Page   \n\t   ")
     head = hr.Head([meta, title])
     li_1 = hr.Li("  First  item:  ")
     para = hr.P("\n\nExplanatory\t\ttext.\n\n", **consts.attrs_pass)
     link = hr.A("https://github.com/", "A useful site!")
     para.append(link)
     hr = hr.Hr()
     li_1.append([hr, para])
     import html_render as hr  # See previous comment
     li_2 = hr.Li("Second")
     br = hr.Br()
     li_2.append([br, "item"])
     li_3 = hr.Li("Third item", onclick="\n\n\t  EventHandler()\t  \n")
     ul = hr.Ul([li_1, li_2, li_3])
     body = hr.Body(ul)
     html = hr.Html((head, body))
     with open(consts.test_filename, 'w') as self.fobj:
         self.assertTrue(html.render(self.fobj))
     with open(consts.test_filename, 'r') as self.file:
         self.strs_out = self.file.readlines()
         self.assertEqual(len(self.strs_out), 27)  # Verify total lines
         self.assertEqual(self.strs_out[0], '<!DOCTYPE html>\n')
         self.assertEqual(self.strs_out[1], '<html>\n')
         self.assertEqual(self.strs_out[2], '<head>\n')
         self.assertEqual(self.strs_out[3], '<meta charset="UTF-8" />\n')
         self.assertEqual(self.strs_out[4], '<title>Random Page</title>\n')
         self.assertEqual(self.strs_out[5], '</head>\n')
         self.assertEqual(self.strs_out[6], '<body>\n')
         self.assertEqual(self.strs_out[7], '<ul>\n')
         self.assertEqual(self.strs_out[8], '<li>\n')
         self.assertEqual(self.strs_out[9], 'First item:\n')
         self.assertEqual(self.strs_out[10], '<hr />\n')
         self.assertEqual(self.strs_out[11],
                          '<p id="Marker" alt="Fancy Pants">\n')
         self.assertEqual(self.strs_out[12], 'Explanatory text.\n')
         self.assertEqual(
             self.strs_out[13],
             '<a href="https://github.com/">A useful site!</a>\n')
         self.assertEqual(self.strs_out[14], '</p>\n')
         self.assertEqual(self.strs_out[15], '</li>\n')
         self.assertEqual(self.strs_out[16], '<li>\n')
         self.assertEqual(self.strs_out[17], 'Second\n')
         self.assertEqual(self.strs_out[18], '<br />\n')
         self.assertEqual(self.strs_out[19], 'item\n')
         self.assertEqual(self.strs_out[20], '</li>\n')
         self.assertEqual(self.strs_out[21],
                          '<li onclick="EventHandler()">\n')
         self.assertEqual(self.strs_out[22], 'Third item\n')
         self.assertEqual(self.strs_out[23], '</li>\n')
         self.assertEqual(self.strs_out[24], '</ul>\n')
         self.assertEqual(self.strs_out[25], '</body>\n')
         self.assertEqual(self.strs_out[26], '</html>\n')
     del meta, title, head, li_1, li_2, li_3, para, link, \
             hr, br, ul, body, html
def test_doc_meta_tags():
    """A function to test the added meta self-closing tag."""
    page = hr.Html()
    head = hr.Head()

    head.append(hr.Meta(charset="UTF-8"))

    assert head.content[1].tag == ('<meta charset="UTF-8" />')
Ejemplo n.º 14
0
def test_self_closing_tags():
    hr_tag = hr.Hr()
    assert hr_tag.tag == 'hr', ('Hr: tag failure')
    br_tag = hr.Br('BR Value')
    assert br_tag.contents == ['BR Value'], ('Br: contents failure')
    assert br_tag.tag == 'br', ('Br: tag failure')
    meta_tag = hr.Meta()
    assert meta_tag.tag == 'meta', ('Meta: tag failure')
 def test_Meta(self):
     ''' Tests for a <meta charset="UTF-8" /> '''
     test = hr.Meta(charset="UTF-8")
     test_correct = '<meta charset="UTF-8" />\n'
     f = StringIO()
     test.render(f)
     print(f.getvalue())
     self.assertEqual(f.getvalue(), test_correct)
Ejemplo n.º 16
0
    def test_meta_tag(self):
        comp_string = '    <meta charset="UTF-8" /> \n'

        with open(path.join(self.test_dir, 'test.txt'), 'w') as f:
            test = hr.Meta(charset="UTF-8").render(f, "")

        with open(path.join(self.test_dir, 'test.txt')) as f:
            self.assertEqual(comp_string, f.read())
Ejemplo n.º 17
0
 def test_meta(self):
     """Run a test for html, body, and p tags"""
     test_content = hr.Meta("test string", charset="UTF-8")
     f = StringIO()
     test_content.render(f)
     expected = '<meta charset="UTF-8" />\n'
     actual = f.getvalue()
     self.assertEqual(expected, actual)
    def testRender(self):
        """testRender validates a basic Meta render operation."""
        want = ["<metacharset=UTF-8 />"]

        got = open(self.file_out, 'w')
        html_render.Meta(charset="UTF-8").render(got)
        got.close()

        self.assertTrue(validate_output(self.file_out, want))
Ejemplo n.º 19
0
def test_meta():
    """
    Verify meta tag was created correctly
    """
    output = io.StringIO()
    meta = hr.Meta(charset="UTF-8")
    meta.render(output, "")
    file_cont = output.getvalue()
    assert "\n" not in file_cont[:-2]
    assert '<meta charset="UTF-8" />' == file_cont.strip()
Ejemplo n.º 20
0
 def setUp(self):
     self.html = hr.Html()
     self.head = hr.Head(hr.Title('The Title is Title'))
     self.body = hr.Body()
     self.paragraph = hr.P('This is my paragraph', style="color:blue;")
     self.horizontal_rule = hr.Hr()
     self.anchor = hr.A('http://chicktech.org', 'link')
     self.unorderedlist = hr.Ul(id="UL_List", style="line-height:100%")
     self.headertwo = hr.H(3, 'This is a Header 3 ')
     self.meta = hr.Meta(charset="UTF-8")
Ejemplo n.º 21
0
 def test_meta_tag(self):
     head = html.Head()
     head.append(html.Meta(charset="UTF-8"))
     outfile = io.StringIO()
     head.render(outfile)
     output = outfile.getvalue().strip().split('\n')
     print(output)
     self.assertEqual(output[0].strip(), '<head>')
     self.assertEqual(output[1].strip(), '<meta charset="UTF-8" />')
     self.assertEqual(output[-1].strip(), '</head>')
Ejemplo n.º 22
0
    def test_head_tag_append(self):
        comp_string = '<head>\n    <meta charset="UTF-8" /> \n</head>\n'

        with open(path.join(self.test_dir, 'test.txt'), 'w') as f:
            test = hr.Head()
            test.append(hr.Meta(charset="UTF-8"))
            test.render(f)

        with open(path.join(self.test_dir, 'test.txt')) as f:
            self.assertEqual(comp_string, f.read())
Ejemplo n.º 23
0
 def generate_base():
     taskList = routes.GatherData()._get()
     output = render.Html()
     header = render.Head()
     header.append(render.Meta(charset="UTF-8"))
     header.append(render.BootstrapLink())
     header.append(render.Title("Task List"))
     output.append(header)
     body = render.Body()
     return taskList, output, body
def test_step8_html_output_using_ind_optional_input():
    page = hr.Html(ind=0)
    head = hr.Head()
    head.append(hr.Meta(charset="UTF-8"))
    head.append(hr.Title("PythonClass = Revision 1087:"))
    page.append(head)
    body = hr.Body()
    body.append(hr.H(2, "PythonClass - Example"))
    body.append(
        hr.P(
            "Here is a paragraph of text -- there could be more of them, "
            "but this is enough  to show that we can do some text",
            style="text-align: center; font-style: oblique;"))
    body.append(hr.Hr())
    list = hr.Ul(id="TheList", style="line-height:200%")
    list.append(hr.Li("The first item in a list"))
    list.append(hr.Li("This is the second item", style="color: red"))
    item = hr.Li()
    item.append("And this is a ")
    item.append(hr.A("http://google.com", "link"))
    item.append("to google")
    list.append(item)
    body.append(list)
    page.append(body)
    f = StringIO()
    page.render(f)
    expected = "<!DOCTYPE html>\n" \
               "<html>\n" \
               "<head>\n" \
               '<meta charset="UTF-8" />\n' \
               "<title>PythonClass = Revision 1087:</title>\n" \
               "</head>\n" \
               "<body>\n" \
               "<h2>PythonClass - Example</h2>\n" \
               '<p style="text-align: center; font-style: oblique;">\n' \
               "Here is a paragraph of text -- there could be more of them, but this is enough " \
               " to show that we can do some text\n" \
               "</p>\n" \
               "<hr />\n" \
               '<ul id="TheList" style="line-height:200%">\n' \
               "<li>\n" \
               "The first item in a list\n" \
               "</li>\n" \
               '<li style="color: red">\n' \
               "This is the second item\n" \
               "</li>\n" \
               "<li>\n" \
               "And this is a \n" \
               '<a href="http://google.com">link</a>\n' \
               "to google\n" \
               "</li>\n" \
               "</ul>\n" \
               "</body>\n" \
               "</html>\n"
    assert f.getvalue() == expected
 def test_Meta_200(self):
     self.e2 = hr.Meta(charset="\t    UTF-8   \n")
     self.e1 = hr.Head(self.e2)
     with open(consts.test_filename, 'w') as self.fobj:
         self.assertTrue(self.e1.render(self.fobj, '     '))
     with open(consts.test_filename, 'r') as self.file:
         self.strs_out = self.file.readlines()
         self.assertEqual(len(self.strs_out), 3)  # Verify total lines
         self.assertEqual(self.strs_out[0], '<head>\n')
         self.assertEqual(self.strs_out[1],
                          '     <meta charset="UTF-8" />\n')
         self.assertEqual(self.strs_out[2], '</head>\n')
def test_2():
    page_test = hr.Html()
    head = hr.Head()
    head.append(hr.Meta(charset="UTF-8"))
    head.append(hr.Title("Lorem ipsum dolor sit amet"))
    page_test.append(head)
    hr.render_page(page_test, "test_2_head_class.htm")
    test_file = f"{tmp_directory}test_2_head_class.htm"
    hash_object_open = hashlib.md5()
    with open(test_file, 'rb') as afile:
        buf = afile.read()
        hash_object_open.update(buf)
    assert hash_object_open.hexdigest() == "b362162f7599ff8217d0b5e8e5598849"
Ejemplo n.º 27
0
 def test_Meta(self):
     self.assertTrue(issubclass(hr.Meta, hr.SelfClosingTag))
     obj = hr.Meta()
     self.assertIsInstance(obj, hr.Meta)
     self.assertIsInstance(obj, hr.SelfClosingTag)
     self.assertIsInstance(obj, hr.Element)
     self.assertTrue(obj.tag == 'meta')
     self.assertTrue(hasattr(obj, 'props'))
     self.assertTrue(type(obj.props) == list)
     self.assertTrue(len(obj.props) == 0)
     self.assertTrue(hasattr(obj, 'propstring'))
     self.assertTrue(type(obj.propstring) == str)
     self.assertTrue(len(obj.propstring) == 0)
Ejemplo n.º 28
0
def test_meta():
    html = hr.Html()
    body = hr.Body()
    html.append(body)
    meta = hr.Meta(charset="UTF-8")
    body.append(meta)

    f = StringIO()
    html.render(f)
    f.seek(0)
    text = f.read().strip()

    print(text)
    assert text.find("<meta charset=\"UTF-8\" />") != -1
def test_step8_output(step8_sample_output):
    """copied and pasted from run_html_render.py, step7.
    Expect this gives same result as test html"""
    page = hr.Html()

    head = hr.Head()
    head.append(hr.Meta(charset="UTF-8"))
    head.append(hr.Title("PythonClass = Revision 1087:"))

    page.append(head)

    body = hr.Body()

    body.append(hr.H(2, "PythonClass - Example"))

    body.append(
        hr.P(
            "Here is a paragraph of text -- there could be more of them, "
            "but this is enough  to show that we can do some text",
            style="text-align: center; font-style: oblique;"))

    body.append(hr.Hr())

    list = hr.Ul(id="TheList", style="line-height:200%")

    list.append(hr.Li("The first item in a list"))
    list.append(hr.Li("This is the second item", style="color: red"))

    item = hr.Li()
    item.append("And this is a ")
    item.append(hr.A("http://google.com", "link"))
    item.append("to google")

    list.append(item)

    body.append(list)

    page.append(body)

    render_page(page, "test_html_output8.html")

    with open('test_html_output8.html') as f:
        generated_file = f.read()

    assert generated_file == step8_sample_output
Ejemplo n.º 30
0
def html_report():
    """ Saves a report in HTML format """
    now = datetime.datetime.now()
    rendered_page = StringIO()
    page = hr.Html()
    head = hr.Head()
    head.append(hr.Meta(charset="UTF-8"))
    head.append(hr.Title("Mailroom OO Report"))
    page.append(head)
    body = hr.Body()
    body.append(hr.H(2, "Donation Report"))
    table = hr.Table(border=1, width=900)
    table.append(hr.Caption(f'Mailroom Database'))
    table.append(hr.Th('Name'))
    table.append(hr.Th('Total Given'))
    table.append(hr.Th('# of Gifts'))
    table.append(hr.Th('Average Gift'))

    for name in mailroom.database:
        # style="text-align:(left,center,right)"" can go on TR for the whole row or each TD
        table_row = hr.Tr(style="text-align:right")
        table_row.append(hr.Td(f'{mailroom.database[name].name}'))
        table_row.append(
            hr.Td(f'${mailroom.database[name].total_donations:,.2f}'))
        if mailroom.database[name].donations == []:
            table_row.append(hr.Td('0'))
        else:
            table_row.append(
                hr.Td(f'{len(mailroom.database[name].donations)}'))
        table_row.append(
            hr.Td(f'${mailroom.database[name].average_donation:,.2f}'))
        table.append(table_row)

    table_row = hr.Tr()
    table_row.append(
        hr.Td(f'Generated {now.strftime("%Y-%m-%d %H:%M:%S")}', colspan=4))
    table.append(table_row)
    body.append(table)
    page.append(body)
    page.render(rendered_page, '    ')
    with open('./mailroom.html', 'w') as outfile:
        outfile.write(rendered_page.getvalue())
    return f'HTML report saved to ./mailroom.html'