source: main/waeup.cas/trunk/waeup/cas/tests/test_server.py @ 10355

Last change on this file since 10355 was 10352, checked in by uli, 12 years ago

Make sure CASServer options can be set via paste.deploy ini file.

File size: 3.2 KB
Line 
1import os
2import shutil
3import tempfile
4import unittest
5from paste.deploy import loadapp
6from webob import Request
7from waeup.cas.server import CASServer
8
9
10class CASServerTests(unittest.TestCase):
11
12    def setUp(self):
13        # Create a new location where tempfiles are created.  This way
14        # also temporary dirs of local CASServers can be removed on
15        # tear-down.
16        self._new_tmpdir = tempfile.mkdtemp()
17        self._old_tmpdir = tempfile.tempdir
18        tempfile.tempdir = self._new_tmpdir
19        self.workdir = os.path.join(self._new_tmpdir, 'home')
20        self.db_path = os.path.join(self.workdir, 'mycas.db')
21        self.paste_conf1 = os.path.join(
22            os.path.dirname(__file__), 'sample1.ini')
23        self.paste_conf2 = os.path.join(
24            os.path.dirname(__file__), 'sample2.ini')
25
26    def tearDown(self):
27        # remove local tempfile and reset old tempdir setting
28        if os.path.isdir(self._new_tmpdir):
29            shutil.rmtree(self._new_tmpdir)
30        tempfile.tempdir = self._old_tmpdir
31
32    def test_paste_deploy_loader(self):
33        # we can load the CAS server via paste.deploy plugin
34        app = loadapp('config:%s' % self.paste_conf1)
35        assert isinstance(app, CASServer)
36        assert hasattr(app, 'db_path')
37        assert app.db_path is not None
38
39    def test_paste_deploy_options(self):
40        # we can set CAS server-related options via paste.deploy config
41        app = loadapp('config:%s' % self.paste_conf2)
42        assert isinstance(app, CASServer)
43        assert app.db_path == '/a/path/to/cas.db'
44
45    def test_init(self):
46        # we get a db dir set automatically
47        app = CASServer()
48        assert hasattr(app, 'db_path')
49        assert app.db_path is not None
50        assert os.path.exists(os.path.dirname(app.db_path))
51
52    def test_init_explicit_db_path(self):
53        # we can set a db_path explicitly
54        app = CASServer(db_path=self.db_path)
55        assert hasattr(app, 'db_path')
56        assert app.db_path == self.db_path
57
58    def test_call_root(self):
59        # the CAS protocol requires no root
60        app = CASServer()
61        req = Request.blank('http://localhost/')
62        resp = app(req)
63        assert resp.status == '404 Not Found'
64
65    def test_first_time_login(self):
66        # we can get a login page
67        app = CASServer()
68        req = Request.blank('http://localhost/login')
69        resp = app(req)
70        assert resp.status == '200 OK'
71
72    def test_validate(self):
73        # we can access a validation page
74        app = CASServer()
75        req = Request.blank('http://localhost/validate')
76        resp = app(req)
77        assert resp.status == '501 Not Implemented'
78
79    def test_logout(self):
80        # we can access a logout page
81        app = CASServer()
82        req = Request.blank('http://localhost/logout')
83        resp = app(req)
84        assert resp.status == '501 Not Implemented'
85
86    def test_login_simple(self):
87        # a simple login with no service will result in login screen
88        # (2.1.1#service of protocol specs)
89        app = CASServer()
90        req = Request.blank('http://localhost/login')
91        resp = app(req)
92        assert resp.status == '200 OK'
93        assert resp.content_type == 'text/html'
94        assert b'<form ' in resp.body
Note: See TracBrowser for help on using the repository browser.