| 1 |
""" |
| 2 |
Tests for special behaviour of meta values defined in base.typedmeta. |
| 3 |
""" |
| 4 |
|
| 5 |
#c Copyright 2008-2025, the GAVO project <[email protected]> |
| 6 |
#c |
| 7 |
#c This program is free software, covered by the GNU GPL. See the |
| 8 |
#c COPYING file in the source distribution. |
| 9 |
|
| 10 |
|
| 11 |
from gavo.helpers import testhelpers |
| 12 |
|
| 13 |
from gavo import base |
| 14 |
from gavo.base import meta |
| 15 |
from gavo.base import typedmeta |
| 16 |
from gavo.web import metarender |
| 17 |
|
| 18 |
from metatest import parseMetaXML, getMetaHTMLFor |
| 19 |
|
| 20 |
|
| 21 |
class BibTeXTest(testhelpers.VerboseTest): |
| 22 |
def testBasic(self): |
| 23 |
mc = parseMetaXML("<meta>creator.name: Thor, A.U.\n" |
| 24 |
"creator:\ncreator.name: Bohr, N.\ntitle:On GAVO's role" |
| 25 |
" in Writing DaCHS & \\\\expandafter\ncreationDate: 1984-08-05\n" |
| 26 |
"referenceURL:http://purl.org/pub/thor+bohr\n" |
| 27 |
"shortName:testres\n" |
| 28 |
"doi:10.542/testing</meta>") |
| 29 |
self.assertEqual(metarender.makeBibTeXForMetaCarrier(mc), |
| 30 |
r"""@MISC{vo:testres, |
| 31 |
year=1984, |
| 32 |
title={On {GAVO}'s role in Writing {DaCHS} \& \\expandafter}, |
| 33 |
author={Thor, A.U. and Bohr, N.}, |
| 34 |
url={http://purl.org/pub/thor+bohr}, |
| 35 |
howpublished={{VO} resource provided by the Unittest Suite}, |
| 36 |
doi = {10.542/testing} |
| 37 |
} |
| 38 |
""") |
| 39 |
|
| 40 |
def testIncompleteMetaErrors(self): |
| 41 |
mc = parseMetaXML("<meta>creator.name: Thor, A.U.</meta>") |
| 42 |
self.assertRaisesWithMsg(base.MetaError, |
| 43 |
"On <test meta carrier>: No meta item creationDate", |
| 44 |
metarender.makeBibTeXForMetaCarrier, |
| 45 |
(mc,)) |
| 46 |
|
| 47 |
def testIdFallback1(self): |
| 48 |
mc = parseMetaXML("<meta>creator.name: Thor, A.U.\n" |
| 49 |
"creationDate: 1984-08-05T13:45:23\ntitle: Ulysses\n" |
| 50 |
"referenceURL:http://purl.org/pub/thor\n</meta>") |
| 51 |
self.assertTrue(metarender.makeBibTeXForMetaCarrier(mc |
| 52 |
).startswith("@MISC{vo:eiabtliumabb,")) |
| 53 |
|
| 54 |
def testTableNameMangling(self): |
| 55 |
mc = parseMetaXML("<meta>creator.name: Thor, A.U.\n" |
| 56 |
"creationDate: 1984-08-05T13:45:23\ntitle: ToC\n" |
| 57 |
"referenceURL:http://purl.org/pub/thor\n</meta>") |
| 58 |
mc.getQName = lambda: "mySchema.someTable" |
| 59 |
self.assertTrue(metarender.makeBibTeXForMetaCarrier(mc |
| 60 |
).startswith("@MISC{vo:mySchema_someTable,")) |
| 61 |
|
| 62 |
def testNoAuthor(self): |
| 63 |
mc = parseMetaXML("<meta>creationDate: 1984-08-05T13:45:23\n" |
| 64 |
"title: Der hessische Landbote\n" |
| 65 |
"referenceURL:http://purl.org/pub/thor\n</meta>") |
| 66 |
# The fallback to the DC creator is probably a bad idea here. |
| 67 |
# Well, any other behaviour is going to be still more painful. |
| 68 |
self.assertTrue( |
| 69 |
"author={Could be same as contact.name}," |
| 70 |
in metarender.makeBibTeXForMetaCarrier(mc)) |
| 71 |
|
| 72 |
|
| 73 |
class RightsTest(testhelpers.VerboseTest): |
| 74 |
def testCopyrightMaps(self): |
| 75 |
self.assertEqual( |
| 76 |
getMetaHTMLFor( |
| 77 |
'<meta name="copyright">Free to use</meta>', |
| 78 |
"rights"), |
| 79 |
'<span class="plainmeta">Free to use</span>') |
| 80 |
|
| 81 |
def testCombiningSynonyms(self): |
| 82 |
self.assertEqual( |
| 83 |
getMetaHTMLFor( |
| 84 |
'<meta name="_copyright">Do not dare touch this</meta>' |
| 85 |
'<meta name="copyright">Free to use</meta>' |
| 86 |
'<meta name="rights" format="rst">http://xkcd.com/2228/</meta>', |
| 87 |
"rights"), |
| 88 |
'<ul class="metaEnum"><li class="metaItem"><span class="plainmeta">' |
| 89 |
'Do not dare touch this</span></li>' |
| 90 |
'<li class="metaItem"><span class="plainmeta">Free to use</span></li>' |
| 91 |
'<li class="metaItem"><p><a class="reference external"' |
| 92 |
' href="http://xkcd.com/2228/">http://xkcd.com/2228/</a></p>' |
| 93 |
'\n</li></ul>') |
| 94 |
|
| 95 |
def testRenamingHappens(self): |
| 96 |
self.assertRaisesWithMsg( |
| 97 |
base.NoMetaKey, |
| 98 |
"On <test meta carrier>: No meta item copyright", |
| 99 |
getMetaHTMLFor, |
| 100 |
('<meta name="_copyright">Do not dare touch this</meta>', "copyright")) |
| 101 |
|
| 102 |
|
| 103 |
class LinkTest(testhelpers.VerboseTest): |
| 104 |
def testLink(self): |
| 105 |
"""tests for working recognition of link-typed metas. |
| 106 |
""" |
| 107 |
mc = parseMetaXML('<meta name="_related" title="a link">' |
| 108 |
'http://foo.bar</meta>') |
| 109 |
self.assertEqual(mc.getMeta("_related").getContent("html"), |
| 110 |
'<a href="http://foo.bar">a link</a>') |
| 111 |
|
| 112 |
|
| 113 |
class NoteTest(testhelpers.VerboseTest): |
| 114 |
def testCustomMetaIndentation(self): |
| 115 |
mc = parseMetaXML('\t\t<meta name="note" tag="6">\n' |
| 116 |
'\t\t\tA zero for the number of used images indicates that all images\n' |
| 117 |
'\t\t\thave some "problem" (such as overexposure).\n' |
| 118 |
'\t\t</meta>') |
| 119 |
self.assertEqual(mc.getMeta("note").children[0].content, |
| 120 |
'\nA zero for the number of used images indicates that all images\n' |
| 121 |
'have some "problem" (such as overexposure).') |
| 122 |
|
| 123 |
|
| 124 |
class RelationshipTest(testhelpers.VerboseTest): |
| 125 |
def testRDAttribute(self): |
| 126 |
mc = parseMetaXML( |
| 127 |
'<meta name="isServedBy" ivoId="ivo://dc.g-vo.org/tap">' |
| 128 |
'GAVO TAP Service</meta>') |
| 129 |
self.assertEqual( |
| 130 |
str(mc.getMeta("isServedBy.ivoId")), |
| 131 |
"ivo://dc.g-vo.org/tap") |
| 132 |
self.assertEqual( |
| 133 |
str(mc.getMeta("isServedBy")), |
| 134 |
'GAVO TAP Service') |
| 135 |
|
| 136 |
def testRelationshipNames(self): |
| 137 |
self.assertEqual( |
| 138 |
list(meta.getKeysForClass(typedmeta.RelatedResourceMeta)), [ |
| 139 |
'servedBy', 'serviceFor', 'relatedTo', 'mirrorOf', 'derivedFrom', |
| 140 |
'uses', 'cites', 'isSupplementTo', 'isSupplementedBy', 'isContinuedBy', |
| 141 |
'continues', 'isNewVersionOf', 'isPreviousVersionOf', 'isPartOf', |
| 142 |
'hasPart', 'isSourceOf', 'isDerivedFrom', 'isIdenticalTo', |
| 143 |
'isServiceFor', 'isServedBy']) |
| 144 |
|
| 145 |
|
| 146 |
if __name__=="__main__": |
| 147 |
testhelpers.main(RelationshipTest) |