Ejemplo n.º 1
0
def test_dependencies_2():
    """
    Two dependencies
    EntityDep4 has an array field (deps1) with deps from EntityDep1
    EntityDep4 has a string field (dep2) with deps from EntityDep2
    """
    api = load_test_open_api_spec()
    EntityDep1 = api.entities['EntityDep1'].cls
    EntityDep2 = api.entities['EntityDep2'].cls
    EntityDep4 = api.entities['EntityDep4'].cls
    deps1 = EntitiesSet({
        EntityWrapper(EntityDep1(id='d11', name='dep11')),
        EntityWrapper(EntityDep1(id='d12', name='dep12')),
        EntityWrapper(EntityDep1(id='d13', name='dep13')),
    })
    deps2 = EntitiesSet({
        EntityWrapper(EntityDep2(id='d21', name='dep21')),
        EntityWrapper(EntityDep2(id='d22', name='dep22')),
        EntityWrapper(EntityDep2(id='d23', name='dep23')),
    })

    # no conflicts
    deps4 = EntitiesSet({
        EntityWrapper(
            EntityDep4(id='d31',
                       name='dep31',
                       deps1=frozenset({'dep11', 'dep12'}),
                       dep2='dep23'))
    })
    deps3_resolved, conflicts = resolve_entities(deps4, [(deps1, 'deps1'),
                                                         (deps2, 'dep2')])
    assert conflicts is None
    assert deps3_resolved.entities == {
        EntityWrapper(
            EntityDep4(id='d31',
                       name='dep31',
                       deps1=frozenset({'d11', 'd12'}),
                       dep2='d23'))
    }

    # conflicts in field deps1
    deps4 = EntitiesSet({
        EntityWrapper(
            EntityDep4(id='d31',
                       name='dep31',
                       deps1=frozenset({'dep14', 'dep12'}),
                       dep2='dep33'))
    })
    deps3_resolved, conflicts = resolve_entities(deps4, [(deps1, 'deps1'),
                                                         (deps2, 'dep2')])
    assert conflicts == {
        'dep31': {
            'deps1': frozenset({'dep14'}),
            'dep2': frozenset({'dep33'})
        }
    }
Ejemplo n.º 2
0
def test_dependencies_3():
    """
    several dependencies (even nested)
    See EntityDep5 for details
    """
    api = load_test_open_api_spec()
    EntityDep1 = api.entities['EntityDep1'].cls
    EntityDep5 = api.entities['EntityDep5'].cls
    EntityDep5_Obj1 = api.entities['EntityDep5_Obj1'].cls
    EntityDep5_Obj1_Obj2 = api.entities['EntityDep5_Obj1_Obj2'].cls
    deps1 = EntitiesSet({
        EntityWrapper(EntityDep1(id='d11', name='dep11')),
        EntityWrapper(EntityDep1(id='d12', name='dep12')),
        EntityWrapper(EntityDep1(id='d13', name='dep13')),
    })
    data = {'id': 'd51', 'name': 'dep51', 'obj1': {'obj2': {'dep1': 'dep11'}}}
    deps5 = EntitiesSet(
        {EntityWrapper(K8S_LOADER.load(data, None, EntityDep5))})
    deps5_resolved, conflicts = resolve_entities(deps5,
                                                 [(deps1, 'obj1.obj2.dep1')])
    assert conflicts is None
    assert deps5_resolved.entities == {
        EntityWrapper(
            EntityDep5(
                id='d51',
                name='dep51',
                obj1=EntityDep5_Obj1(obj2=EntityDep5_Obj1_Obj2(dep1='d11'))))
    }
Ejemplo n.º 3
0
def test_normalize_policies_3():
    policies = EntitiesSet({
        EntityWrapper(
            policy(
                name='policy-1',
                entitlements=['entitlement1', 'entitlement2',
                              'entitlement3'])),
        EntityWrapper(
            policy(name='policy-2',
                   entitlements=[
                       'entitlement1',
                       'entitlement4',
                       'entitlement5',
                   ])),
    })
    entitlements = EntitiesSet({
        EntityWrapper(entitlement(id='id1', name='entitlement1')),
        EntityWrapper(entitlement(id='id2', name='entitlement2')),
        EntityWrapper(entitlement(id='id3', name='entitlement3')),
        EntityWrapper(entitlement(name='entitlement5'))
    })
    policies_set, conflicts = resolve_entities(
        policies, [(entitlements, 'entitlements')])
    assert conflicts == {
        'policy-2': {
            'entitlements': frozenset({'entitlement4', 'entitlement5'})
        }
    }
Ejemplo n.º 4
0
def test_normalize_policies_1():
    policies = EntitiesSet({
        EntityWrapper(
            policy(
                name='policy-1',
                entitlements=['entitlement1', 'entitlement2',
                              'entitlement3'])),
        EntityWrapper(
            policy(name='policy-2',
                   entitlements=[
                       'entitlement1',
                       'entitlement2',
                       'entitlement3',
                   ])),
    })
    entitlements = EntitiesSet()
    policies_set, conflicts = resolve_entities(
        policies, [(entitlements, 'entitlements')])
    assert conflicts == {
        'policy-1': {
            'entitlements':
            frozenset({'entitlement1', 'entitlement2', 'entitlement3'})
        },
        'policy-2': {
            'entitlements':
            frozenset({'entitlement1', 'entitlement2', 'entitlement3'})
        }
    }
Ejemplo n.º 5
0
def test_normalize_policies_2():
    policies = EntitiesSet({
        EntityWrapper(
            policy(
                name='policy-1',
                entitlements=['entitlement1', 'entitlement2',
                              'entitlement3'])),
        EntityWrapper(
            policy(name='policy-2',
                   entitlements=[
                       'entitlement1',
                       'entitlement4',
                       'entitlement5',
                   ])),
    })
    entitlements = EntitiesSet({
        EntityWrapper(entitlement(id='e1', name='entitlement1')),
        EntityWrapper(entitlement(id='e2', name='entitlement2')),
        EntityWrapper(entitlement(id='e3', name='entitlement3')),
        EntityWrapper(entitlement(id='e4', name='entitlement4')),
        EntityWrapper(entitlement(id='e5', name='entitlement5')),
    })
    policies_set, conflicts = resolve_entities(
        policies, [(entitlements, 'entitlements')])
    assert conflicts is None
    assert policies_set.entities == {
        EntityWrapper(policy(name='policy-1', entitlements=['e1', 'e2',
                                                            'e3'])),
        EntityWrapper(
            policy(name='policy-2', entitlements=[
                'e1',
                'e4',
                'e5',
            ])),
    }
Ejemplo n.º 6
0
def test_normalize_policies_0():
    policies = EntitiesSet()
    entitlements = EntitiesSet()
    policies_set, conflicts = resolve_entities(
        policies, [(entitlements, 'entitlements')])
    assert policies_set.entities == set()
    assert conflicts is None
Ejemplo n.º 7
0
def test_normalize_entitlements_3():
    entitlements = EntitiesSet({
        EntityWrapper(
            entitlement(name='entitlement-1',
                        conditions=['condition1', 'condition2',
                                    'condition3'])),
        EntityWrapper(
            entitlement(name='entitlement-2',
                        conditions=[
                            'condition1',
                            'condition4',
                            'condition5',
                        ])),
    })
    conditions = EntitiesSet({
        EntityWrapper(condition(id='id1', name='condition1')),
        EntityWrapper(condition(id='id2', name='condition2')),
        EntityWrapper(condition(id='id3', name='condition3')),
        EntityWrapper(condition(name='condition4')),
        EntityWrapper(condition(name='condition5')),
    })
    entitlements_set, conflicts = resolve_entities(
        entitlements, [(conditions, 'conditions')])
    assert conflicts == {
        'entitlement-2': {
            'conditions': frozenset({'condition4', 'condition5'}),
        }
    }
Ejemplo n.º 8
0
def test_normalize_entitlements_2():
    entitlements = EntitiesSet({
        EntityWrapper(
            entitlement(name='entitlement-1',
                        conditions=['condition1', 'condition2',
                                    'condition3'])),
        EntityWrapper(
            entitlement(name='entitlement-2',
                        conditions=[
                            'condition1',
                            'condition4',
                            'condition5',
                        ])),
    })
    conditions = EntitiesSet({
        EntityWrapper(condition(id='c1', name='condition1')),
        EntityWrapper(condition(id='c2', name='condition2')),
        EntityWrapper(condition(id='c3', name='condition3')),
        EntityWrapper(condition(id='c4', name='condition4')),
        EntityWrapper(condition(id='c5', name='condition5')),
    })
    entitlements_set, conflicts = resolve_entities(
        entitlements, [(conditions, 'conditions')])
    assert entitlements_set.entities == {
        EntityWrapper(
            entitlement(name='entitlement-1', conditions=['c1', 'c2', 'c3'])),
        EntityWrapper(
            entitlement(name='entitlement-2', conditions=[
                'c1',
                'c4',
                'c5',
            ])),
    }
    assert conflicts is None
Ejemplo n.º 9
0
def test_normalize_entitlements_1():
    entitlements = EntitiesSet({
        EntityWrapper(
            entitlement(name='entitlement-1',
                        conditions=['condition1', 'condition2',
                                    'condition3'])),
        EntityWrapper(
            entitlement(name='entitlement-2',
                        conditions=[
                            'condition1',
                            'condition2',
                            'condition3',
                        ])),
    })
    conditions = EntitiesSet()
    entitlements_set, conflicts = resolve_entities(
        entitlements, [(conditions, 'conditions')])
    assert entitlements_set.entities == entitlements.entities
    assert conflicts == {
        'entitlement-1': {
            'conditions': frozenset({'condition1', 'condition2', 'condition3'})
        },
        'entitlement-2': {
            'conditions': frozenset({'condition1', 'condition2', 'condition3'})
        },
    }
Ejemplo n.º 10
0
def test_normalize_entitlements_0():
    entitlements = EntitiesSet()
    conditions = EntitiesSet()
    entitlements_set, conflicts = resolve_entities(
        entitlements, [(conditions, 'conditions')])
    assert entitlements_set.entities == set()
    assert conflicts is None
Ejemplo n.º 11
0
def test_dependencies_1():
    """
    One dependency
    EntityDep3 has an array field (deps1) with deps from EntityDep1
    """
    api = load_test_open_api_spec()
    EntityDep1 = api.entities['EntityDep1'].cls
    EntityDep3 = api.entities['EntityDep3'].cls
    deps1 = EntitiesSet({
        EntityWrapper(EntityDep1(id='d11', name='dep11')),
        EntityWrapper(EntityDep1(id='d12', name='dep12')),
        EntityWrapper(EntityDep1(id='d13', name='dep13')),
    })
    deps3 = EntitiesSet({
        EntityWrapper(
            EntityDep3(id='d31',
                       name='dep31',
                       deps1=frozenset({'dep11', 'dep12'})))
    })

    # No conflits
    deps3_resolved, conflicts = resolve_entities(deps3, [(deps1, 'deps1')])
    assert conflicts is None
    assert deps3_resolved.entities == {
        EntityWrapper(
            EntityDep3(id='d31', name='dep31', deps1=frozenset({'d11',
                                                                'd12'})))
    }

    # Conflicts
    deps3 = EntitiesSet({
        EntityWrapper(
            EntityDep3(id='d31',
                       name='dep31',
                       deps1=frozenset({'dep14', 'dep12'})))
    })
    deps3_resolved, conflicts = resolve_entities(deps3, [(deps1, 'deps1')])
    assert conflicts == {'dep31': {'deps1': frozenset({'dep14'})}}