Changeset 10351 for main/waeup.cas


Ignore:
Timestamp:
22 Jun 2013, 21:47:04 (11 years ago)
Author:
uli
Message:

Add a db_path option for CAS server.

Location:
main/waeup.cas/trunk/waeup/cas
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • main/waeup.cas/trunk/waeup/cas/server.py

    r10343 r10351  
    22"""
    33import os
     4import tempfile
    45from webob import exc, Response
    56from webob.dec import wsgify
     
    1011class CASServer(object):
    1112    """A WSGI CAS server.
     13
     14    This CAS server stores credential data (tickets, etc.) in a local
     15    sqlite3 database file.
     16
     17    `db_path` -
     18       The filesystem path to the database to use. If none is given
     19       CAS server will create a new one in some new, temporary
     20       directory. Please note that credentials will be lost after a
     21       CAS server restart.
     22
     23       If the path is given and the file exists already, it will be
     24       used.
     25
     26       If the database file does not exist, it will be created.
    1227    """
     28    def __init__(self, db_path=None):
     29        if db_path is None:
     30            db_path = os.path.join(tempfile.mkdtemp(), 'cas.db')
     31        self.db_path = db_path
     32
    1333    @wsgify
    1434    def __call__(self, req):
  • main/waeup.cas/trunk/waeup/cas/tests/test_server.py

    r10348 r10351  
    3838        assert isinstance(app, CASServer)
    3939
     40    def test_init(self):
     41        # we get a db dir set automatically
     42        app = CASServer()
     43        assert hasattr(app, 'db_path')
     44        assert app.db_path is not None
     45        assert os.path.exists(os.path.dirname(app.db_path))
     46
     47    def test_init_explicit_db_path(self):
     48        # we can set a db_path explicitly
     49        app = CASServer(db_path=self.db_path)
     50        assert hasattr(app, 'db_path')
     51        assert app.db_path == self.db_path
     52
    4053    def test_call_root(self):
    4154        # the CAS protocol requires no root
Note: See TracChangeset for help on using the changeset viewer.