Added beginging of root logger, modifed setup.py to support python setup.py test.

Added a few todos.
This commit is contained in:
Chris Austin
2011-03-15 19:49:04 -04:00
parent 8023394219
commit c36a9a7d3e
8 changed files with 2181 additions and 16 deletions

10
.bzrignore Normal file
View File

@@ -0,0 +1,10 @@
.idea
build
python_saml2.egg-info
dist
.coverage
htmlcov
*.bak
*.dat
*.dir
*.log

2105
runtests.py Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -17,11 +17,24 @@
# #
# #
from distutils.core import Command
from setuptools import setup, find_packages from setuptools import setup, find_packages
class PyTest(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import sys,subprocess
errno = subprocess.call([sys.executable, 'runtests.py'])
raise SystemExit(errno)
setup( setup(
name='pysaml2', name='python-saml2',
version='0.2.0', version='0.2.0',
description='Python implementation of SAML Version 2 to be used with WSGI applications', description='Python implementation of SAML Version 2 to be used with WSGI applications',
# long_description = read("README"), # long_description = read("README"),
@@ -29,14 +42,20 @@ setup(
author_email='roland.hedberg@adm.umu.se', author_email='roland.hedberg@adm.umu.se',
license='Apache 2.0', license='Apache 2.0',
url='https://code.launchpad.net/~roland-hedberg/pysaml2/main', url='https://code.launchpad.net/~roland-hedberg/pysaml2/main',
packages=find_packages('src'),
package_dir={'': 'src'}, packages=['saml2', 'xmldsig', 'xmlenc', 's2repoze',
classifiers=[ 's2repoze.plugins'],
"Development Status :: 4 - Beta",
package_dir = {'saml2':'src/saml2', 'xmldsig':'src/xmldsig',
'xmlenc': 'src/xmlenc',
's2repoze': 'src/s2repoze'},
classifiers = ["Development Status :: 4 - Beta",
"License :: OSI Approved :: Apache Software License", "License :: OSI Approved :: Apache Software License",
"Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Software Development :: Libraries :: Python Modules"],
],
scripts=["tools/parse_xsd2.py", "tools/make_metadata.py"], scripts=["tools/parse_xsd2.py", "tools/make_metadata.py"],
install_requires=[ install_requires=[
# core dependencies # core dependencies
'decorator', 'decorator',
@@ -44,10 +63,14 @@ setup(
# for the tests: # for the tests:
'pyasn1', 'pyasn1',
'python-memcached', 'python-memcached',
"pytest",
"pytest-coverage",
# for s2repoze: # for s2repoze:
'paste', 'paste',
'zope.interface', 'zope.interface',
'repoze.who<2.0', 'repoze.who<2.0',
], ],
zip_safe=False, zip_safe=False,
cmdclass = {'test': PyTest},
) )

View File

@@ -46,7 +46,9 @@
# raise ImportError, "lxml or ElementTree are not installed, "\ # raise ImportError, "lxml or ElementTree are not installed, "\
# +"see http://codespeak.net/lxml "\ # +"see http://codespeak.net/lxml "\
# +"or http://effbot.org/zone/element-index.htm" # +"or http://effbot.org/zone/element-index.htm"
import logging
try: try:
from xml.etree import cElementTree as ElementTree from xml.etree import cElementTree as ElementTree
except ImportError: except ImportError:
@@ -55,6 +57,9 @@ except ImportError:
except ImportError: except ImportError:
from elementtree import ElementTree from elementtree import ElementTree
root_logger = logging.getLogger("pySAML2")
root_logger.level = logging.NOTSET
NAMESPACE = 'urn:oasis:names:tc:SAML:2.0:assertion' NAMESPACE = 'urn:oasis:names:tc:SAML:2.0:assertion'
#TEMPLATE = '{urn:oasis:names:tc:SAML:2.0:assertion}%s' #TEMPLATE = '{urn:oasis:names:tc:SAML:2.0:assertion}%s'
#XSI_NAMESPACE = 'http://www.w3.org/2001/XMLSchema-instance' #XSI_NAMESPACE = 'http://www.w3.org/2001/XMLSchema-instance'
@@ -740,4 +745,4 @@ def extension_element_to_element(extension_element, translation_functions,
pass pass
return None return None

View File

@@ -12,7 +12,7 @@ from saml2.metadata import ENDPOINTS, DEFAULT_BINDING
class MissingValue(Exception): class MissingValue(Exception):
pass pass
def entity_id2url(meta, entity_id): def entity_id2url(meta, entity_id):
""" Grab the first endpoint if there are more than one, """ Grab the first endpoint if there are more than one,
raises IndexError if the function returns an empty list. raises IndexError if the function returns an empty list.
@@ -82,6 +82,17 @@ class Config(dict):
self["secret"] = "abc" # not a very good secret :-) self["secret"] = "abc" # not a very good secret :-)
return self return self
def log_level(self):
"""Pass
"""
# The assumption that I am currently working on is that the app should
# be capable of specifying a logger of any manner as long as it
# follows the logging idiom found in the python standard lib.
if "logging" in self.keys():
log_level = self["logging"]
def xmlsec(self): def xmlsec(self):
return self["xmlsec_binary"] return self["xmlsec_binary"]
@@ -121,6 +132,9 @@ class Config(dict):
def attribute_converters(self): def attribute_converters(self):
return self["attrconverters"] return self["attrconverters"]
def set_logger(self):
pass
def debug(self): def debug(self):
try: try:
@@ -232,4 +246,4 @@ class SPConfig(Config):
return self["service"]["sp"]["idp"][entity_id][ return self["service"]["sp"]["idp"][entity_id][
"single_sign_on_service"][binding] "single_sign_on_service"][binding]
except KeyError: except KeyError:
return None return None

View File

@@ -1,5 +1,6 @@
import os import os
#TODO: On my system this function seems to be returning an incorrect location
def pytest_funcarg__xmlsec(request): def pytest_funcarg__xmlsec(request):
for path in os.environ["PATH"].split(":"): for path in os.environ["PATH"].split(":"):
fil = os.path.join(path, "xmlsec1") fil = os.path.join(path, "xmlsec1")

View File

@@ -68,8 +68,14 @@ def test_add_duration_2():
assert t.tm_sec == 0 assert t.tm_sec == 0
def test_str_to_time(): def test_str_to_time():
t = time.mktime(str_to_time("2000-01-12T00:00:00Z")) import calendar
assert t == 947631600.0 t = calendar.timegm(str_to_time("2000-01-12T00:00:00Z"))
#TODO: Find all instances of time.mktime(.....)
#t = time.mktime(str_to_time("2000-01-12T00:00:00Z"))
#assert t == 947631600.0
#TODO: add something to show how this time was arrived at
# do this as an external method in the
assert t == 947635200
def test_instant(): def test_instant():
inst = str_to_time(instant()) inst = str_to_time(instant())

View File

@@ -54,7 +54,8 @@ class TestIdentifier():
assert nameid.text.strip() != nameid2.text.strip() assert nameid.text.strip() != nameid2.text.strip()
def teardown_class(self): def teardown_class(self):
os.unlink("foobar.db") if os.path.exists("foobar.db"):
os.unlink("foobar.db")
class TestServer1(): class TestServer1():
def setup_class(self): def setup_class(self):
@@ -475,4 +476,4 @@ class TestServerLogout():
# allow_create="true"), # allow_create="true"),
# "foba0001@example.com", sign=True) # "foba0001@example.com", sign=True)
# print authn_resp # print authn_resp
# assert False # assert False