Пример #1
0
def test_imediate_circular_dependency_rename_must_return_expected_result(
        basic_trees, basic_types):
    root, new_root = basic_trees

    # Circular dependency of network just inside network
    root_network = root.get_child_by_name('Network')
    root_network.add_child(root_network)

    # Add a new module node inside network of our ORIGINAL tree
    root_module_type = entities.ElementType(
        name='ModuleType',
        children=[
            entities.Element(name='Owner',
                             element_type=basic_types['token_type']),
        ])

    root_network.add_child(
        entities.Element(name='Module', element_type=root_module_type))

    # Add a new module node inside network of our NEW tree
    module_type = entities.ElementType(
        name='ModuleType',
        children=[
            entities.Element(name='Name',
                             element_type=basic_types['token_type']),
        ])

    network = new_root.get_child_by_name('Network')

    # Adding a circular dependency
    network.add_child(network)

    network.add_child(entities.Element(name='Module',
                                       element_type=module_type))

    recalculate_hashes(new_root)
    recalculate_hashes(root)

    result = compare(root, new_root)

    expected_renames = [('/Root/Network/Module/Owner',
                         '/Root/Network/Module/Name')]

    assert result['renames'] == expected_renames
    others_empty(result, 'renames')
Пример #2
0
def create_network_type(basic_types):
    network_children = [
        entities.Element(name='Owner', element_type=basic_types['token_type']),
        entities.Element(name='ReadOnly',
                         element_type=basic_types['boolean_type']),
    ]

    e_type = entities.ElementType(name='NetworkType',
                                  children=network_children)
    e_type.annotation = 'Node to describe network elements'
    return e_type
Пример #3
0
def create_root_type(basic_types, network_type):
    # Root type
    root_children = [
        entities.Element(name='Network', element_type=network_type),
        entities.Element(name='Owner', element_type=basic_types['token_type']),
        entities.Element(name='ReadOnly',
                         element_type=basic_types['boolean_type']),
        entities.Element(name='Service',
                         element_type=basic_types['token_type']),
    ]

    return entities.ElementType(name='RootType', children=root_children)
Пример #4
0
def test_relocation_with_new_sub_element_must_return_expected_result(
        basic_trees, basic_types):
    root, new_root = basic_trees

    # Moving Root->Service to new node Root->Module->Service
    service = new_root.children[3]
    new_root.remove_child(service)

    module_children = [
        entities.Element(name='Owner', element_type=basic_types['token_type']),
        service
    ]

    module_type = entities.ElementType(name='ModuleType',
                                       children=module_children)

    module = entities.Element(name='Module', element_type=module_type)

    new_root.add_child(module)

    recalculate_hashes(new_root)
    recalculate_hashes(root)

    # Now, they must be different
    assert root != new_root

    result = compare(root, new_root)

    expected_relocations = [('/Root/Service', '/Root/Module/Service')]

    expected_additions = ['/Root/Module']

    expected_removals = ['/Root/Service']

    assert result['relocations'] == expected_relocations
    assert result['additions'] == expected_additions
    assert result['removals'] == expected_removals

    others_empty(result, 'relocations', 'additions', 'removals')
Пример #5
0
def test_circular_dependency_rename_tag_must_return_expected_result(
        basic_trees, basic_types):
    root, new_root = basic_trees
    network = new_root.children[0]

    # Rename Root->Network->ReadOnly attr
    network.children[1].name = 'OnlyRead'

    module_children = [
        entities.Element(name='Owner', element_type=basic_types['token_type']),
        network  # Adding a ciclic dependency here
    ]

    module_type = entities.ElementType(name='ModuleType',
                                       children=module_children)

    module = entities.Element(name='Module', element_type=module_type)

    network.add_child(module)

    recalculate_hashes(new_root)
    recalculate_hashes(root)

    expected_renames = [
        ('/Root/Network/ReadOnly', '/Root/Network/OnlyRead'),
    ]

    expected_additions = [
        '/Root/Network/Module',
    ]

    result = compare(root, new_root)

    assert result['renames'] == expected_renames
    assert result['additions'] == expected_additions

    others_empty(result, 'renames', 'additions')
Пример #6
0
def basic_types():
    return {
        'boolean_type': entities.ElementType(name='xsd:boolean'),
        'token_type': entities.ElementType(name='xsd:token')
    }