def test_double_repeat(self):
     table_configuration = TableConfiguration(
         path=[
             PathNode(name="form", is_repeat=False),
             PathNode(name="repeat1", is_repeat=True),
             PathNode(name="group1", is_repeat=False),
             PathNode(name="repeat2", is_repeat=True),
         ],
         columns=[
             RowNumberColumn(
                 selected=True
             ),
             ExportColumn(
                 item=ScalarItem(
                     path=[
                         PathNode(name='form'),
                         PathNode(name='repeat1', is_repeat=True),
                         PathNode(name='group1'),
                         PathNode(name='repeat2', is_repeat=True),
                         PathNode(name='q1')
                     ],
                 ),
                 selected=True,
             ),
         ]
     )
     submission = {
         'domain': 'my-domain',
         '_id': '1234',
         'form': {
             'repeat1': [
                 {
                     'group1': {
                         'repeat2': [
                             {'q1': 'foo'},
                             {'q1': 'bar'}
                         ]
                     }
                 },
                 {
                     'group1': {
                         'repeat2': [
                             {'q1': 'beep'},
                             {'q1': 'boop'}
                         ]
                     }
                 },
             ]
         }
     }
     self.assertEqual(
         [row.data for row in table_configuration.get_rows(submission, 0)],
         [
             ["0.0.0", 0, 0, 0, 'foo'],
             ["0.0.1", 0, 0, 1, 'bar'],
             ["0.1.0", 0, 1, 0, 'beep'],
             ["0.1.1", 0, 1, 1, 'boop']
         ]
     )
Exemplo n.º 2
0
 def test_row_number_column_is_removed(self):
     export_with_row_number_column = ExportInstance(
         is_odata_config=True,
         tables=[
             TableConfiguration(columns=[
                 RowNumberColumn(label='row-number', ),
                 ExportColumn(
                     label='label',
                     item=ExportItem(path=[PathNode(name='val')]),
                     selected=True,
                 )
             ])
         ])
     export_with_row_number_column.save()
     self.addCleanup(export_with_row_number_column.delete)
     cleaned_export = ExportInstance.get(
         export_with_row_number_column.get_id)
     tables = cleaned_export.tables
     self.assertEqual(len(tables), 1)
     columns = tables[0].columns
     self.assertEqual(len(columns), 1)
     self.assertFalse(isinstance(columns[0], RowNumberColumn))
     self.assertEqual(columns[0].label, 'label')
Exemplo n.º 3
0
                                      OWNER_ID_TRANSFORM, PROPERTY_TAG_NONE)
from corehq.apps.export.models import (
    ExportColumn,
    ExportItem,
    PathNode,
    StockExportColumn,
    RowNumberColumn,
    SplitGPSExportColumn,
    GeopointItem,
)

# System properties to be displayed above the form questions
TOP_MAIN_FORM_TABLE_PROPERTIES = [
    RowNumberColumn(
        tags=[PROPERTY_TAG_ROW],
        label="number",
        item=ExportItem(path=[PathNode(name='number')]),
        selected=True,
    ),
    ExportColumn(
        tags=[PROPERTY_TAG_INFO],
        label="formid",
        item=ExportItem(path=[
            PathNode(name='form'),
            PathNode(name='meta'),
            PathNode(name='instanceID')
        ]),
        help_text=_('Unique identifier of the form submission'),
        selected=True,
    )
]
Exemplo n.º 4
0
 def test_get_value_with_simple_index(self):
     col = RowNumberColumn()
     self.assertEqual(
         col.get_value('domain', 'docid', {}, [], row_index=(7,)),
         ["7"]
     )
Exemplo n.º 5
0
 def test_get_value_with_compound_index(self):
     col = RowNumberColumn()
     self.assertEqual(
         col.get_value('domain', 'docid', {}, [], row_index=(12, 0, 6, 1)),
         ["12.0.6.1", 12, 0, 6, 1]
     )
Exemplo n.º 6
0
 def test_get_headers(self):
     col = RowNumberColumn(label="row number", repeat=2)
     self.assertEqual(
         col.get_headers(),
         ['row number', 'row number__0', 'row number__1', 'row number__2']
     )
Exemplo n.º 7
0
 def test_get_value_with_compound_index(self):
     col = RowNumberColumn()
     self.assertEqual(
         col.get_value('domain', 'docid', {}, [], row_index=(12, 0, 6, 1)),
         ["12.0.6.1", 12, 0, 6, 1])
Exemplo n.º 8
0
 def test_get_value_with_simple_index(self):
     col = RowNumberColumn()
     self.assertEqual(
         col.get_value('domain', 'docid', {}, [], row_index=(7, )), ["7"])
Exemplo n.º 9
0
 def test_get_headers(self):
     col = RowNumberColumn(label="row number", repeat=2)
     self.assertEqual(
         col.get_headers(),
         ['row number', 'row number__0', 'row number__1', 'row number__2'])
Exemplo n.º 10
0
 def test_get_headers(self):
     col = RowNumberColumn(label="row number", repeat=2)
     self.assertEqual(col.get_headers(), ["row number", "row number__0", "row number__1", "row number__2"])