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

@@ -57,6 +57,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":
return object.__getattribute__(self, item)

View File

@@ -218,3 +218,16 @@ def test_sp():
assert cnf.endpoint("assertion_consumer_service") == \
"http://lingon.catalogix.se:8087/"
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"