""" Tests for special behaviour of meta values defined in base.typedmeta. """ #c Copyright 2008-2025, the GAVO project #c #c This program is free software, covered by the GNU GPL. See the #c COPYING file in the source distribution. from gavo.helpers import testhelpers from gavo import base from gavo.base import meta from gavo.base import typedmeta from gavo.web import metarender from metatest import parseMetaXML, getMetaHTMLFor class BibTeXTest(testhelpers.VerboseTest): def testBasic(self): mc = parseMetaXML("creator.name: Thor, A.U.\n" "creator:\ncreator.name: Bohr, N.\ntitle:On GAVO's role" " in Writing DaCHS & \\\\expandafter\ncreationDate: 1984-08-05\n" "referenceURL:http://purl.org/pub/thor+bohr\n" "shortName:testres\n" "doi:10.542/testing") self.assertEqual(metarender.makeBibTeXForMetaCarrier(mc), r"""@MISC{vo:testres, year=1984, title={On {GAVO}'s role in Writing {DaCHS} \& \\expandafter}, author={Thor, A.U. and Bohr, N.}, url={http://purl.org/pub/thor+bohr}, howpublished={{VO} resource provided by the Unittest Suite}, doi = {10.542/testing} } """) def testIncompleteMetaErrors(self): mc = parseMetaXML("creator.name: Thor, A.U.") self.assertRaisesWithMsg(base.MetaError, "On : No meta item creationDate", metarender.makeBibTeXForMetaCarrier, (mc,)) def testIdFallback1(self): mc = parseMetaXML("creator.name: Thor, A.U.\n" "creationDate: 1984-08-05T13:45:23\ntitle: Ulysses\n" "referenceURL:http://purl.org/pub/thor\n") self.assertTrue(metarender.makeBibTeXForMetaCarrier(mc ).startswith("@MISC{vo:eiabtliumabb,")) def testTableNameMangling(self): mc = parseMetaXML("creator.name: Thor, A.U.\n" "creationDate: 1984-08-05T13:45:23\ntitle: ToC\n" "referenceURL:http://purl.org/pub/thor\n") mc.getQName = lambda: "mySchema.someTable" self.assertTrue(metarender.makeBibTeXForMetaCarrier(mc ).startswith("@MISC{vo:mySchema_someTable,")) def testNoAuthor(self): mc = parseMetaXML("creationDate: 1984-08-05T13:45:23\n" "title: Der hessische Landbote\n" "referenceURL:http://purl.org/pub/thor\n") # The fallback to the DC creator is probably a bad idea here. # Well, any other behaviour is going to be still more painful. self.assertTrue( "author={Could be same as contact.name}," in metarender.makeBibTeXForMetaCarrier(mc)) class RightsTest(testhelpers.VerboseTest): def testCopyrightMaps(self): self.assertEqual( getMetaHTMLFor( 'Free to use', "rights"), 'Free to use') def testCombiningSynonyms(self): self.assertEqual( getMetaHTMLFor( 'Do not dare touch this' 'Free to use' 'http://xkcd.com/2228/', "rights"), '') def testRenamingHappens(self): self.assertRaisesWithMsg( base.NoMetaKey, "On : No meta item copyright", getMetaHTMLFor, ('Do not dare touch this', "copyright")) class LinkTest(testhelpers.VerboseTest): def testLink(self): """tests for working recognition of link-typed metas. """ mc = parseMetaXML('' 'http://foo.bar') self.assertEqual(mc.getMeta("_related").getContent("html"), 'a link') class NoteTest(testhelpers.VerboseTest): def testCustomMetaIndentation(self): mc = parseMetaXML('\t\t\n' '\t\t\tA zero for the number of used images indicates that all images\n' '\t\t\thave some "problem" (such as overexposure).\n' '\t\t') self.assertEqual(mc.getMeta("note").children[0].content, '\nA zero for the number of used images indicates that all images\n' 'have some "problem" (such as overexposure).') class RelationshipTest(testhelpers.VerboseTest): def testRDAttribute(self): mc = parseMetaXML( '' 'GAVO TAP Service') self.assertEqual( str(mc.getMeta("isServedBy.ivoId")), "ivo://dc.g-vo.org/tap") self.assertEqual( str(mc.getMeta("isServedBy")), 'GAVO TAP Service') def testRelationshipNames(self): self.assertEqual( list(meta.getKeysForClass(typedmeta.RelatedResourceMeta)), [ 'servedBy', 'serviceFor', 'relatedTo', 'mirrorOf', 'derivedFrom', 'uses', 'cites', 'isSupplementTo', 'isSupplementedBy', 'isContinuedBy', 'continues', 'isNewVersionOf', 'isPreviousVersionOf', 'isPartOf', 'hasPart', 'isSourceOf', 'isDerivedFrom', 'isIdenticalTo', 'isServiceFor', 'isServedBy']) if __name__=="__main__": testhelpers.main(RelationshipTest)