def test_step6_output(step6_sample_output):
    """copied and pasted from run_html_render.py, step6.
    Expect this gives same result as test html"""
    page = hr.Html()

    head = hr.Head()
    head.append(hr.Title("PythonClass = Revision 1087:"))

    page.append(head)

    body = hr.Body()

    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())

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

    page.append(body)

    render_page(page, "test_html_output6.html")

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

    assert generated_file == step6_sample_output
def test_A():
    eval = html_render.A('TESTING', 'TESTING2')
    f = StringIO()
    eval.render(f)
    actual = f.getvalue()
    expected = '<a href="TESTING">\n    TESTING2\n</a>\n'
    assert actual == expected
Exemple #3
0
 def test_6_A(self):
     f = StringIO()
     link = hr.A("http://google.com", "link")
     link.render(f)
     actual = f.getvalue()
     expected = '<a href="http://google.com">\n  link\n</a>\n'
     self.assertEqual(actual, expected)
 def test_a(self):
     object = hr.A("http://google.com", "link")
     with open("outfile.html", "w") as outfile:
         object.render(outfile, cur_ind="")
     with open("outfile.html", "r") as infile:
         content = infile.read()
         assert content == '<a href="http://google.com">\nlink\n</a>\n'
Exemple #5
0
 def test_atag(self):
     test_atag = hr.A("http://google.com", "Some link")
     f = StringIO()
     test_atag.render(f)
     self.assertEqual(
         f.getvalue(), "<a href=\"http://google.com\">\n" +
         test_atag.indent + "Some link\n</a>\n")
Exemple #6
0
 def test_A(self):
     self.assertTrue(issubclass(hr.A, hr.Element))
     obj = hr.A('https://www.uw.edu', 'university')
     self.assertIsInstance(obj, hr.A)
     self.assertIsInstance(obj, hr.Element)
     self.assertTrue(obj.tag == 'a')
     self.assertTrue(hasattr(obj, 'render'))
def test_a_element():
    f = StringIO()
    test_a = h.A("http://www.google.com", "Google")
    test_a.render(f)
    page = f.getvalue()
    expected_page = '<a href="http://www.google.com">Google</a>\n'
    assert page == expected_page
def test_Body_A_test_Content_2():
    body = hr.Body()
    body.append("Test 34 ")
    body.append(hr.A("Test 35", "Test 36"))
    body.append(" Test 37")
    testdata = body.content
    assert testdata == "<body>\n    Test 34 \n    <a href=\"Test 35\">Test 36</a>\n     Test 37\n</body>"
def test_hyperlinks():
    """A function to test the functionality and creation
    of hyperlink objects."""
    a = hr.A("http://google.com", "link")

    assert a.open_tag == ('<a href="http://google.com">')
    assert a.content[0] == ("link")
 def test_A(self):
     test_anchor_tag = hr.A('http://www.boeing.com', 'link')
     file = StringIO()
     test_anchor_tag.render(file)
     self.assertEqual(
         file.getvalue(),
         '<a href="http://www.boeing.com">\n' + '    link\n' + '</a>\n')
def test_step_6_html_output():
    page = hr.Html()
    head = hr.Head()
    head.append(hr.Title("PythonClass = Revision 1087:"))
    page.append(head)
    body = hr.Body()
    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())
    body.append("And this is a ")
    body.append(hr.A("http://google.com", "link"))
    body.append("to google")
    page.append(body)
    f = StringIO()
    page.render(f)
    expected = "<!DOCTYPE html>\n" \
               "<html>\n" \
               "   <head>\n" \
               "      <title>PythonClass = Revision 1087:</title>\n" \
               "   </head>\n" \
               "   <body>\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" \
               "      And this is a \n" \
               '      <a href="http://google.com">link</a>\n' \
               "      to google\n" \
               "   </body>\n" \
               "</html>\n"
    assert f.getvalue() == expected
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>"
Exemple #13
0
 def test_a_obj_hypertext(self):
     # Tests "A" object created with hypertext link
     a_obj = hr.A("www.cnn.com", "Click here for news")
     self.assertDictEqual(
         {a_obj.another_attrib_key: a_obj.another_attrib_value},
         {"href": "www.cnn.com"})
     self.assertListEqual(a_obj.content, ["Click here for news"])
 def test_A(self):
     test_anchor = h.A('http://www.google.com', 'link')
     f = StringIO()
     test_anchor.render(f)
     self.assertEqual(
         f.getvalue(),
         '<a href="http://www.google.com">\n' + '    link\n' + '</a>\n')
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", "    ")
Exemple #16
0
def test_selfclosing_attr():
    a = html_render.A("www.alink.com", "link", id="cat", style="hat")
    output = render_element(a, indent_spaces)
    print("\n" + output)
    assert output.startswith(indent_spaces + "<a ")
    assert ('style="hat"' and 'id="cat"' and 'href="www.alink.com"') in output
    assert output.endswith(">link</a>\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_A_render():
    test_link = "http://google.com"
    test_string = "test string"
    element = hr.A(test_link, test_string)
    goal_string = '<a href="{}">{}</a>'.format(test_link, test_string)
    f = StringIO()
    element.render(f)
    assert goal_string == f.getvalue()
Exemple #19
0
 def removeTask(input):
     taskList, output, body = renderFile().generate_base()
     body.append(render.H(1, "Remove Task: " + input.replace("-", " ")))
     body.append(render.Form("/task/" + input + "/remove"))
     body.append(render.Submit("Remove", input))
     body.append(render.A("/tasklist", "Cancel"))
     output.append(body)
     return render.render_page(output, "index.html")
def test_a():
    """Test that link tags are constructed and render as expected"""
    a = h.A("http://google.com", "link to google")
    f = cStringIO.StringIO()
    a.render(f)
    f.reset()
    assert f.read() == '<a href="http://google.com">\n' +\
        h.Element.tabstring + "link to google\n" + "</a>\n"
Exemple #21
0
 def homepage():
     taskList, output, body = renderFile().generate_base()
     body.append(render.H(1, "Task List"))
     body.append(render.A("/tasklist/new", "Add New Task"))
     unorderedList = render.Ul(id="unordered-task-list")
     for task in taskList:
         item = render.Li()
         item.append(task)
         item.append(
             render.A("/tasklist/"+(task).replace(" ", "-")+"/remove", "Delete"))
         item.append(
             render.A("/tasklist/"+(task).replace(" ", "-") + "/update", "Update"))
         item.append(render.Br())
         unorderedList.append(item)
     body.append(unorderedList)
     output.append(body)
     return render.render_page(output, "index.html")
 def test_href_link_generates_correctly(self):
     href_link = hr.A('www.python.org', 'link to python.org')
     href_link.indent = ''
     output = StringIO()
     href_link.render(output)
     self.assertEqual(
         output.getvalue(),
         '<a href="www.python.org">\nlink to python.org\n</a>\n')
Exemple #23
0
 def test_anchor_tag(self):
     """Run a test for tags with links"""
     test_content = hr.A("http://google.com", "test link")
     f = StringIO()
     test_content.render(f)
     expected = '<a href="http://google.com">test link</a>\n'
     actual = f.getvalue()
     self.assertEqual(expected, actual)
Exemple #24
0
    def test_A(self):
        """Test that the A class with render <a href="http://google.com">link to google</a>"""

        a_class = hr.A("http://google.com", "link to google")
        file_contents = render_result(a_class)
        print(file_contents)
        test_text = "<a href=\"http://google.com\">link to google</a>\n"
        self.assertEqual(file_contents, test_text)
def test_Ul_Li_A_test_Content_id_style():
    unordered = hr.Ul(id="Test 56", style="Test 57")
    item = hr.Li()
    item.append("Test 58")
    item.append(hr.A("Test 59", "Test 60"))
    item.append(" Test 61")
    unordered.append(item)
    testdata = unordered.content
    assert testdata == "<ul id=\"Test 56\" style=\"Test 57\">\n    <li>\n        Test 58\n        <a href=\"Test 59\">Test 60</a>\n         Test 61\n    </li>\n</ul>"
Exemple #26
0
    def test_a_tag(self):
        comp_string = '        <a href="http://google.com">google</a>\n'

        with open(path.join(self.test_dir, 'test.txt'), 'w') as f:
            test = hr.A("http://google.com", "google")
            test.indent = ""
            test.render(f, "")

        with open(path.join(self.test_dir, 'test.txt')) as f:
            self.assertEqual(comp_string, f.read())
Exemple #27
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")
def test_Html_Body_A_test_Content():
    page = hr.Html()
    body = hr.Body()
    body.append("Test 38 ")
    body.append(hr.A("Test 39", "Test 40"))
    body.append(" Test 41")
    page.append(body)
    render_page(page, "page.html")
    testdata = open("page.html").read()
    assert testdata == "<html>\n    <body>\n        Test 38 \n        <a href=\"Test 39\">Test 40</a>\n         Test 41\n    </body>\n</html>"
Exemple #29
0
def test_A():
    e = hr.A("http://google.com", "link to google")
    f = StringIO()
    e.render(f)
    f.seek(0)
    text = f.read().strip()
    assert 'href="http://google.com"' in text
    assert text.startswith('<a')
    assert text.endswith('</a>')
    assert 'link to google' in text
Exemple #30
0
 def updateTask(input):
     taskList, output, body = renderFile().generate_base()
     body.append(render.H(1, "Update Task: " + input.replace("-", " ")))
     body.append(render.Form("/tasklist/" + input.replace(
         "%20", " ") + "/update"))
     body.append(render.Input("update", input))
     body.append(render.Submit("Update", input))
     body.append(render.A("/tasklist", "Cancel"))
     output.append(body)
     return render.render_page(output, "index.html")