def test_remove_no_annotations_returns_same_value(self):
        xsd_string = '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' \
                     '<xs:element name="integer" type="xs:integer"/></xs:schema>'

        xsd_tree = XSDTree.build_tree(xsd_string)
        remove_annotations(xsd_tree)
        result_xsd_string = XSDTree.tostring(xsd_tree)

        self.assertTrue(xsd_string == result_xsd_string)
    def test_remove_annotations_returns_tree_without_annotations(self):
        xsd_string = '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' \
                     '<xs:annotation><xs:appinfo/></xs:annotation>' \
                     '<xs:element name="integer" type="xs:integer"/></xs:schema>'

        expected_xsd_string = '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' \
                              '<xs:element name="integer" type="xs:integer"/></xs:schema>'

        xsd_tree = XSDTree.build_tree(xsd_string)
        remove_annotations(xsd_tree)
        result_xsd_string = XSDTree.tostring(xsd_tree)

        self.assertTrue(expected_xsd_string == result_xsd_string)
Esempio n. 3
0
def build_template(request, template_id):
    """View that allows to build the Template.

    Args:
        request:
        template_id:

    Returns:

    """
    if template_id == "new":
        base_template_path = finders.find(join('core_composer_app', 'user', 'xsd', 'new_base_template.xsd'))
        xsd_string = read_file_content(base_template_path)
    else:
        template = template_api.get(template_id)
        xsd_string = template.content

    request.session['newXmlTemplateCompose'] = xsd_string
    request.session['includedTypesCompose'] = []

    # store the current includes/imports
    xsd_tree = XSDTree.build_tree(xsd_string)
    includes = xsd_tree.findall("{}include".format(LXML_SCHEMA_NAMESPACE))
    for el_include in includes:
        if 'schemaLocation' in el_include.attrib:
            request.session['includedTypesCompose'].append(el_include.attrib['schemaLocation'])
    imports = xsd_tree.findall("{}import".format(LXML_SCHEMA_NAMESPACE))
    for el_import in imports:
        if 'schemaLocation' in el_import.attrib:
            request.session['includedTypesCompose'].append(el_import.attrib['schemaLocation'])

    # remove annotations from the tree
    remove_annotations(xsd_tree)
    xsd_string = XSDTree.tostring(xsd_tree)

    # loads XSLT
    xslt_path = finders.find(join('core_composer_app', 'user', 'xsl', 'xsd2html.xsl'))
    # reads XSLT
    xslt_string = read_file_content(xslt_path)
    # transform XML to HTML
    xsd_to_html_string = xsl_transform(xsd_string, xslt_string)

    # 1) Get user defined types
    user_types = type_version_manager_api.get_version_managers_by_user(str(request.user.id))
    # 2) Get buckets
    buckets = bucket_api.get_all()

    # 3) no_buckets_types: list of types that are not assigned to a specific bucket
    no_buckets_types = type_version_manager_api.get_no_buckets_types()

    # 4) Build list of built-in types
    built_in_types = []
    for built_in_type in get_xsd_types():
        built_in_types.append({'current': 'built_in_type', 'title': built_in_type})

    assets = {
        "js": [
            {
                "path": 'core_composer_app/user/js/build_template.js',
                "is_raw": False
            },
            {
                "path": 'core_composer_app/user/js/build_template.raw.js',
                "is_raw": True
            },
            {
                "path": 'core_composer_app/user/js/xpath.js',
                "is_raw": False
            },
            {
                "path": 'core_composer_app/user/js/menus.js',
                "is_raw": False
            },
            {
                "path": 'core_composer_app/user/js/xsd_tree.js',
                "is_raw": False
            },
        ],
        "css": ['core_main_app/common/css/XMLTree.css',
                'core_composer_app/common/css/bucket.css',
                'core_composer_app/user/css/menu.css',
                'core_composer_app/user/css/style.css',
                'core_composer_app/user/css/xsd_tree.css']
    }
    context = {
        'buckets': buckets,
        'built_in_types': built_in_types,
        'no_buckets_types': no_buckets_types,
        'user_types': user_types,
        'xsd_form': xsd_to_html_string,
        'template_id': template_id,
    }

    modals = [
        'core_composer_app/user/builder/menus/sequence.html',
        'core_composer_app/user/builder/menus/element.html',
        'core_composer_app/user/builder/menus/element_root.html',

        'core_composer_app/user/builder/modals/root_type_name.html',
        'core_composer_app/user/builder/modals/element_name.html',
        'core_composer_app/user/builder/modals/insert_element.html',
        'core_composer_app/user/builder/modals/delete_element.html',
        'core_composer_app/user/builder/modals/change_type.html',
        'core_composer_app/user/builder/modals/save_template.html',
        'core_composer_app/user/builder/modals/save_type.html',
        'core_composer_app/user/builder/modals/save_success.html',
        'core_composer_app/user/builder/modals/occurrences.html',
        'core_composer_app/user/builder/modals/errors.html',
    ]

    return render(request,
                  'core_composer_app/user/build_template.html',
                  assets=assets,
                  context=context,
                  modals=modals)