<s> import os <EOL> import sys <EOL> import lxml . etree <EOL> from mock import Mock , MagicMock , patch <EOL> from Bcfg2 . Server . Plugins . Bundler import * <EOL> from Bcfg2 . version import Bcfg2VersionInfo <EOL> path = os . path . dirname ( __file__ ) <EOL> while path != "<STR_LIT:/>" : <EOL> if os . path . basename ( path ) . lower ( ) . startswith ( "<STR_LIT:test>" ) : <EOL> sys . path . append ( path ) <EOL> if os . path . basename ( path ) == "<STR_LIT>" : <EOL> break <EOL> path = os . path . dirname ( path ) <EOL> from common import * <EOL> from TestPlugin import TestStructFile , TestPlugin , TestStructure , TestXMLDirectoryBacked <EOL> class TestBundleFile ( TestStructFile ) : <EOL> test_obj = BundleFile <EOL> path = os . path . join ( datastore , "<STR_LIT:test>" , "<STR_LIT>" ) <EOL> def test_bundle_name ( self ) : <EOL> cases = [ ( "<STR_LIT>" , "<STR_LIT:foo>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT:foo>" ) ] <EOL> bf = self . get_obj ( ) <EOL> for fname , bname in cases : <EOL> bf . name = fname <EOL> self . assertEqual ( bf . bundle_name , bname ) <EOL> class TestBundler ( TestPlugin , TestStructure , TestXMLDirectoryBacked ) : <EOL> test_obj = Bundler <EOL> def get_obj ( self , core = None ) : <EOL> @ patch ( "<STR_LIT>" % ( self . test_obj . __module__ , <EOL> self . test_obj . __name__ ) , <EOL> Mock ( ) ) <EOL> def inner ( ) : <EOL> return TestPlugin . get_obj ( self , core = core ) <EOL> return inner ( ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_HandleEvent ( self , mock_HandleEvent ) : <EOL> b = self . get_obj ( ) <EOL> b . bundles = dict ( foo = Mock ( ) , bar = Mock ( ) ) <EOL> b . entries = { "<STR_LIT>" : BundleFile ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : BundleFile ( "<STR_LIT>" ) } <EOL> event = Mock ( ) <EOL> b . HandleEvent ( event ) <EOL> mock_HandleEvent . assert_called_with ( b , event ) <EOL> self . assertItemsEqual ( b . bundles , <EOL> dict ( foo = b . entries [ '<STR_LIT>' ] , <EOL> baz = b . entries [ '<STR_LIT>' ] ) ) <EOL> def test_BuildStructures ( self ) : <EOL> b = self . get_obj ( ) <EOL> b . bundles = dict ( error = Mock ( ) , skip = Mock ( ) , xinclude = Mock ( ) , <EOL> has_dep = Mock ( ) , is_dep = Mock ( ) , indep = Mock ( ) ) <EOL> expected = dict ( ) <EOL> b . bundles [ '<STR_LIT:error>' ] . XMLMatch . side_effect = TemplateError ( None ) <EOL> xinclude = lxml . etree . Element ( "<STR_LIT>" ) <EOL> lxml . etree . SubElement ( lxml . etree . SubElement ( xinclude , "<STR_LIT>" ) , <EOL> "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> b . bundles [ '<STR_LIT>' ] . XMLMatch . return_value = xinclude <EOL> expected [ '<STR_LIT>' ] = lxml . etree . Element ( "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> lxml . etree . SubElement ( expected [ '<STR_LIT>' ] , "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> has_dep = lxml . etree . Element ( "<STR_LIT>" ) <EOL> lxml . etree . SubElement ( has_dep , "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> lxml . etree . SubElement ( has_dep , "<STR_LIT>" , name = "<STR_LIT>" , <EOL> inherit_modification = "<STR_LIT:true>" ) <EOL> lxml . etree . SubElement ( has_dep , "<STR_LIT>" , name = "<STR_LIT:foo>" ) <EOL> b . bundles [ '<STR_LIT>' ] . XMLMatch . return_value = has_dep <EOL> expected [ '<STR_LIT>' ] = lxml . etree . Element ( "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> lxml . etree . SubElement ( expected [ '<STR_LIT>' ] , "<STR_LIT>" , name = "<STR_LIT:foo>" ) <EOL> lxml . etree . SubElement ( expected [ '<STR_LIT>' ] , "<STR_LIT>" , <EOL> name = "<STR_LIT>" ) <EOL> is_dep = lxml . etree . Element ( "<STR_LIT>" ) <EOL> lxml . etree . SubElement ( is_dep , "<STR_LIT>" , name = "<STR_LIT:bar>" ) <EOL> b . bundles [ '<STR_LIT>' ] . XMLMatch . return_value = is_dep <EOL> expected [ '<STR_LIT>' ] = lxml . etree . Element ( "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> lxml . etree . SubElement ( expected [ '<STR_LIT>' ] , "<STR_LIT>" , name = "<STR_LIT:bar>" ) <EOL> indep = lxml . etree . Element ( "<STR_LIT>" , independent = "<STR_LIT:true>" ) <EOL> lxml . etree . SubElement ( indep , "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> b . bundles [ '<STR_LIT>' ] . XMLMatch . return_value = indep <EOL> expected [ '<STR_LIT>' ] = lxml . etree . Element ( "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> lxml . etree . SubElement ( expected [ '<STR_LIT>' ] , "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> metadata = Mock ( ) <EOL> metadata . bundles = set ( [ "<STR_LIT:error>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> metadata . version_info = Bcfg2VersionInfo ( '<STR_LIT>' ) <EOL> rv = b . BuildStructures ( metadata ) <EOL> self . assertEqual ( len ( rv ) , <NUM_LIT:4> ) <EOL> for bundle in rv : <EOL> name = bundle . get ( "<STR_LIT:name>" ) <EOL> self . assertIsNotNone ( name , <EOL> "<STR_LIT>" % name ) <EOL> self . assertIn ( name , expected , <EOL> "<STR_LIT>" % name ) <EOL> self . assertXMLEqual ( bundle , expected [ name ] , <EOL> "<STR_LIT>" % name ) <EOL> b . bundles [ name ] . XMLMatch . assert_called_with ( metadata ) <EOL> b . bundles [ '<STR_LIT:error>' ] . XMLMatch . assert_called_with ( metadata ) <EOL> self . assertFalse ( b . bundles [ '<STR_LIT>' ] . XMLMatch . called ) <EOL> def test_BuildStructuresOldClient ( self ) : <EOL> b = self . get_obj ( ) <EOL> b . bundles = dict ( has_dep = Mock ( ) ) <EOL> expected = dict ( ) <EOL> has_dep = lxml . etree . Element ( "<STR_LIT>" ) <EOL> lxml . etree . SubElement ( has_dep , "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> lxml . etree . SubElement ( has_dep , "<STR_LIT>" , name = "<STR_LIT>" , <EOL> inherit_modification = "<STR_LIT:true>" ) <EOL> lxml . etree . SubElement ( has_dep , "<STR_LIT>" , name = "<STR_LIT:foo>" ) <EOL> b . bundles [ '<STR_LIT>' ] . XMLMatch . return_value = has_dep <EOL> expected [ '<STR_LIT>' ] = lxml . etree . Element ( "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> lxml . etree . SubElement ( expected [ '<STR_LIT>' ] , "<STR_LIT>" , name = "<STR_LIT:foo>" ) <EOL> metadata = Mock ( ) <EOL> metadata . bundles = set ( [ "<STR_LIT>" ] ) <EOL> metadata . version_info = Bcfg2VersionInfo ( '<STR_LIT>' ) <EOL> rv = b . BuildStructures ( metadata ) <EOL> self . assertEqual ( len ( rv ) , len ( metadata . bundles ) ) <EOL> for bundle in rv : <EOL> name = bundle . get ( "<STR_LIT:name>" ) <EOL> self . assertIsNotNone ( name , <EOL> "<STR_LIT>" % name ) <EOL> self . assertIn ( name , expected , <EOL> "<STR_LIT>" % name ) <EOL> self . assertXMLEqual ( bundle , expected [ name ] , <EOL> "<STR_LIT>" % name ) <EOL> b . bundles [ name ] . XMLMatch . assert_called_with ( metadata ) </s>
