def testGetUniqueWithSetsMask(self): self.observer.returnValues['getRecord'] = MockRecord( 'id', sets=['set1', 'set2', 'set3']) self.dna.call.getRecord('xyz', setsMask=['set3']) self.assertEqual(['getRecord'], self.observer.calledMethodNames()) getRecordCall = self.observer.calledMethods[0] self.assertEqual(('xyz', ), getRecordCall.args) self.observer.calledMethods.reset() self.observer.returnValues['getRecord'] = MockRecord( 'id', sets=['set1', 'set2']) self.dna.call.getRecord('xyz', setsMask=['set3']) self.assertEqual(['getRecord'], self.observer.calledMethodNames())
def testRecordWithRetrieveData(self): def getData(*_, **__): raise DeclineMessage() def retrieveData(*_, **__): return '<retrieved/>' yield self.observer.methods['retrieveData'] = retrieveData self.observer.methods['getData'] = getData self.observer.returnValues.pop('getData') result = ''.join( compose( self.oaiRecord.oaiRecord(record=MockRecord('id'), metadataPrefix='oai_dc', fetchedRecords=None))) self.assertEqualsWS( """<record> <header> <identifier>id</identifier> <datestamp>2011-03-25T10:45:00Z</datestamp> <setSpec>set0</setSpec> <setSpec>set1</setSpec> </header> <metadata> <retrieved/> </metadata> </record>""", result) self.assertEqual([ "getData(identifier='id', name='oai_dc')", "retrieveData(identifier='id', name='oai_dc')", "provenance('id')" ], [str(m) for m in self.observer.calledMethods])
def testRecordWithFetchedRecordsWithRepositoryIdentifier(self): self.setUpOaiRecord(repository=OaiRepository(identifier='example.org')) record = MockRecord('id') result = ''.join( compose( self.oaiRecord.oaiRecord(record=record, metadataPrefix='oai_dc', fetchedRecords={ record.identifier: "<the>data</the>", 'abc': '<some>other data</some>' }))) self.assertEqualsWS( """<record> <header> <identifier>oai:example.org:id</identifier> <datestamp>2011-03-25T10:45:00Z</datestamp> <setSpec>set0</setSpec> <setSpec>set1</setSpec> </header> <metadata> <the>data</the> </metadata> </record>""", result) self.assertEqual(["provenance('id')"], [str(m) for m in self.observer.calledMethods])
def testRecordForListIdentifiers(self): result = ''.join( compose( self.oaiRecord.oaiRecordHeader(record=MockRecord('id'), metadataPrefix='oai_dc', kwarg0="ignored"))) self.assertEqualsWS( """<header> <identifier>id</identifier> <datestamp>2011-03-25T10:45:00Z</datestamp> <setSpec>set0</setSpec> <setSpec>set1</setSpec> </header>""", result) self.assertEqual([], [str(m) for m in self.observer.calledMethods])
def testRecordIsDeleted(self): result = ''.join( compose( self.oaiRecord.oaiRecord(record=MockRecord('id', deleted=True), metadataPrefix='oai_dc'))) self.assertEqualsWS( """<record> <header status="deleted"> <identifier>id</identifier> <datestamp>2011-03-25T10:45:00Z</datestamp> <setSpec>set0</setSpec> <setSpec>set1</setSpec> </header> </record>""", result) self.assertEqual([], [str(m) for m in self.observer.calledMethods])
def testRecordWithDeleteInSetsSupport(self): self.setUpOaiRecord(deleteInSets=True) result = ''.join( compose( self.oaiRecord.oaiRecord(record=MockRecord( 'id', sets={'set0', 'set1'}, deletedSets={'set1'}), metadataPrefix='oai_dc'))) self.assertEqualsWS( """<record> <header> <identifier>id</identifier> <datestamp>2011-03-25T10:45:00Z</datestamp> <setSpec>set0</setSpec> <setSpec status="deleted">set1</setSpec> </header> <metadata><data/></metadata> </record>""", result)
def testDeletedRecordWithProvenance(self): self.observer.returnValues['provenance'] = ( f for f in ['PROV', 'ENANCE']) result = ''.join( compose( self.oaiRecord.oaiRecord(record=MockRecord('id&0', deleted=True), metadataPrefix='oai_dc'))) self.assertEqualsWS( """<record> <header status="deleted"> <identifier>id&0</identifier> <datestamp>2011-03-25T10:45:00Z</datestamp> <setSpec>set0</setSpec> <setSpec>set1</setSpec> </header> </record>""", result) self.assertEqual([], [str(m) for m in self.observer.calledMethods])
def testRecordsWithoutSets(self): result = ''.join( compose( self.oaiRecord.oaiRecord(record=MockRecord('id', sets=[]), metadataPrefix='oai_dc'))) self.assertEqualsWS( """<record> <header> <identifier>id</identifier> <datestamp>2011-03-25T10:45:00Z</datestamp> </header> <metadata> <data/> </metadata> </record>""", result) self.assertEqual( ["getData(identifier='id', name='oai_dc')", "provenance('id')"], [str(m) for m in self.observer.calledMethods])
def testRecordWithRepositoryIdentifier(self): self.setUpOaiRecord(repository=OaiRepository(identifier='example.org')) result = ''.join( compose( self.oaiRecord.oaiRecord(record=MockRecord('id'), metadataPrefix='oai_dc', fetchedRecords=None))) self.assertEqualsWS( """<record> <header> <identifier>oai:example.org:id</identifier> <datestamp>2011-03-25T10:45:00Z</datestamp> <setSpec>set0</setSpec> <setSpec>set1</setSpec> </header> <metadata> <data/> </metadata> </record>""", result) self.assertEqual( ["getData(identifier='id', name='oai_dc')", "provenance('id')"], [str(m) for m in self.observer.calledMethods])
def testRecordWithProvenance(self): self.observer.returnValues['provenance'] = ( f for f in ['PROV', 'ENANCE']) result = ''.join( compose( self.oaiRecord.oaiRecord(record=MockRecord('id'), metadataPrefix='oai_dc'))) self.assertEqualsWS( """<record> <header> <identifier>id</identifier> <datestamp>2011-03-25T10:45:00Z</datestamp> <setSpec>set0</setSpec> <setSpec>set1</setSpec> </header> <metadata> <data/> </metadata> <about>PROVENANCE</about> </record>""", result) self.assertEqual( ["getData(identifier='id', name='oai_dc')", "provenance('id')"], [str(m) for m in self.observer.calledMethods])
def testPreciseDatestamp(self): self.setUpOaiRecord(preciseDatestamp=True) record = MockRecord('id') result = ''.join( compose( self.oaiRecord.oaiRecord(record=record, metadataPrefix='oai_dc', fetchedRecords={ record.identifier: "<the>data</the>", 'abc': '<some>other data</some>' }))) self.assertEqualsWS( """<record> <header> <identifier>id</identifier> <datestamp>2011-03-25T10:45:00.123Z</datestamp> <setSpec>set0</setSpec> <setSpec>set1</setSpec> </header> <metadata> <the>data</the> </metadata> </record>""", result)
def testGetUniqueNotInSet(self): self.observer.returnValues['getRecord'] = MockRecord('id', sets=['set4']) self.dna.call.getRecord('xyz') self.assertEqual(['getRecord'], self.observer.calledMethodNames())