Exemple #1
0
    def test_from_dict_empty(self):
        row1_dict = Row().to_dict()

        clean_dict = loads(dumps(row1_dict, ensure_ascii=False),
                           encoding='utf-8')
        row2_dict = Row().from_dict('tb', clean_dict).to_dict()

        self.assertDictEqual(row1_dict, row2_dict)
Exemple #2
0
    def test_to_dict_returns_only_cells(self):
        obj = Row() \
            .add_cells([
                Cell(
                    name="Price",
                    value=1
                ),
                Cell(
                    name="Date",
                    value=1
                )
            ]) \
            .to_dict()

        self.assertEqual(len(obj.keys()), 2)
Exemple #3
0
    def test_from_dict_th(self):
        row1_dict = Row() \
            .add_cells([
                Head(
                    name="Price",
                    displayName="Цена",
                ),
                Head(
                    name="Price",
                    displayName="Цена",
                )
            ]) \
            .to_dict()

        clean_dict = loads(dumps(row1_dict, ensure_ascii=False),
                           encoding='utf-8')
        row2_dict = Row().from_dict('th', clean_dict).to_dict()

        self.assertDictEqual(row1_dict, row2_dict)
Exemple #4
0
 def test_add_cell_appends_cell(self):
     obj = Row() \
         .add_cell(Cell(
             name="Price",
             value=1
         )) \
         .add_cell(Cell(
             name="Date",
             value=1
         ))
     self.assertEqual(len(obj.cells), 2)
Exemple #5
0
 def test_add_cell_appends_head(self):
     obj = Row() \
         .add_cell(Head(
             name="Price",
             displayName="Цена",
         )) \
         .add_cell(Head(
             name="Date",
             displayName="Дата",
         ))
     self.assertEqual(len(obj.cells), 2)
Exemple #6
0
    def test_from_dict_tb(self):
        row1_dict = Row() \
            .add_cells([
                Cell(
                    name="Price",
                    value=1,
                    type=FieldType.Price
                ),
                Cell(
                    name="Date",
                    value=1,
                    type=FieldType.Date
                )
            ]) \
            .to_dict()

        clean_dict = loads(dumps(row1_dict, ensure_ascii=False),
                           encoding='utf-8')
        row2_dict = Row().from_dict('tb', clean_dict).to_dict()

        self.assertDictEqual(row1_dict, row2_dict)
Exemple #7
0
 def test_validate_invalid_children(self):
     errors = Row() \
         .add_cells([
             Head(
                 name="Price",
             ),
             Head(
                 name="Date",
             )
         ]) \
         .validate("tb.0", "parent")
     self.assertEqual(len(errors), 2)
     self.assertTrue(all([e.startswith('parent.tb.0.') for e in errors]))
Exemple #8
0
 def test_validate_invalid_children_not_unique(self):
     errors = Row() \
         .add_cells([
             Head(
                 name="Price",
                 displayName="Цена",
             ),
             Head(
                 name="Price",
                 displayName="Цена",
             )
         ]) \
         .validate("tb.0", "parent")
     self.assertEqual(len(errors), 1)
     self.assertTrue(all([e.startswith('parent.tb.0:') for e in errors]))
Exemple #9
0
    def test_to_dict_head_convertable_to_dict(self):
        obj = Row() \
            .add_cells([
                Head(
                    name="Price",
                    displayName="Цена",
                ),
                Head(
                    name="Date",
                    displayName="Дата",
                )
            ]) \
            .to_dict()

        expected = "{\"0\": {\"fn\": \"Price\", \"fv\": \"Цена\"}, \"1\": {\"fn\": \"Date\", \"fv\": \"Дата\"}}"
        self.assertEqual(dumps(obj, ensure_ascii=False), expected)
Exemple #10
0
    def test_to_dict_cell_convertable_to_dict(self):
        obj = Row() \
            .add_cells([
                Cell(
                    name="Price",
                    value=1
                ),
                Cell(
                    name="Date",
                    value=1
                )
            ]) \
            .to_dict()

        expected = "{\"0\": {\"fn\": \"Price\", \"ft\": \"None\", \"fv\": 1}, \"1\": {\"fn\": \"Date\", \"ft\": \"None\", \"fv\": 1}}"
        self.assertEqual(dumps(obj, ensure_ascii=False), expected)
Exemple #11
0
 def test_add_cells_extends_cells(self):
     obj = Row() \
         .add_cell(Cell(
             name="Price",
             displayName="Цена",
             value=1
         )) \
         .add_cells([
             Cell(
                 name="Date",
                 value=1
             ),
             Cell(
                 name="Date2",
                 value=2
             )
         ])
     self.assertEqual(len(obj.cells), 3)
Exemple #12
0
 def test_to_dict_returns_none_when_rows_are_empty(self):
     obj = Body(name="Table1").set_header(Row())
     self.assertEqual(obj.to_dict(), None)
Exemple #13
0
    def test_add_row_object(self):
        obj = Body(name="Table1").add_row(Row()).add_row(Row())

        self.assertEqual(len(obj.rows), 2)
        self.assertIsInstance(obj.rows[0], Row)
Exemple #14
0
    def test_set_header_object(self):
        row = Row()
        obj = Body(name="Table1").set_header(row)

        self.assertEqual(obj.head, row)