source: TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/unit/paster_templates/test_paster_templates.py @ 7817

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/unit/paster_templates/test_paster_templates.py@7817
Revision 7817, 5.9 KB checked in by pjkersha, 9 years ago (diff)

Incomplete - task 16: NDG Security 2.x.x - incl. updated Paster templates

  • major progress on independent OpenID Provider template. Requires some fixes to Yadis templates to complete.
Line 
1#!/usr/bin/env python
2"""Unit tests for NDG Security paster templates
3
4NERC DataGrid Project
5"""
6__author__ = "P J Kershaw"
7__date__ = "18/11/10"
8__copyright__ = "(C) 2010 Science and Technology Facilities Council"
9__license__ = "BSD - see LICENSE file in top-level directory"
10__contact__ = "Philip.Kershaw@stfc.ac.uk"
11__revision__ = '$Id$'
12import logging
13logging.basicConfig(level=logging.DEBUG)
14log = logging.getLogger(__name__)
15
16import unittest
17from os import path, listdir, environ
18import shutil
19from paste.script.create_distro import CreateDistroCommand
20       
21_HERE_DIR = path.dirname(path.abspath(__file__))
22_NDGSEC_UNITTEST_KEEP_PASTER_CONF_DIRS = environ.get(
23    'NDGSEC_UNITTEST_KEEP_PASTER_CONF_DIRS')
24   
25
26class ServicesTemplateTestCase(unittest.TestCase):
27    """Test create configuration for an application which bundles all the NDG
28    Security Services
29    """
30    HERE_DIR = _HERE_DIR
31    SERVICE_TMPL_NAME = 'ndgsecurity_services'
32    SERVICE_CONF_DIR = 'services'
33    SERVICE_CONF_DIRPATH = path.join(HERE_DIR, SERVICE_CONF_DIR)
34    SERVICE_CONF_DIR_FILES = (
35        'pki', 'pip-mapping.txt', 'service.ini', 'policy.xml', 'user.db'
36    )
37   
38    def test01Run(self):
39        log.debug("_"*80)
40        log.debug("Creating Services template ...")
41        log.debug("_"*80)
42        cmd = CreateDistroCommand(None)
43        cmd.default_interactive = False
44        cmd.run([self.__class__.SERVICE_CONF_DIR, 
45                 '-t', 
46                 self.__class__.SERVICE_TMPL_NAME])
47       
48        createdFiles = listdir(self.__class__.SERVICE_CONF_DIRPATH)
49       
50        for _file in self.__class__.SERVICE_CONF_DIR_FILES:
51            self.assert_(_file in createdFiles, "Missing file %r" % _file)
52
53    def tearDown(self):
54        if _NDGSEC_UNITTEST_KEEP_PASTER_CONF_DIRS:
55            return
56
57        shutil.rmtree(self.__class__.SERVICE_CONF_DIRPATH, True)
58           
59
60class AttributeServiceTemplateTestCase(unittest.TestCase):
61    """Test creation of ini file and basic configuration settings for NDG
62    Security Attribute Service
63    """
64    HERE_DIR = _HERE_DIR
65    ATTRIBUTE_SERVICE_TMPL_NAME = 'ndgsecurity_attribute_service'
66    ATTRIBUTE_SERVICE_CONF_DIR = 'attribute-service'
67    ATTRIBUTE_SERVICE_CONF_DIRPATH = path.join(HERE_DIR, 
68                                                ATTRIBUTE_SERVICE_CONF_DIR)
69    ATTRIBUTE_SERVICE_CONF_DIR_FILES = (
70        'pki', 'attribute-service.ini', 'user.db'
71    )
72   
73    def test01Run(self):
74        log.debug("_"*80)
75        log.debug("Creating Attribute Service template ...")
76        log.debug("_"*80)
77        cmd = CreateDistroCommand(None)
78        cmd.default_interactive = False
79        cmd.run([self.__class__.ATTRIBUTE_SERVICE_CONF_DIR, 
80                 '-t', 
81                 self.__class__.ATTRIBUTE_SERVICE_TMPL_NAME])
82       
83        createdFiles = listdir(
84                            self.__class__.ATTRIBUTE_SERVICE_CONF_DIRPATH)
85       
86        for _file in self.__class__.ATTRIBUTE_SERVICE_CONF_DIR_FILES:
87            self.assert_(_file in createdFiles, "Missing file %r" % _file)
88
89    def tearDown(self):
90        if _NDGSEC_UNITTEST_KEEP_PASTER_CONF_DIRS:
91            return
92
93        shutil.rmtree(self.__class__.ATTRIBUTE_SERVICE_CONF_DIRPATH, True) 
94                   
95
96class AuthorisationServiceTemplateTestCase(unittest.TestCase):
97    """Test creation of ini file and basic configuration settings for NDG
98    Security Authorisation Service
99    """
100    HERE_DIR = _HERE_DIR
101    AUTHORISATION_SERVICE_TMPL_NAME = 'ndgsecurity_authorisation_service'
102    AUTHORISATION_SERVICE_CONF_DIR = 'authorisation-service'
103    AUTHORISATION_SERVICE_CONF_DIRPATH = path.join(HERE_DIR, 
104                                                AUTHORISATION_SERVICE_CONF_DIR)
105    AUTHORISATION_SERVICE_CONF_DIR_FILES = (
106        'pki', 'pip-mapping.txt', 'authorisation-service.ini', 'policy.xml'
107    )
108   
109    def test01Run(self):
110        log.debug("_"*80)
111        log.debug("Creating Authorisation Service template ...")
112        log.debug("_"*80)
113        cmd = CreateDistroCommand(None)
114        cmd.default_interactive = False
115        cmd.run([self.__class__.AUTHORISATION_SERVICE_CONF_DIR, 
116                 '-t', 
117                 self.__class__.AUTHORISATION_SERVICE_TMPL_NAME])
118       
119        createdFiles = listdir(
120                            self.__class__.AUTHORISATION_SERVICE_CONF_DIRPATH)
121       
122        for _file in self.__class__.AUTHORISATION_SERVICE_CONF_DIR_FILES:
123            self.assert_(_file in createdFiles, "Missing file %r" % _file)
124
125    def tearDown(self):
126        if _NDGSEC_UNITTEST_KEEP_PASTER_CONF_DIRS:
127            return
128
129        shutil.rmtree(self.__class__.AUTHORISATION_SERVICE_CONF_DIRPATH, True)         
130
131
132class OpenIdProviderTemplateTestCase(unittest.TestCase):
133    """Test creation of ini file and basic configuration settings for NDG
134    Security OpenID Provider Service
135    """
136    HERE_DIR = _HERE_DIR
137    OP_SERVICE_TMPL_NAME = 'ndgsecurity_openidprovider_service'
138    OP_SERVICE_CONF_DIR = 'openidprovider'
139    OP_SERVICE_CONF_DIRPATH = path.join(HERE_DIR, OP_SERVICE_CONF_DIR)
140    OP_SERVICE_CONF_DIR_FILES = (
141        'pki', 'service.ini', 'user.db', 'templates', 'public', 'log'
142    )
143   
144    def test01Run(self):
145        log.debug("_"*80)
146        log.debug("Creating OpenID Provider Service template ...")
147        log.debug("_"*80)
148        cmd = CreateDistroCommand(None)
149        cmd.default_interactive = False
150        cmd.run([self.__class__.OP_SERVICE_CONF_DIR, 
151                 '-t', 
152                 self.__class__.OP_SERVICE_TMPL_NAME])
153       
154        createdFiles = listdir(
155                            self.__class__.OP_SERVICE_CONF_DIRPATH)
156       
157        for _file in self.__class__.OP_SERVICE_CONF_DIR_FILES:
158            self.assert_(_file in createdFiles, "Missing file %r" % _file)
159
160    def tearDown(self):
161        if _NDGSEC_UNITTEST_KEEP_PASTER_CONF_DIRS:
162            return
163
164        shutil.rmtree(self.__class__.OP_SERVICE_CONF_DIRPATH, True)
165       
166
167if __name__ == "__main__":
168    unittest.main()
Note: See TracBrowser for help on using the repository browser.