Пример #1
0
 def test_clubbed_json(self):
     clubbed_json = _to_ordered_dict({"sample": [ {"a":1, "b":2, "c":3}, {"a":5, "b":6, "c":7} ] })
     result = convert(clubbed_json)
     clubbed_table = "<table><tr><th>sample</th><td><table><tr><th>a</th><th>b</th><th>c</th></tr><"\
                     "tr><td>1</td><td>2</td><td>3</td></tr><tr><td>5</td><td>6</td><td>7</td></tr>"\
                     "</table></td></tr></table>"
     self.assertEqual(result, clubbed_table)
Пример #2
0
 def test_nested_left_to_right(self):
     result = convert(self.nested_json, build_direction="LEFT_TO_RIGHT")
     nested_table = "<table><tr><th>menu</th><td><table><tr><th>id</th><td>file</td></tr><tr><th>me"\
                    "nuitem</th><td><table><tr><th>onclick</th><th>value</th></tr><tr><td>CreateNew"\
                    "Doc()</td><td>New</td></tr><tr><td>OpenDoc()</td><td>Open</td></tr><tr><td>Clo"\
                    "seDoc()</td><td>Close</td></tr></table></td></tr><tr><th>value</th><td>File</t"\
                    "d></tr></table></td></tr></table>"
     self.assertEqual(result, nested_table)
Пример #3
0
 def test_nested_left_to_right(self):
     result = convert(self.nested_json, build_direction="LEFT_TO_RIGHT")
     nested_table = "<table><tr><th>menu</th><td><table><tr><th>id</th><td>file</td></tr><tr><th>me"\
                    "nuitem</th><td><table><tr><th>onclick</th><th>value</th></tr><tr><td>CreateNew"\
                    "Doc()</td><td>New</td></tr><tr><td>OpenDoc()</td><td>Open</td></tr><tr><td>Clo"\
                    "seDoc()</td><td>Close</td></tr></table></td></tr><tr><th>value</th><td>File</t"\
                    "d></tr></table></td></tr></table>"
     self.assertEqual(result, nested_table)
Пример #4
0
 def test_nested_top_to_bottom(self):
     result = convert(self.nested_json, build_direction="TOP_TO_BOTTOM")
     nested_table = "<table><tr><th>menu</th></tr><tr><td><table><tr><th>id</th><th>menuitem</th><t"\
                    "h>value</th></tr><tr><td>file</td><td><table><tr><th>onclick</th><th>value</th"\
                    "></tr><tr><td>CreateNewDoc()</td><td>New</td></tr><tr><td>OpenDoc()</td><td>Op"\
                    "en</td></tr><tr><td>CloseDoc()</td><td>Close</td></tr></table></td><td>File</t"\
                    "d></tr></table></td></tr></table>"
     self.assertEqual(result, nested_table)
Пример #5
0
 def test_nested_top_to_bottom(self):
     result = convert(self.nested_json, build_direction="TOP_TO_BOTTOM")
     nested_table = "<table><tr><th>menu</th></tr><tr><td><table><tr><th>id</th><th>menuitem</th><t"\
                    "h>value</th></tr><tr><td>file</td><td><table><tr><th>onclick</th><th>value</th"\
                    "></tr><tr><td>CreateNewDoc()</td><td>New</td></tr><tr><td>OpenDoc()</td><td>Op"\
                    "en</td></tr><tr><td>CloseDoc()</td><td>Close</td></tr></table></td><td>File</t"\
                    "d></tr></table></td></tr></table>"
     self.assertEqual(result, nested_table)
Пример #6
0
def show_data():
    shark_db = get_db()

    all_data = {}
    result_cursor = shark_db.find_all('stocks').sort([
        ('key', pymongo.DESCENDING)
    ]).limit(7)
    for doc in result_cursor:
        doc.pop('_id')
        all_data[doc['key']] = doc

    return json2table.convert(all_data, "LEFT_TO_RIGHT", {'border': 1})
Пример #7
0
 def test_clubbed_json(self):
     clubbed_json = _to_ordered_dict(
         {"sample": [{
             "a": 1,
             "b": 2,
             "c": 3
         }, {
             "a": 5,
             "b": 6,
             "c": 7
         }]})
     result = convert(clubbed_json)
     clubbed_table = "<table><tr><th>sample</th><td><table><tr><th>a</th><th>b</th><th>c</th></tr><"\
                     "tr><td>1</td><td>2</td><td>3</td></tr><tr><td>5</td><td>6</td><td>7</td></tr>"\
                     "</table></td></tr></table>"
     self.assertEqual(result, clubbed_table)
Пример #8
0
 def test_invalid_build_direction(self):
     with self.assertRaises(ValueError) as context:
         convert(None, build_direction=None)
         self.assertTrue("Invalid build direction" in context.exception)
Пример #9
0
 def test_build_direction_top_to_bottom(self):
     result = convert(self.simple_json, build_direction="TOP_TO_BOTTOM")
     simple_table = "<table><tr><th>key</th></tr><tr><td>value</td></tr></table>"
     self.assertEqual(result, simple_table)
Пример #10
0
 def test_invalid_table_attributes(self):
     with self.assertRaises(TypeError) as context:
         convert(None, table_attributes=0)
         self.assertTrue(
             "Table attributes must be either" in context.exception)
Пример #11
0
 def test_simple(self):
     result = convert(self.simple_json)
     simple_table = "<table><tr><th>key</th><td>value</td></tr></table>"
     self.assertEqual(result, simple_table)
Пример #12
0
 def test_custom_table_attributes(self):
     result = convert({}, table_attributes=self.custom_table_attributes)
     self.assertTrue("border=\"1\"" in result)
Пример #13
0
 def test_invalid_table_attributes(self):
     with self.assertRaises(TypeError) as context:
         convert(None, table_attributes=0)
         self.assertTrue("Table attributes must be either" in context.exception)
Пример #14
0
 def test_invalid_json(self):
     with self.assertRaises(AttributeError) as context:
         convert(None)
Пример #15
0
 def test_invalid_build_direction(self):
     with self.assertRaises(ValueError) as context:
         convert(None, build_direction=None)
         self.assertTrue("Invalid build direction" in context.exception)
Пример #16
0
 def test_invalid_json(self):
     with self.assertRaises(AttributeError) as context:
         convert(None)
Пример #17
0
 def test_build_direction_top_to_bottom(self):
     result = convert(self.simple_json, build_direction="TOP_TO_BOTTOM")
     simple_table = "<table><tr><th>key</th></tr><tr><td>value</td></tr></table>"
     self.assertEqual(result, simple_table)
Пример #18
0
 def test_custom_table_attributes(self):
     result = convert({}, table_attributes=self.custom_table_attributes)
     self.assertTrue("border=\"1\"" in result)
Пример #19
0
 def test_simple(self):
     result = convert(self.simple_json)
     simple_table = "<table><tr><th>key</th><td>value</td></tr></table>"
     self.assertEqual(result, simple_table)