Example #1
0
 def setUp(self):
     SeecrTestCase.setUp(self)
     self.mock_createUpload_exception = ''
     self._testpath = os.path.realpath(os.path.curdir)
     self.output = StringIO()
     self.mappingData = dict(identifier="mappingId", code=DEFAULT_DC_CODE)
     self.mapping = Mapping('mappingId')
     self.mapping.code = DEFAULT_DC_CODE
     self.harvest = OnlineHarvest(self.output)
Example #2
0
    def testMappingRaisesException(self):
        mapping = CallTrace()
        self.harvest = OnlineHarvest(self.output)

        mapping.exceptions['createUpload'] = Exception('Mushroom, mushroom')
        data = 'file://%s/mocktud/00002.xml' % self._testpath
        try:
            self.harvest.performMapping(None, data, mappingObject=mapping)
            self.fail()
        except Exception as ex:
            self.assertEqual('Mushroom, mushroom', str(ex))
        self.assertEqual('\n',self.output.getvalue())
Example #3
0
 def testMapping(self):
     upload = CallTrace('upload')
     upload.id = 'id'
     upload.isDeleted = True
     mapping = CallTrace()
     mapping.returnValues['createUpload'] = upload
     self.harvest = OnlineHarvest(self.output)
     data = 'file://%s/mocktud/00002.xml' % self._testpath
     self.harvest.performMapping(None, data, mapping)
     self.assertEqual(['addObserver', 'mappingInfo', 'createUpload', 'createUpload', 'createUpload'], [m.name for m in mapping.calledMethods])
     for createUploadMethod in mapping.calledMethods[2:]:
         self.assertTrue(createUploadMethod.kwargs['doAsserts'])
Example #4
0
    def testMappingRaisesDataMapAssertionException(self):
        mapping = CallTrace()
        self.harvest = OnlineHarvest(self.output)

        calls = []
        def createUpload(*args, **kwargs):
            calls.append(1)
            if len(calls) == 1:
                raise DataMapAssertionException('O no, it\'s a snake!!')
            upload = CallTrace('upload')
            upload.id = 'id'
            upload.isDeleted = True
            return upload
        mapping.methods['createUpload'] = createUpload
        data = 'file://%s/mocktud/00002.xml' % self._testpath
        self.harvest.performMapping(None, data, mappingObject=mapping)
        self.assertEqual(2, self.output.getvalue().count('upload.id='))
 def setUp(self):
     SeecrTestCase.setUp(self)
     self.mock_createUpload_exception = ''
     self._testpath = os.path.realpath(os.path.curdir)
     self.output = StringIO()
     self.mappingData = dict(identifier="mappingId", code=DEFAULT_DC_CODE)
     self.mapping = Mapping('mappingId')
     self.mapping.code = DEFAULT_DC_CODE
     self.harvest = OnlineHarvest(self.output)
    def testMappingRaisesException(self):
        mapping = CallTrace()
        self.harvest = OnlineHarvest(self.output)

        mapping.exceptions['createUpload'] = Exception('Mushroom, mushroom')
        data = 'file://%s/mocktud/00002.xml' % self._testpath
        try:
            self.harvest.performMapping(None, data, mappingObject=mapping)
            self.fail()
        except Exception, ex:
            self.assertEquals('Mushroom, mushroom', str(ex))
 def testMapping(self):
     upload = CallTrace('upload')
     upload.id = 'id'
     upload.isDeleted = True
     mapping = CallTrace()
     mapping.returnValues['createUpload'] = upload
     self.harvest = OnlineHarvest(self.output)
     data = 'file://%s/mocktud/00002.xml' % self._testpath
     self.harvest.performMapping(None, data, mapping)
     self.assertEquals(['addObserver', 'mappingInfo', 'createUpload', 'createUpload', 'createUpload'], [m.name for m in mapping.calledMethods])
     for createUploadMethod in mapping.calledMethods[2:]:
         self.assertTrue(createUploadMethod.kwargs['doAsserts'])
    def testMappingRaisesDataMapAssertionException(self):
        mapping = CallTrace()
        self.harvest = OnlineHarvest(self.output)

        calls = []
        def createUpload(*args, **kwargs):
            calls.append(1)
            if len(calls) == 1:
                raise DataMapAssertionException('O no, it\'s a snake!!')
            upload = CallTrace('upload')
            upload.id = 'id'
            upload.isDeleted = True
            return upload
        mapping.methods['createUpload'] = createUpload
        data = 'file://%s/mocktud/00002.xml' % self._testpath
        self.harvest.performMapping(None, data, mappingObject=mapping)
        self.assertEquals(2, self.output.getvalue().count('upload.id='))
Example #9
0
class OnlineHarvestTest(SeecrTestCase):
    def setUp(self):
        SeecrTestCase.setUp(self)
        self.mock_createUpload_exception = ''
        self._testpath = os.path.realpath(os.path.curdir)
        self.output = StringIO()
        self.mappingData = dict(identifier="mappingId", code=DEFAULT_DC_CODE)
        self.mapping = Mapping('mappingId')
        self.mapping.code = DEFAULT_DC_CODE
        self.harvest = OnlineHarvest(self.output)

    def testRealMapping(self):
        data = 'file://%s/mocktud/00002.xml' % self._testpath
        self.harvest.performMapping(self.mappingData, data)
        self.assertEqual(3,self.output.getvalue().count('upload.id='))

    def testMapping(self):
        upload = CallTrace('upload')
        upload.id = 'id'
        upload.isDeleted = True
        mapping = CallTrace()
        mapping.returnValues['createUpload'] = upload
        self.harvest = OnlineHarvest(self.output)
        data = 'file://%s/mocktud/00002.xml' % self._testpath
        self.harvest.performMapping(None, data, mapping)
        self.assertEqual(['addObserver', 'mappingInfo', 'createUpload', 'createUpload', 'createUpload'], [m.name for m in mapping.calledMethods])
        for createUploadMethod in mapping.calledMethods[2:]:
            self.assertTrue(createUploadMethod.kwargs['doAsserts'])

    def testMappingWithDeletedRecord(self):
        data = 'file://%s/mocktud/00003.xml' % self._testpath
        self.harvest.performMapping(dict(identifier='mappingId', code=DEFAULT_DC_CODE, name="My Mapping"), data)
        self.assertEqual("Mappingname 'My Mapping'\n\nupload.id=repository.id:oai:tudelft.nl:107087\nDELETED", self.output.getvalue().strip())

    def testMappingRaisesDataMapAssertionException(self):
        mapping = CallTrace()
        self.harvest = OnlineHarvest(self.output)

        calls = []
        def createUpload(*args, **kwargs):
            calls.append(1)
            if len(calls) == 1:
                raise DataMapAssertionException('O no, it\'s a snake!!')
            upload = CallTrace('upload')
            upload.id = 'id'
            upload.isDeleted = True
            return upload
        mapping.methods['createUpload'] = createUpload
        data = 'file://%s/mocktud/00002.xml' % self._testpath
        self.harvest.performMapping(None, data, mappingObject=mapping)
        self.assertEqual(2, self.output.getvalue().count('upload.id='))

    def testMappingRaisesException(self):
        mapping = CallTrace()
        self.harvest = OnlineHarvest(self.output)

        mapping.exceptions['createUpload'] = Exception('Mushroom, mushroom')
        data = 'file://%s/mocktud/00002.xml' % self._testpath
        try:
            self.harvest.performMapping(None, data, mappingObject=mapping)
            self.fail()
        except Exception as ex:
            self.assertEqual('Mushroom, mushroom', str(ex))
        self.assertEqual('\n',self.output.getvalue())
class OnlineHarvestTest(SeecrTestCase):
    def setUp(self):
        SeecrTestCase.setUp(self)
        self.mock_createUpload_exception = ''
        self._testpath = os.path.realpath(os.path.curdir)
        self.output = StringIO()
        self.mappingData = dict(identifier="mappingId", code=DEFAULT_DC_CODE)
        self.mapping = Mapping('mappingId')
        self.mapping.code = DEFAULT_DC_CODE
        self.harvest = OnlineHarvest(self.output)

    def testRealMapping(self):
        data = 'file://%s/mocktud/00002.xml' % self._testpath
        self.harvest.performMapping(self.mappingData, data)
        self.assertEquals(3,self.output.getvalue().count('upload.id='))

    def testMapping(self):
        upload = CallTrace('upload')
        upload.id = 'id'
        upload.isDeleted = True
        mapping = CallTrace()
        mapping.returnValues['createUpload'] = upload
        self.harvest = OnlineHarvest(self.output)
        data = 'file://%s/mocktud/00002.xml' % self._testpath
        self.harvest.performMapping(None, data, mapping)
        self.assertEquals(['addObserver', 'mappingInfo', 'createUpload', 'createUpload', 'createUpload'], [m.name for m in mapping.calledMethods])
        for createUploadMethod in mapping.calledMethods[2:]:
            self.assertTrue(createUploadMethod.kwargs['doAsserts'])

    def testMappingWithDeletedRecord(self):
        data = 'file://%s/mocktud/00003.xml' % self._testpath
        self.harvest.performMapping(dict(identifier='mappingId', code=DEFAULT_DC_CODE, name="My Mapping"), data)
        self.assertEquals("Mappingname 'My Mapping'\n\nupload.id=repository.id:oai:tudelft.nl:107087\nDELETED", self.output.getvalue().strip())

    def testMappingRaisesDataMapAssertionException(self):
        mapping = CallTrace()
        self.harvest = OnlineHarvest(self.output)

        calls = []
        def createUpload(*args, **kwargs):
            calls.append(1)
            if len(calls) == 1:
                raise DataMapAssertionException('O no, it\'s a snake!!')
            upload = CallTrace('upload')
            upload.id = 'id'
            upload.isDeleted = True
            return upload
        mapping.methods['createUpload'] = createUpload
        data = 'file://%s/mocktud/00002.xml' % self._testpath
        self.harvest.performMapping(None, data, mappingObject=mapping)
        self.assertEquals(2, self.output.getvalue().count('upload.id='))

    def testMappingRaisesException(self):
        mapping = CallTrace()
        self.harvest = OnlineHarvest(self.output)

        mapping.exceptions['createUpload'] = Exception('Mushroom, mushroom')
        data = 'file://%s/mocktud/00002.xml' % self._testpath
        try:
            self.harvest.performMapping(None, data, mappingObject=mapping)
            self.fail()
        except Exception, ex:
            self.assertEquals('Mushroom, mushroom', str(ex))
        self.assertEquals('\n',self.output.getvalue())