Ejemplo n.º 1
0
 def new_shadow_module(self, slug, source_module, with_form=True):
     module = self.app.add_module(
         ShadowModule.new_module('{} module'.format(slug), None))
     module.unique_id = '{}_module'.format(slug)
     module.source_module_id = source_module.unique_id
     self.slugs[module.unique_id] = slug
     return (module, self.new_form(module)) if with_form else module
Ejemplo n.º 2
0
 def test_shadow_module(self, mockh):
     module = self.app.add_module(ShadowModule.new_module("Module0", "en"))
     self.app.save()
     self._test_status_codes(['view_module'], {
         'domain': self.project.name,
         'app_id': self.app.id,
         'module_unique_id': module.unique_id,
     })
Ejemplo n.º 3
0
 def test_shadow_module(self):
     module = self.app.add_module(ShadowModule.new_module("Module0", "en"))
     self.app.save()
     self._test_status_codes(['view_module'], {
         'domain': self.domain.name,
         'app_id': self.app.id,
         'module_id': module.id,
     })
Ejemplo n.º 4
0
 def test_shadow_module(self, mockh):
     module = self.app.add_module(ShadowModule.new_module("Module0", "en"))
     self.app.save()
     self._test_status_codes(['view_module'], {
         'domain': self.project.name,
         'app_id': self.app.id,
         'module_unique_id': module.unique_id,
     })
Ejemplo n.º 5
0
 def new_shadow_module(self, slug, source_module, with_form=True, shadow_module_version=2, parent_module=None):
     module = self.app.add_module(ShadowModule.new_module('{} module'.format(slug), None))
     module.unique_id = '{}_module'.format(slug)
     module.source_module_id = source_module.unique_id
     if parent_module:
         module.root_module_id = self.unique_id(parent_module)
     module.shadow_module_version = shadow_module_version
     self.slugs[module.unique_id] = slug
     return (module, self.new_form(module)) if with_form else module
Ejemplo n.º 6
0
 def test_shadow_module(self):
     module = self.app.add_module(ShadowModule.new_module("Module0", "en"))
     self.app.save()
     self._test_status_codes(
         ['view_module'], {
             'domain': self.domain.name,
             'app_id': self.app.id,
             'module_id': module.id,
         })
 def test_shadow_module_source_parent(self, *args):
     # With version 2 style shadow modules, we need a real module for the child
     self.shadow.source_module_id = self.parent.unique_id
     self.shadow_child = self.app.add_module(
         ShadowModule.new_module('Shadow Child Module', None))
     self.shadow_child.source_module_id = self.child.unique_id
     self.shadow_child.root_module_id = self.shadow.unique_id
     self.assertXmlPartialEqual(
         self.get_xml('shadow_module_families_source_parent'),
         self.app.create_suite(), "./menu")
    def test_mixture_v1_v2_shadow_modules(self, *args):
        """If there are both V1 and V2 shadow modules pointing to the same source, they
        should both be added to the suite with their different semantics to
        maintain backwards compatibility

        """
        self.shadow.shadow_module_version = 1
        self.shadow.source_module_id = self.parent.unique_id

        self.shadow_v2 = self.app.add_module(
            ShadowModule.new_module('V2 Shadow Module', None))
        self.shadow_v2.source_module_id = self.parent.unique_id
        self.shadow_child = self.app.add_module(
            ShadowModule.new_module('Shadow Child Module', None))
        self.shadow_child.source_module_id = self.child.unique_id
        self.shadow_child.root_module_id = self.shadow_v2.unique_id

        self.assertXmlPartialEqual(
            self.get_xml('shadow_module_source_parent_v1_v2'),
            self.app.create_suite(), "./menu")
Ejemplo n.º 9
0
    def setUp(self):
        self.app = Application.new_app('domain', "Untitled Application")

        self.parent = self.app.add_module(Module.new_module('Parent Module', None))
        self.app.new_form(self.parent.id, "Parent Form", None)

        self.child = self.app.add_module(Module.new_module('Child Module', None))
        self.child.root_module_id = self.parent.unique_id
        self.app.new_form(self.child.id, "Child Form", None)

        self.shadow = self.app.add_module(ShadowModule.new_module('Shadow Module', None))
Ejemplo n.º 10
0
 def test_shadow_module_source_parent_forms_only(self, *args):
     self.shadow.source_module_id = self.parent.unique_id
     self.shadow_child = self.app.add_module(
         ShadowModule.new_module('Shadow Child Module', None))
     self.shadow_child.source_module_id = self.child.unique_id
     self.shadow_child.root_module_id = self.shadow.unique_id
     for m in self.app.get_modules():
         m.put_in_root = True
     self.assertXmlPartialEqual(
         self.get_xml('shadow_module_families_source_parent_forms_only'),
         self.app.create_suite(), "./menu")
Ejemplo n.º 11
0
    def _get_family_app(self):
        app = Application.new_app('domain', "Untitled Application")

        parent = app.add_module(Module.new_module('module', None))
        app.new_form(parent.id, "Untitled Form", None)

        child = app.add_module(Module.new_module('module', None))
        child.root_module_id = parent.unique_id

        app.new_form(child.id, "Untitled Form", None)
        shadow = app.add_module(ShadowModule.new_module('module', None))

        return (app, shadow)
Ejemplo n.º 12
0
    def _get_family_app(self):
        app = Application.new_app('domain', "Untitled Application")

        parent = app.add_module(Module.new_module('module', None))
        app.new_form(parent.id, "Untitled Form", None)

        child = app.add_module(Module.new_module('module', None))
        child.root_module_id = parent.unique_id

        app.new_form(child.id, "Untitled Form", None)
        shadow = app.add_module(ShadowModule.new_module('module', None))

        return (app, shadow)
Ejemplo n.º 13
0
 def test_additional_types__shadow_module(self, *args):
     shadow_module = self.app.add_module(ShadowModule.new_module("shadow", "en"))
     shadow_module.source_module_id = self.module.get_or_create_unique_id()
     shadow_module.search_config = CaseSearch(
         search_label=CaseSearchLabel(
             label={
                 'en': 'Search from Shadow Module'
             }
         ),
         properties=[
             CaseSearchProperty(name='name', label={'en': 'Name'}),
         ],
     )
     another_case_type = "another_case_type"
     self.module.search_config.additional_case_types = [another_case_type]
     app = Application.wrap(self.app.to_json())
     suite_xml = app.create_suite()
     suite = parse_normalize(suite_xml, to_string=False)
     ref_path = './remote-request[2]/session/datum/@nodeset'
     self.assertEqual(
         "instance('{}')/{}/case[@case_type='{}' or @case_type='{}']{}".format(
             RESULTS_INSTANCE,
             RESULTS_INSTANCE,
             self.module.case_type,
             another_case_type,
             EXCLUDE_RELATED_CASES_FILTER
         ),
         suite.xpath(ref_path)[0]
     )
     self.assertXmlPartialEqual(
         """
         <partial>
           <data key="case_type" ref="'case'"/>
           <data key="case_type" ref="'another_case_type'"/>
         </partial>
         """,
         suite_xml,
         "./remote-request[2]/session/query/data[@key='case_type']"
     )
Ejemplo n.º 14
0
def _new_shadow_module(request, domain, app, name, lang):
    module = app.add_module(ShadowModule.new_module(name, lang))
    app.save()
    return back_to_main(request, domain, app_id=app.id, module_id=module.id)
Ejemplo n.º 15
0
def _new_shadow_module(request, domain, app, name, lang):
    module = app.add_module(ShadowModule.new_module(name, lang))
    app.save()
    return back_to_main(request, domain, app_id=app.id, module_id=module.id)
Ejemplo n.º 16
0
def handle_shadow_child_modules(app, shadow_parent):
    """Creates or deletes shadow child modules if the parent module requires

    Used primarily when changing the "source module id" of a shadow module
    """
    changes = False

    if shadow_parent.shadow_module_version == 1:
        # For old-style shadow modules, we don't create any child-shadows
        return False

    if not shadow_parent.source_module_id:
        return False

    # if the source module is a child, but not a shadow, then the shadow should have the same parent
    source = app.get_module_by_unique_id(shadow_parent.source_module_id)
    if source.root_module_id != shadow_parent.root_module_id:
        shadow_parent.root_module_id = source.root_module_id
        changes = True

    source_module_children = [
        m for m in app.get_modules()
        if m.root_module_id == shadow_parent.source_module_id
        and m.module_type != 'shadow'
    ]
    source_module_children_ids = [
        source_module_child.unique_id
        for source_module_child in source_module_children
    ]

    shadow_parent_children = [
        m for m in app.get_modules()
        if m.root_module_id == shadow_parent.unique_id
    ]  # All the child shadows that already exist

    # Delete child modules that no longer have a source
    unneeded_module_ids = [
        child.unique_id for child in shadow_parent_children
        if child.source_module_id not in source_module_children_ids
    ]
    for unneeded_module_id in unneeded_module_ids:
        changes = True
        app.delete_module(unneeded_module_id)

    # We need to create child modules for those source children that don't have them
    existing_child_shadow_sources = [
        child.source_module_id for child in shadow_parent_children
    ]  # The set of source children ids that already have shadows
    needed_modules = [
        source_child for source_child in source_module_children
        if source_child.unique_id not in existing_child_shadow_sources
    ]
    for source_child in needed_modules:
        changes = True
        new_shadow = ShadowModule.new_module(
            source_child.default_name(app=app), app.default_language)
        new_shadow.source_module_id = source_child.unique_id

        # ModuleBase properties
        new_shadow.module_filter = source_child.module_filter
        new_shadow.put_in_root = source_child.put_in_root
        new_shadow.root_module_id = shadow_parent.unique_id
        new_shadow.fixture_select = deepcopy(source_child.fixture_select)
        new_shadow.report_context_tile = source_child.report_context_tile
        new_shadow.auto_select_case = source_child.auto_select_case
        new_shadow.is_training_module = source_child.is_training_module

        # ShadowModule properties
        for prop, to_deepcopy in SHADOW_MODULE_PROPERTIES_TO_COPY:
            new_value = getattr(source_child, prop)
            setattr(new_shadow, prop,
                    deepcopy(new_value) if to_deepcopy else new_value)

        # move excluded form ids
        source_child_form_ids = set(
            f.unique_id for f in app.get_module_by_unique_id(
                new_shadow.source_module_id).get_forms())
        new_shadow.excluded_form_ids = list(
            set(shadow_parent.excluded_form_ids) & source_child_form_ids)
        shadow_parent.excluded_form_ids = list(
            set(shadow_parent.excluded_form_ids) - source_child_form_ids)

        app.add_module(new_shadow)

    if changes:
        app.move_child_modules_after_parents()
        app.save()

    return changes
Ejemplo n.º 17
0
    def setUp(self):
        super().setUp()
        self.app = Application.new_app(DOMAIN, "Application with Shadow")
        self.app._id = '456'
        self.app.build_spec = BuildSpec(version='2.53.0', build_number=1)
        self.module = self.app.add_module(Module.new_module("Followup", None))
        self.form = self.app.new_form(0, "Untitled Form", None, attachment=get_simple_form("xmlns1.0"))
        self.form.requires = 'case'
        self.module.case_type = 'case'

        self.module.case_details.long.columns.append(
            DetailColumn.wrap(dict(
                header={"en": "name"},
                model="case",
                format="plain",
                field="whatever",
            ))
        )

        self.module.search_config = CaseSearch(
            properties=[
                CaseSearchProperty(name='name', label={'en': 'Name'}),
                CaseSearchProperty(name='favorite_color', label={'en': 'Favorite Color'}, itemset=Itemset(
                    instance_id='item-list:colors', instance_uri='jr://fixture/item-list:colors',
                    nodeset="instance('item-list:colors')/colors_list/colors",
                    label='name', sort='name', value='value'),
                )
            ],
            data_registry="myregistry",
            data_registry_workflow=REGISTRY_WORKFLOW_LOAD_CASE,
            additional_registry_cases=["'another case ID'"],
        )

        self.shadow_module = self.app.add_module(ShadowModule.new_module("Shadow", "en"))
        self.shadow_module.source_module_id = self.module.unique_id

        self.shadow_module.case_details.long.columns.append(
            DetailColumn.wrap(dict(
                header={"en": "name"},
                model="case",
                format="plain",
                field="whatever",
            ))
        )

        self.shadow_module.search_config = CaseSearch(
            properties=[
                CaseSearchProperty(name='name', label={'en': 'Name'}),
                CaseSearchProperty(name='favorite_color', label={'en': 'Texture'}, itemset=Itemset(
                    instance_id='item-list:textures', instance_uri='jr://fixture/item-list:textures',
                    nodeset="instance('item-list:textures')/textures_list/textures",
                    label='name', sort='name', value='value'),
                )
            ],
            data_registry="myregistry",
            data_registry_workflow=REGISTRY_WORKFLOW_LOAD_CASE,
        )

        # wrap to have assign_references called
        self.app = Application.wrap(self.app.to_json())

        # reset to newly wrapped module
        self.module = self.app.modules[0]
        self.shadow_module = self.app.modules[1]
Ejemplo n.º 18
0
 def new_shadow_module(self, slug, source_module, with_form=True):
     module = self.app.add_module(ShadowModule.new_module('{} module'.format(slug), None))
     module.unique_id = '{}_module'.format(slug)
     module.source_module_id = source_module.unique_id
     self.slugs[module.unique_id] = slug
     return (module, self.new_form(module)) if with_form else module