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

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@7827
Revision 7827, 6.2 KB checked in by pjkersha, 10 years ago (diff)

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

  • integrating SQLite test user db into 'Site A' test Attribute Authority
  • Property svn:keywords set to Id
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                 '-o',
48                 self.__class__.HERE_DIR])
49       
50        createdFiles = listdir(self.__class__.SERVICE_CONF_DIRPATH)
51       
52        for _file in self.__class__.SERVICE_CONF_DIR_FILES:
53            self.assert_(_file in createdFiles, "Missing file %r" % _file)
54
55    def tearDown(self):
56        if _NDGSEC_UNITTEST_KEEP_PASTER_CONF_DIRS:
57            return
58
59        shutil.rmtree(self.__class__.SERVICE_CONF_DIRPATH, True)
60           
61
62class AttributeServiceTemplateTestCase(unittest.TestCase):
63    """Test creation of ini file and basic configuration settings for NDG
64    Security Attribute Service
65    """
66    HERE_DIR = _HERE_DIR
67    ATTRIBUTE_SERVICE_TMPL_NAME = 'ndgsecurity_attribute_service'
68    ATTRIBUTE_SERVICE_CONF_DIR = 'attribute-service'
69    ATTRIBUTE_SERVICE_CONF_DIRPATH = path.join(HERE_DIR, 
70                                               ATTRIBUTE_SERVICE_CONF_DIR)
71    ATTRIBUTE_SERVICE_CONF_DIR_FILES = (
72        'pki', 'attribute-service.ini', 'user.db', 'log'
73    )
74   
75    def test01Run(self):
76        log.debug("_"*80)
77        log.debug("Creating Attribute Service template ...")
78        log.debug("_"*80)
79        cmd = CreateDistroCommand(None)
80        cmd.default_interactive = False
81        cmd.run([self.__class__.ATTRIBUTE_SERVICE_CONF_DIR, 
82                 '-t', 
83                 self.__class__.ATTRIBUTE_SERVICE_TMPL_NAME,
84                 '-o',
85                 self.__class__.HERE_DIR])
86       
87        createdFiles = listdir(
88                            self.__class__.ATTRIBUTE_SERVICE_CONF_DIRPATH)
89       
90        for _file in self.__class__.ATTRIBUTE_SERVICE_CONF_DIR_FILES:
91            self.assert_(_file in createdFiles, "Missing file %r" % _file)
92
93    def tearDown(self):
94        if _NDGSEC_UNITTEST_KEEP_PASTER_CONF_DIRS:
95            return
96
97        shutil.rmtree(self.__class__.ATTRIBUTE_SERVICE_CONF_DIRPATH, True) 
98                   
99
100class AuthorisationServiceTemplateTestCase(unittest.TestCase):
101    """Test creation of ini file and basic configuration settings for NDG
102    Security Authorisation Service
103    """
104    HERE_DIR = _HERE_DIR
105    AUTHORISATION_SERVICE_TMPL_NAME = 'ndgsecurity_authorisation_service'
106    AUTHORISATION_SERVICE_CONF_DIR = 'authorisation-service'
107    AUTHORISATION_SERVICE_CONF_DIRPATH = path.join(HERE_DIR, 
108                                                AUTHORISATION_SERVICE_CONF_DIR)
109    AUTHORISATION_SERVICE_CONF_DIR_FILES = (
110        'pki', 'pip-mapping.txt', 'authorisation-service.ini', 'policy.xml'
111    )
112   
113    def test01Run(self):
114        log.debug("_"*80)
115        log.debug("Creating Authorisation Service template ...")
116        log.debug("_"*80)
117        cmd = CreateDistroCommand(None)
118        cmd.default_interactive = False
119        cmd.run([self.__class__.AUTHORISATION_SERVICE_CONF_DIR, 
120                 '-t', 
121                 self.__class__.AUTHORISATION_SERVICE_TMPL_NAME,
122                 '-o',
123                 self.__class__.HERE_DIR])
124       
125        createdFiles = listdir(
126                            self.__class__.AUTHORISATION_SERVICE_CONF_DIRPATH)
127       
128        for _file in self.__class__.AUTHORISATION_SERVICE_CONF_DIR_FILES:
129            self.assert_(_file in createdFiles, "Missing file %r" % _file)
130
131    def tearDown(self):
132        if _NDGSEC_UNITTEST_KEEP_PASTER_CONF_DIRS:
133            return
134
135        shutil.rmtree(self.__class__.AUTHORISATION_SERVICE_CONF_DIRPATH, True)         
136
137
138class OpenIdProviderTemplateTestCase(unittest.TestCase):
139    """Test creation of ini file and basic configuration settings for NDG
140    Security OpenID Provider Service
141    """
142    HERE_DIR = _HERE_DIR
143    OP_SERVICE_TMPL_NAME = 'ndgsecurity_openidprovider'
144    OP_SERVICE_CONF_DIR = 'openidprovider'
145    OP_SERVICE_CONF_DIRPATH = path.join(HERE_DIR, OP_SERVICE_CONF_DIR)
146    OP_SERVICE_CONF_DIR_FILES = (
147        'pki', 'service.ini', 'user.db', 'templates', 'public', 'log'
148    )
149   
150    def test01Run(self):
151        log.debug("_"*80)
152        log.debug("Creating OpenID Provider Service template ...")
153        log.debug("_"*80)
154        cmd = CreateDistroCommand(None)
155        cmd.default_interactive = False
156        cmd.run([self.__class__.OP_SERVICE_CONF_DIR, 
157                 '-t', 
158                 self.__class__.OP_SERVICE_TMPL_NAME,
159                 '-o',
160                 self.__class__.HERE_DIR])
161       
162        createdFiles = listdir(
163                            self.__class__.OP_SERVICE_CONF_DIRPATH)
164       
165        for _file in self.__class__.OP_SERVICE_CONF_DIR_FILES:
166            self.assert_(_file in createdFiles, "Missing file %r" % _file)
167
168    def tearDown(self):
169        if _NDGSEC_UNITTEST_KEEP_PASTER_CONF_DIRS:
170            return
171
172        shutil.rmtree(self.__class__.OP_SERVICE_CONF_DIRPATH, True)
173       
174
175if __name__ == "__main__":
176    unittest.main()
Note: See TracBrowser for help on using the repository browser.