Added copy_into method

This commit is contained in:
Roland Hedberg
2011-03-18 13:40:45 +01:00
parent c3984d6560
commit 7678ef2866
2 changed files with 25 additions and 1 deletions

View File

@@ -56,6 +56,17 @@ class Config(object):
def serves(self):
return [t for t in ["sp", "idp", "aa"] if self._attr[t]]
def copy_into(self, typ=""):
if typ == "sp":
copy = SPConfig()
elif typ in ["idp", "aa"]:
copy = IdPConfig()
else:
copy = Config()
copy.context = typ
copy._attr = self._attr.copy()
return copy
def __getattribute__(self, item):
if item == "context":

View File

@@ -217,4 +217,17 @@ def test_sp():
BINDING_HTTP_POST) == ["http://localhost:8088/slo"]
assert cnf.endpoint("assertion_consumer_service") == \
"http://lingon.catalogix.se:8087/"
assert len(cnf.idps()) == 1
assert len(cnf.idps()) == 1
def test_dual():
cnf = Config().load_file("idp_sp_conf")
cnf.serves() == ["sp", "idp"]
spcnf = cnf.copy_into("sp")
assert isinstance(spcnf, SPConfig)
assert spcnf.context == "sp"
idpcnf = cnf.copy_into("idp")
assert isinstance(idpcnf, IdPConfig)
assert idpcnf.context == "idp"