def setUp(self):
     SeecrTestCase.setUp(self)
     self.combine = CombineParts({'together': ['one', 'two']})
     self.observer = CallTrace('observer')
     self.combine.addObserver(self.observer)
     self.observer.methods[
         'getData'] = lambda identifier, name: '<%s/>' % name
    def testTogetherWithGivenMissingPartsAllowed(self):
        self.combine = CombineParts({'together': ['one', 'two']},
                                    allowMissingParts=['two'])
        self.combine.addObserver(self.observer)

        def getData(identifier, name):
            if name == 'one':
                raise KeyError('one')
            return '<%s/>' % name

        self.observer.methods['getData'] = getData
        self.assertRaises(
            KeyError, lambda: self.combine.getData(identifier='identifier',
                                                   name='together'))
    def testTogetherWithOnePartMissingAllowed(self):
        self.combine = CombineParts({'together': ['one', 'two']},
                                    allowMissingParts=['two'])
        self.combine.addObserver(self.observer)

        def getData(identifier, name):
            if name == 'two':
                raise KeyError('two')
            return '<%s/>' % name

        self.observer.methods['getData'] = getData
        result = self.combine.getData(identifier='identifier', name='together')
        self.assertEquals(
            '<doc:document xmlns:doc="http://meresco.org/namespace/harvester/document"><doc:part name="one"><one/></doc:part></doc:document>',
            result)