def test_replace_ndn(self): idp = find_entity(root(self.t2), 'https://idp.nordu.net/idp/shibboleth') assert (idp is not None) idp2 = copy.deepcopy(idp) assert idp2 is not None for o in idp2.findall(".//{%s}OrganizationName" % NS['md']): o.text = "FOO" idp2.set('ID', 'kaka4711') replace_existing(idp, idp2) idp3 = find_entity(root(self.t2), 'kaka4711', attr='ID') assert (idp3 is not None) for o in idp2.findall(".//{%s}OrganizationName" % NS['md']): assert (o.text == "FOO") remove(idp3, None) idp = find_entity(root(self.t2), 'kaka4711', attr='ID') assert (idp3 is not None)
def merge(self, t, nt, strategy=merge_strategies.replace_existing, strategy_name=None): """ :param t: The EntitiesDescriptor element to merge *into* :param nt: The EntitiesDescriptor element to merge *from* :param strategy: A callable implementing the merge strategy pattern :param strategy_name: The name of a strategy to import. Overrides the callable if present. :return: Two EntitiesDescriptor elements are merged - the second into the first. For each element in the second collection that is present (using the @entityID attribute as key) in the first the strategy callable is called with the old and new EntityDescriptor elements as parameters. The strategy callable thus must implement the following pattern: :old_e: The EntityDescriptor from t :e: The EntityDescriptor from nt :return: A merged EntityDescriptor element Before each call to strategy old_e is removed from the MDRepository index and after merge the resultant EntityDescriptor is added to the index before it is used to replace old_e in t. """ if strategy_name is not None: strategy = find_merge_strategy(strategy_name) for e in iter_entities(nt): entity_id = e.get("entityID") # we assume ddup:ed tree old_e = find_entity(t, entity_id) new = strategy(old_e, e) if new is not None: self.update(new)