usr/src/lib/install_utils/test/test_manifest_serv.py
changeset 862 e9f31f2f2f2d
child 1169 83735ef8ac29
equal deleted inserted replaced
861:ccd399d2c6f7 862:e9f31f2f2f2d
       
     1 #!/usr/bin/python2.6
       
     2 #
       
     3 # CDDL HEADER START
       
     4 #
       
     5 # The contents of this file are subject to the terms of the
       
     6 # Common Development and Distribution License (the "License").
       
     7 # You may not use this file except in compliance with the License.
       
     8 #
       
     9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
    10 # or http://www.opensolaris.org/os/licensing.
       
    11 # See the License for the specific language governing permissions
       
    12 # and limitations under the License.
       
    13 #
       
    14 # When distributing Covered Code, include this CDDL HEADER in each
       
    15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    16 # If applicable, add the following below this CDDL HEADER, with the
       
    17 # fields enclosed by brackets "[]" replaced with your own identifying
       
    18 # information: Portions Copyright [yyyy] [name of copyright owner]
       
    19 #
       
    20 # CDDL HEADER END
       
    21 #
       
    22 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
       
    23 #
       
    24 
       
    25 '''
       
    26 To run these tests, see the instructions in usr/src/tools/tests/README.
       
    27 Remember that since the proto area is used for the PYTHONPATH, the gate
       
    28 must be rebuilt for these tests to pick up any changes in the tested code.
       
    29 Note: the XML and DTD files are picked up from usr/src/cmd/auto-install
       
    30 and not the proto area.
       
    31 '''
       
    32 
       
    33 import gettext
       
    34 import unittest
       
    35 
       
    36 from osol_install.ManifestServ import ManifestServ
       
    37 from osol_install.DefValProc import ManifestProcError
       
    38 
       
    39 
       
    40 # This is the path for the Manifest and Schema files.
       
    41 # It is relative to usr/src in the current workspace.
       
    42 XML_DIR="cmd/auto-install"
       
    43 
       
    44 
       
    45 class DTDManifest(unittest.TestCase):
       
    46     '''Tests for DTD Manifests'''
       
    47 
       
    48     def setUp(self):
       
    49         # Create a ManifestServ for the default Manifest, default.xml.
       
    50         self.man_serv = ManifestServ("%s/default" % XML_DIR,
       
    51             full_init=False)
       
    52 
       
    53     def test_create(self):
       
    54         '''ManifestServ: can be instantiated with manifest default.xml'''
       
    55 
       
    56         instance_names = self.man_serv.get_values("auto_install/ai_instance/name")
       
    57         print "instance_names = [%s]" % instance_names
       
    58         self.assertEquals(len(instance_names), 1)
       
    59         self.assertEquals(instance_names[0], "default")
       
    60 
       
    61     def test_validate_fails_if_dtd_schema_is_false(self):
       
    62         '''ManifestServ: validate fails if dtd_schema is False'''
       
    63 
       
    64         self.assertRaises(ManifestProcError,
       
    65             self.man_serv.schema_validate,
       
    66             schema_name="%s/ai.dtd" % XML_DIR,
       
    67             dtd_schema=False)
       
    68 
       
    69     def test_validate_succeeds_if_dtd_schema_is_true(self):
       
    70         '''ManifestServ: validate succeeds if dtd_schema is True'''
       
    71 
       
    72         try:
       
    73             self.man_serv.schema_validate(
       
    74                 schema_name="%s/ai.dtd" % XML_DIR,
       
    75                 dtd_schema=True)
       
    76         except ManifestProcError, err:
       
    77             self.fail("schema_validate unexpectedly failed: [%s]" % str(err))
       
    78 
       
    79 
       
    80 if __name__ == '__main__':
       
    81     unittest.main()