File: magicmetatest.py

package info (click to toggle)
gavodachs 2.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 8,972 kB
  • sloc: python: 100,078; xml: 3,014; javascript: 2,360; ansic: 918; sh: 216; makefile: 31
file content (141 lines) | stat: -rw-r--r-- 4,972 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
"""
Tests for special behaviour of meta values defined in base.typedmeta.
"""

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("<meta>creator.name: Thor, A.U.\n"
			"creator:\ncreator.name: Bohr, N.\ntitle:On GAVO's role"
			" in Writing DaCHS &amp; \\\\expandafter\ncreationDate: 1984-08-05\n"
			"referenceURL:http://purl.org/pub/thor+bohr\n"
			"shortName:testres\n"
			"doi:10.542/testing</meta>")
		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("<meta>creator.name: Thor, A.U.</meta>")
		self.assertRaisesWithMsg(base.MetaError,
			"On <test meta carrier>: No meta item creationDate",
			metarender.makeBibTeXForMetaCarrier,
			(mc,))
	
	def testIdFallback1(self):
		mc = parseMetaXML("<meta>creator.name: Thor, A.U.\n"
			"creationDate: 1984-08-05T13:45:23\ntitle: Ulysses\n"
			"referenceURL:http://purl.org/pub/thor\n</meta>")
		self.assertTrue(metarender.makeBibTeXForMetaCarrier(mc
			).startswith("@MISC{vo:eiabtliumabb,"))

	def testTableNameMangling(self):
		mc = parseMetaXML("<meta>creator.name: Thor, A.U.\n"
			"creationDate: 1984-08-05T13:45:23\ntitle: ToC\n"
			"referenceURL:http://purl.org/pub/thor\n</meta>")
		mc.getQName = lambda: "mySchema.someTable"
		self.assertTrue(metarender.makeBibTeXForMetaCarrier(mc
			).startswith("@MISC{vo:mySchema_someTable,"))

	def testNoAuthor(self):
		mc = parseMetaXML("<meta>creationDate: 1984-08-05T13:45:23\n"
			"title: Der hessische Landbote\n"
			"referenceURL:http://purl.org/pub/thor\n</meta>")
		# 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(
				'<meta name="copyright">Free to use</meta>',
				"rights"),
			'<span class="plainmeta">Free to use</span>')

	def testCombiningSynonyms(self):
		self.assertEqual(
			getMetaHTMLFor(
				'<meta name="_copyright">Do not dare touch this</meta>'
				'<meta name="copyright">Free to use</meta>'
				'<meta name="rights" format="rst">http://xkcd.com/2228/</meta>',
				"rights"),
			'<ul class="metaEnum"><li class="metaItem"><span class="plainmeta">'
			'Do not dare touch this</span></li>'
			'<li class="metaItem"><span class="plainmeta">Free to use</span></li>'
			'<li class="metaItem"><p><a class="reference external"'
			' href="http://xkcd.com/2228/">http://xkcd.com/2228/</a></p>'
			'\n</li></ul>')

	def testRenamingHappens(self):
		self.assertRaisesWithMsg(
			base.NoMetaKey,
			"On <test meta carrier>: No meta item copyright",
			getMetaHTMLFor,
			('<meta name="_copyright">Do not dare touch this</meta>', "copyright"))


class LinkTest(testhelpers.VerboseTest):
	def testLink(self):
		"""tests for working recognition of link-typed metas.
		"""
		mc = parseMetaXML('<meta name="_related" title="a link">'
			'http://foo.bar</meta>')
		self.assertEqual(mc.getMeta("_related").getContent("html"),
			'<a href="http://foo.bar">a link</a>')


class NoteTest(testhelpers.VerboseTest):
	def testCustomMetaIndentation(self):
		mc = parseMetaXML('\t\t<meta name="note" tag="6">\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</meta>')
		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(
			'<meta name="isServedBy" ivoId="ivo://dc.g-vo.org/tap">'
			'GAVO TAP Service</meta>')
		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)