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)
Пример #4
0
 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'))
Пример #5
0
 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)
class CombinePartsTest(SeecrTestCase):
    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 testPassThroughOtherStuff(self):
        result = self.combine.getData(identifier='identifier', name='name')
        self.assertEquals('<name/>', result)
        self.assertEquals(['getData'], self.observer.calledMethodNames())
        self.assertEquals([dict(identifier='identifier', name='name')],
                          [m.kwargs for m in self.observer.calledMethods])

    def testTogether(self):
        result = self.combine.getData(identifier='identifier', name='together')
        expected = '<doc:document xmlns:doc="http://meresco.org/namespace/harvester/document"><doc:part name="one"><one/></doc:part><doc:part name="two"><two/></doc:part></doc:document>'
        self.assertEquals(expected, result)

        self.assertEquals(['getData', 'getData'],
                          self.observer.calledMethodNames())
        self.assertEquals([
            dict(identifier='identifier', name='one'),
            dict(identifier='identifier', name='two')
        ], [m.kwargs for m in self.observer.calledMethods])

    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)

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

        self.observer.methods['getData'] = getData
        self.assertRaises(
            KeyError, lambda: self.combine.getData(identifier='identifier',
                                                   name='together'))

    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'))
Пример #7
0
 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
Пример #8
0
class CombinePartsTest(SeecrTestCase):
    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 testPassThroughOtherStuff(self):
        result = self.combine.getData(identifier='identifier', name='name')
        self.assertEquals('<name/>', result)
        self.assertEquals(['getData'], self.observer.calledMethodNames())
        self.assertEquals([dict(identifier='identifier', name='name')], [m.kwargs for m in self.observer.calledMethods])

    def testTogether(self):
        result = self.combine.getData(identifier='identifier', name='together')
        expected = '<doc:document xmlns:doc="http://meresco.org/namespace/harvester/document"><doc:part name="one"><one/></doc:part><doc:part name="two"><two/></doc:part></doc:document>'
        self.assertEquals(expected, result)

        self.assertEquals(['getData', 'getData'], self.observer.calledMethodNames())
        self.assertEquals([dict(identifier='identifier', name='one'), dict(identifier='identifier', name='two')], [m.kwargs for m in self.observer.calledMethods])

    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)

    def testTogetherWithOnePartMissingNotAllowed(self):
        def getData(identifier, name):
            if name == 'two':
                raise KeyError('two')
            return '<%s/>' % name
        self.observer.methods['getData'] = getData
        self.assertRaises(KeyError, lambda: self.combine.getData(identifier='identifier', name='together'))

    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'))