Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
import unittest
from html_writer import read_html, read_csv, csv_to_html, combine_template_with_data
class TestHTMLWriter(unittest.TestCase):
def setUp(self):
self.csvdata = [["First", "Last", "E-Mail"]]
self.htmldata = "<tr><td>A</td><td>B</td><td>C</td></tr>"
self.template = read_html()
def test_read_csv_type(self):
result = read_csv("test.csv")
self.assertIsInstance(result, list)
def test_read_csv_data(self):
result = read_csv("test.csv")
first = result[0][0]
self.assertEqual(first, "Andreas")
def test_csv_to_html_type(self):
htmlstring = csv_to_html(self.csvdata)
self.assertIsInstance(htmlstring, str)
def test_csv_to_html_is_table_row(self):
htmlstring = csv_to_html(self.csvdata)
self.assertIn("<tr>", htmlstring)
self.assertIn("</tr>", htmlstring)
def test_csv_to_html_has_table_data(self):
htmlstring = csv_to_html(self.csvdata)
self.assertIn("<td>", htmlstring)
self.assertIn("</td>", htmlstring)
def test_csv_to_html_replaced_brackets(self):
htmlstring = csv_to_html(self.csvdata)
self.assertNotIn("{}", htmlstring)
def test_combine_template_with_data_type(self):
content = combine_template_with_data(self.template, "")
self.assertIsInstance(content, str)
def test_combine_template_with_data_replace(self):
content = combine_template_with_data(self.template, self.htmldata)
self.assertTrue(content.startswith("<!DOCTYPE html>"))
self.assertTrue(content.endswith("</html>\n"))
self.assertNotIn("{}", content)
if __name__ == "__main__":
unittest.main()