Esempio n. 1
0
    def test_put_export_item(self):
        group_schema = InferredExportGroupSchema(
            path=[PathNode(name='random')])
        item = group_schema.put_item(
            [PathNode(name='random'),
             PathNode(name='inferred')])
        self.assertTrue(isinstance(item, ExportItem))
        self.assertTrue(item.inferred)
        self.assertEqual(len(group_schema.items), 1)

        # After putting same item, should not re-add group schema
        item = group_schema.put_item(
            [PathNode(name='random'),
             PathNode(name='inferred')], )
        self.assertEqual(len(group_schema.items), 1)
    def setUpClass(cls):
        cls.current_app = Application.wrap(cls.get_json('basic_application'))

        cls.first_build = Application.wrap(cls.get_json('basic_application'))
        cls.first_build._id = '123'
        cls.first_build.copy_of = cls.current_app.get_id
        cls.first_build.version = 3

        cls.advanced_app = Application.new_app('domain',
                                               "Untitled Application")
        module = cls.advanced_app.add_module(
            AdvancedModule.new_module('Untitled Module', None))
        form = module.new_form("Untitled Form",
                               cls.get_xml('repeat_group_form'))
        form.xmlns = 'repeat-xmlns'
        form.actions.open_cases = [
            AdvancedOpenCaseAction(
                case_type="advanced",
                case_tag="open_case_0",
                name_path="/data/question3/question4",
                repeat_context="/data/question3",
            )
        ]

        cls.apps = [
            cls.current_app,
            cls.first_build,
            cls.advanced_app,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()

        cls.inferred_schema = InferredSchema(
            domain=cls.domain,
            case_type=cls.case_type,
            group_schemas=[
                InferredExportGroupSchema(
                    path=MAIN_TABLE,
                    items=[
                        ExportItem(path=[
                            PathNode(name='data'),
                            PathNode(name='case_property')
                        ],
                                   label='Inferred 1',
                                   inferred=True),
                        ExportItem(path=[
                            PathNode(name='data'),
                            PathNode(name='case_property_2')
                        ],
                                   label='Inferred 1',
                                   inferred=True),
                    ],
                    inferred=True),
            ])
        cls.inferred_schema.save()
Esempio n. 3
0
    def test_put_export_item(self):
        group_schema = InferredExportGroupSchema(
            path=[PathNode(name='random')]
        )
        item = group_schema.put_item(
            [PathNode(name='random'), PathNode(name='inferred')],
            inferred_from='Test',
        )
        item = group_schema.put_item(
            [PathNode(name='random'), PathNode(name='inferred')],
            inferred_from='TestTwo',
        )
        self.assertTrue(isinstance(item, ExportItem))
        self.assertTrue(item.inferred)
        self.assertEqual(item.inferred_from, set(['Test', 'TestTwo']))
        self.assertEqual(len(group_schema.items), 1)

        # After putting same item, should not re-add group schema
        item = group_schema.put_item(
            [PathNode(name='random'), PathNode(name='inferred')],
        )
        self.assertEqual(len(group_schema.items), 1)
Esempio n. 4
0
 def setUpClass(cls):
     super(TestExportInstanceGenerationWithInferredSchema, cls).setUpClass()
     cls.schema = CaseExportDataSchema(
         app_id=cls.app_id,
         case_type=cls.case_type,
         group_schemas=[
             ExportGroupSchema(
                 path=MAIN_TABLE,
                 items=[
                     ExportItem(
                         path=[
                             PathNode(name='data'),
                             PathNode(name='case_property')
                         ],
                         label='Question 1',
                         last_occurrences={cls.app_id: 3},
                     ),
                 ],
                 last_occurrences={cls.app_id: 3},
             ),
         ],
     )
     cls.inferred_schema = InferredSchema(
         case_type=cls.case_type,
         group_schemas=[
             InferredExportGroupSchema(
                 path=MAIN_TABLE,
                 items=[
                     ExportItem(path=[
                         PathNode(name='data'),
                         PathNode(name='case_property')
                     ],
                                label='Inferred 1',
                                inferred=True),
                     ExportItem(path=[
                         PathNode(name='data'),
                         PathNode(name='case_property_2')
                     ],
                                label='Inferred 1',
                                inferred=True),
                 ],
                 inferred=True),
         ])
Esempio n. 5
0
    def setUpClass(cls):
        cls.current_app = Application.wrap(cls.get_json('basic_application'))

        cls.first_build = Application.wrap(cls.get_json('basic_application'))
        cls.first_build._id = '123'
        cls.first_build.copy_of = cls.current_app.get_id
        cls.first_build.version = 3

        cls.apps = [
            cls.current_app,
            cls.first_build,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()

        cls.inferred_schema = InferredSchema(
            domain=cls.domain,
            case_type=cls.case_type,
            group_schemas=[
                InferredExportGroupSchema(
                    path=MAIN_TABLE,
                    items=[
                        ExportItem(path=[
                            PathNode(name='data'),
                            PathNode(name='case_property')
                        ],
                                   label='Inferred 1',
                                   inferred=True),
                        ExportItem(path=[
                            PathNode(name='data'),
                            PathNode(name='case_property_2')
                        ],
                                   label='Inferred 1',
                                   inferred=True),
                    ],
                    inferred=True),
            ])
        cls.inferred_schema.save()
 def setUp(self):
     self.inferred_schema = CaseInferredSchema(
         domain=self.domain,
         case_type=self.case_type,
         group_schemas=[
             InferredExportGroupSchema(
                 path=MAIN_TABLE,
                 items=[
                     ExportItem(path=[
                         PathNode(name='data'),
                         PathNode(name='case_property')
                     ],
                                label='Inferred 1',
                                inferred=True),
                     ExportItem(path=[
                         PathNode(name='data'),
                         PathNode(name='case_property_2')
                     ],
                                label='Inferred 1',
                                inferred=True),
                 ],
                 inferred=True),
         ])
     self.inferred_schema.save()