示例#1
0
    def test_repeat_subcases_schema_generation(self):
        form_xml = self.get_xml('nested_repeat_form')
        repeats_with_subcases = [
            OpenSubCaseAction(repeat_context='/data/repeat',
                              case_properties={
                                  'weight': '/data/repeat/group/weight',
                              }),
            OpenSubCaseAction(repeat_context='/data/repeat/nested_repeat',
                              case_properties={
                                  'age': '/data/repeat/nested_repeat/age',
                              }),
        ]

        schema = FormExportDataSchema._generate_schema_from_repeat_subcases(
            XForm(form_xml),
            repeats_with_subcases,
            ['en'],
            self.app_id,
            1,
        )

        self.assertEqual(len(schema.group_schemas), 2)

        group_schema = schema.group_schemas[0]
        attribute_items = filter(
            lambda item: item.path[-1].name in CASE_ATTRIBUTES,
            group_schema.items)

        self.assertEqual(len(attribute_items), len(CASE_ATTRIBUTES))
        self.assertTrue(
            all(
                map(
                    lambda item: item.readable_path.startswith(
                        'form.repeat.case'),
                    attribute_items,
                )))

        create_items = filter(
            lambda item: item.path[-1].name in CASE_CREATE_ELEMENTS,
            group_schema.items)
        self.assertEqual(len(create_items), len(CASE_CREATE_ELEMENTS))
        self.assertTrue(
            all(
                map(
                    lambda item: item.readable_path.startswith(
                        'form.repeat.case.create'),
                    create_items,
                )))

        update_items = list(
            set(group_schema.items) - set(create_items) - set(attribute_items))
        self.assertEqual(len(update_items), 1)
        self.assertEqual(update_items[0].readable_path,
                         'form.repeat.case.update.group.weight')
示例#2
0
    def test_repeat_subcases_schema_generation(self):
        form_xml = self.get_xml('nested_repeat_form')
        repeats_with_subcases = [
            OpenSubCaseAction(
                repeat_context='/data/repeat',
                case_properties={
                    'weight': '/data/repeat/group/weight',
                }
            ),
            OpenSubCaseAction(
                repeat_context='/data/repeat/nested_repeat',
                case_properties={
                    'age': '/data/repeat/nested_repeat/age',
                }
            ),
        ]

        schema = FormExportDataSchema._generate_schema_from_repeat_subcases(
            XForm(form_xml),
            repeats_with_subcases,
            ['en'],
            self.app_id,
            1,
        )

        self.assertEqual(len(schema.group_schemas), 2)

        group_schema = schema.group_schemas[0]
        attribute_items = filter(lambda item: item.path[-1].name in CASE_ATTRIBUTES, group_schema.items)

        self.assertEqual(len(attribute_items), len(CASE_ATTRIBUTES))
        self.assertTrue(all(map(
            lambda item: item.readable_path.startswith('form.repeat.case'),
            attribute_items,
        )))

        create_items = filter(lambda item: item.path[-1].name in CASE_CREATE_ELEMENTS, group_schema.items)
        self.assertEqual(len(create_items), len(CASE_CREATE_ELEMENTS))
        self.assertTrue(all(map(
            lambda item: item.readable_path.startswith('form.repeat.case.create'),
            create_items,
        )))

        update_items = list(set(group_schema.items) - set(create_items) - set(attribute_items))
        self.assertEqual(len(update_items), 1)
        self.assertEqual(update_items[0].readable_path, 'form.repeat.case.update.group.weight')
    def test_repeat_subcases_schema_generation(self):
        form_xml = self.get_xml('nested_repeat_form')
        repeats_with_subcases = [
            OpenSubCaseAction(
                repeat_context='/data/repeat',
                case_properties={
                    'weight': '/data/repeat/group/weight',
                },
                subcase_index=0,
                nest=False,
            ).with_id(0, None),
            OpenSubCaseAction(
                repeat_context='/data/repeat/nested_repeat',
                case_properties={
                    'age': '/data/repeat/nested_repeat/age',
                },
                subcase_index=1,
                nest=False,  # would normally get added by caller
            ).with_id(1, None),
        ]

        schema = FormExportDataSchema._generate_schema_from_repeat_subcases(
            XForm(form_xml),
            repeats_with_subcases,
            ['en'],
            self.app_id,
            1,
        )

        self.assertEqual(len(schema.group_schemas), 2)

        group_schema = schema.group_schemas[0]
        attribute_items = [
            item for item in group_schema.items
            if item.path[-1].name in CASE_ATTRIBUTES
        ]

        self.assertEqual(len(attribute_items), len(CASE_ATTRIBUTES))
        self.assertTrue(
            all(
                map(
                    lambda item: item.readable_path.startswith(
                        'form.repeat.case'),
                    attribute_items,
                )))

        create_items = [
            item for item in group_schema.items
            if item.path[-1].name in CASE_CREATE_ELEMENTS
        ]
        self.assertEqual(len(create_items), len(CASE_CREATE_ELEMENTS))
        self.assertTrue(
            all(
                map(
                    lambda item: item.readable_path.startswith(
                        'form.repeat.case.create'),
                    create_items,
                )))

        index_items = [
            item for item in group_schema.items
            if 'case.index.parent' in item.readable_path
        ]
        self.assertEqual(len(index_items), 2)

        update_items = list(
            set(group_schema.items) - set(create_items) -
            set(attribute_items) - set(index_items))
        self.assertEqual(len(update_items), 1)
        self.assertEqual(update_items[0].readable_path,
                         'form.repeat.case.update.group.weight')