| 1 |
""" |
| 2 |
Tests having to do with the registry code. |
| 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 |
import datetime |
| 12 |
import re |
| 13 |
import os |
| 14 |
|
| 15 |
from gavo.helpers import testhelpers |
| 16 |
|
| 17 |
from gavo import api |
| 18 |
from gavo import base |
| 19 |
from gavo import registry |
| 20 |
from gavo import rscdesc |
| 21 |
from gavo import svcs |
| 22 |
from gavo import utils |
| 23 |
from gavo.base import meta |
| 24 |
from gavo.helpers import testtricks |
| 25 |
from gavo.registry import builders |
| 26 |
from gavo.registry import common |
| 27 |
from gavo.registry import capabilities |
| 28 |
from gavo.registry import nonservice |
| 29 |
from gavo.registry import oaiinter |
| 30 |
from gavo.registry import publication |
| 31 |
from gavo.registry import tableset |
| 32 |
from gavo.utils import ElementTree |
| 33 |
from gavo.registry.model import OAI |
| 34 |
from gavo.registry.model import VOR |
| 35 |
from gavo.registry.model import VS |
| 36 |
from gavo.web import vosi |
| 37 |
|
| 38 |
import tresc |
| 39 |
|
| 40 |
|
| 41 |
def getGetRecordResponse(resob): |
| 42 |
"""returns XML and parsedXML as returned from an OAI getRecord |
| 43 |
call that retrieves resob. |
| 44 |
""" |
| 45 |
pars = {"verb": "GetRecord", "metadataPrefix": "ivo_vor"} |
| 46 |
source = OAI.PMH[ |
| 47 |
oaiinter.getResponseHeaders(pars), |
| 48 |
builders.getVOGetRecordElement(resob)].render() |
| 49 |
return source, testhelpers.getXMLTree(source, debug=False) |
| 50 |
|
| 51 |
|
| 52 |
class RegistryModelTest(testhelpers.VerboseTest): |
| 53 |
def testVSNamespaces(self): |
| 54 |
from gavo.registry import model |
| 55 |
self.assertEqual(model.VS.ucd()._prefix, "vs") |
| 56 |
|
| 57 |
def testVOTableDataType(self): |
| 58 |
self.assertEqual( |
| 59 |
testhelpers.cleanXML(tableset.voTableDataTypeFactory("char").render()), |
| 60 |
'<dataType arraysize="1" xsi:type="vs:VOTableType">char</dataType>') |
| 61 |
self.assertEqual( |
| 62 |
testhelpers.cleanXML(tableset.voTableDataTypeFactory("integer").render()), |
| 63 |
'<dataType xsi:type="vs:VOTableType">int</dataType>') |
| 64 |
self.assertEqual( |
| 65 |
testhelpers.cleanXML(tableset.voTableDataTypeFactory("text").render()), |
| 66 |
'<dataType arraysize="*" xsi:type="vs:VOTableType">char</dataType>') |
| 67 |
self.assertEqual( |
| 68 |
testhelpers.cleanXML(tableset.voTableDataTypeFactory( |
| 69 |
"integer[20]").render()), |
| 70 |
'<dataType arraysize="20" xsi:type="vs:VOTableType">int</dataType>') |
| 71 |
|
| 72 |
def testUsefulRecordRepr(self): |
| 73 |
el = VOR.Organisation[VOR.identifier["ivo://example.org/myorg"]] |
| 74 |
self.assertEqual(repr(el), "<Organisation: ivo://example.org/myorg>") |
| 75 |
|
| 76 |
def testRecordReprDoesNotBreak(self): |
| 77 |
repr(VOR.Organisation[VOR.shortName["nonid"], |
| 78 |
VOR.title["a test org"], VOR.altIdentifier["test:testing"]]) |
| 79 |
|
| 80 |
def testDataTypeDeclaration(self): |
| 81 |
literal = VS.dataType(xsi_type="vs:SimpleDataType")["char"].render() |
| 82 |
tree = testhelpers.getXMLTree(literal, debug=False) |
| 83 |
self.assertEqual(tree.text, "char") |
| 84 |
self.assertEqual(tree.attrib[ |
| 85 |
'{http://www.w3.org/2001/XMLSchema-instance}type'], 'vs:SimpleDataType') |
| 86 |
|
| 87 |
|
| 88 |
class DeletedTest(testhelpers.VerboseTest): |
| 89 |
"""tests for deletion of record doing roughly what's necessary. |
| 90 |
""" |
| 91 |
# All these things need to run in sequence. Lousy. |
| 92 |
rdId = 'data/pubtest' |
| 93 |
|
| 94 |
resources = [("connection", tresc.dbConnection)] |
| 95 |
|
| 96 |
# def tearDown(self): |
| 97 |
# publication._purgeFromServiceTables(self.rdId, self.connection) |
| 98 |
# self.connection.commit() |
| 99 |
|
| 100 |
def _makeDeletedRecord(self): |
| 101 |
return base.makeStruct(nonservice.DeletedResource, |
| 102 |
resTuple={"sourceRD": "foo", "resId": "bar", "recTimestamp": |
| 103 |
datetime.datetime(2010, 10, 10, 10, 10, 10), |
| 104 |
"ivoid": "ivo://%s/foo/bar"%base.getConfig("ivoa", "authority")}) |
| 105 |
|
| 106 |
def testResob(self): |
| 107 |
dr = self._makeDeletedRecord() |
| 108 |
self.assertEqual(base.getMetaText(dr, "identifier"), |
| 109 |
"ivo://%s/foo/bar"%base.getConfig("ivoa", "authority")) |
| 110 |
self.assertEqual(base.getMetaText(dr, "status"), "deleted") |
| 111 |
|
| 112 |
def testResrec(self): |
| 113 |
dr = self._makeDeletedRecord() |
| 114 |
oairec = builders.getVOResourceElement(dr).render() |
| 115 |
self.assertTrue(b'<oai:header status="deleted"><oai:identifier>' |
| 116 |
b'ivo://x-testing/foo/bar</oai:identifier><oai:datestamp>' |
| 117 |
b'2010-10-10T10:10:10Z</oai:datestamp></oai:header></oai:record>' |
| 118 |
in oairec) |
| 119 |
|
| 120 |
def _createPublication(self): |
| 121 |
rd = api.getRD(self.rdId) |
| 122 |
publication.updateServiceList([rd], connection=self.connection) |
| 123 |
self.connection.commit() |
| 124 |
|
| 125 |
def _deletePublication(self): |
| 126 |
rd = api.getRD(self.rdId) |
| 127 |
del rd.services[0] |
| 128 |
publication.updateServiceList([rd], connection=self.connection) |
| 129 |
self.connection.commit() |
| 130 |
|
| 131 |
def _assertPublished(self): |
| 132 |
# see if oaiinter functions see new service |
| 133 |
yesterday = datetime.datetime.today()+ datetime.timedelta(days=-1) |
| 134 |
matches = [tup for tup in oaiinter.getMatchingRestups( |
| 135 |
{"from": yesterday.strftime(utils.isoTimestampFmt)}) |
| 136 |
if tup["sourceRD"]==self.rdId] |
| 137 |
self.assertTrue(len(matches)==1, "Publication did not write record.") |
| 138 |
match = matches[0] |
| 139 |
self.assertTrue( |
| 140 |
(datetime.datetime.utcnow()-match["recTimestamp"]).seconds==0, |
| 141 |
"Stale publication record? Your machine can't be that slow") |
| 142 |
|
| 143 |
def _assertUnpublished(self): |
| 144 |
yesterday = datetime.datetime.today()+ datetime.timedelta(days=-1) |
| 145 |
matches = [tup for tup in oaiinter.getMatchingRestups( |
| 146 |
{"from": yesterday.strftime(utils.isoTimestampFmt)}) |
| 147 |
if tup["sourceRD"]==self.rdId] |
| 148 |
self.assertTrue(len(matches)==1, "Unpublication deleted record.") |
| 149 |
match = matches[0] |
| 150 |
self.assertTrue(match["deleted"], |
| 151 |
"Unpublication didn't set deleted flag.") |
| 152 |
|
| 153 |
def _assertCanBuildResob(self): |
| 154 |
restup = [tup for tup in oaiinter.getMatchingRestups({}) |
| 155 |
if tup["sourceRD"]==self.rdId][0] |
| 156 |
resob = registry.getResobFromRestup(restup) |
| 157 |
self.assertEqual(resob.resType, "deleted") |
| 158 |
dcRepr = builders.getDCResourceElement(resob).render() |
| 159 |
self.assertTrue(b'<oai:header status="deleted"' in dcRepr) |
| 160 |
self.assertTrue( |
| 161 |
b"<oai:identifier>ivo://x-testing/data/pubtest/moribund<" |
| 162 |
in dcRepr) |
| 163 |
voRepr = builders.getVOResourceElement(resob).render() |
| 164 |
self.assertTrue(b'<oai:header status="deleted"' in voRepr) |
| 165 |
self.assertTrue( |
| 166 |
b"<oai:identifier>ivo://x-testing/data/pubtest/moribund<" |
| 167 |
in voRepr) |
| 168 |
|
| 169 |
def testBigAndUgly(self): |
| 170 |
self._createPublication() |
| 171 |
self._assertPublished() |
| 172 |
|
| 173 |
# Must work a second time, overwriting the old junk |
| 174 |
self._createPublication() |
| 175 |
self._assertPublished() |
| 176 |
|
| 177 |
# reset the rectimestamp so the test fails if delete doesn't |
| 178 |
# update it. |
| 179 |
self.connection.execute("update dc.resources set rectimestamp='2010-01-01'" |
| 180 |
" where ivoid='ivo://x-testing/data/pubtest/moribund'") |
| 181 |
self.connection.commit() |
| 182 |
|
| 183 |
# Now nuke the record |
| 184 |
self._deletePublication() |
| 185 |
self._assertUnpublished() |
| 186 |
|
| 187 |
# And create a resource object from it |
| 188 |
self._assertCanBuildResob() |
| 189 |
|
| 190 |
|
| 191 |
class _TAPCapabilityElement(testhelpers.TestResource): |
| 192 |
resources = [ |
| 193 |
("oc", tresc.obscoreTable)] |
| 194 |
|
| 195 |
def make(self, deps): |
| 196 |
publication = base.caches.getRD("//tap" |
| 197 |
).getById("run").publications[0] |
| 198 |
res = vosi.CAP.capabilities[ |
| 199 |
capabilities.getCapabilityElement(publication)].render() |
| 200 |
return res, testhelpers.getXMLTree(res, debug=False) |
| 201 |
|
| 202 |
|
| 203 |
class TAPCapabilityTest(testhelpers.VerboseTest): |
| 204 |
resources = [ |
| 205 |
("cap", _TAPCapabilityElement())] |
| 206 |
|
| 207 |
def testObscoreDeclared(self): |
| 208 |
for el in self.cap[1].findall("capability/dataModel"): |
| 209 |
if el.get("ivo-id")=="ivo://ivoa.net/std/obscore#core-1.1": |
| 210 |
self.assertEqual(el.text, "Obscore-1.1") |
| 211 |
break |
| 212 |
else: |
| 213 |
raise AssertionError("Obscore 1.1 not in the declared DMs of TAP Cap") |
| 214 |
|
| 215 |
def testADQLAvailable(self): |
| 216 |
el = self.cap[1].find("capability/language[name='ADQL']") |
| 217 |
self.assertEqual( |
| 218 |
el.xpath("version[.='2.0']")[0].get("ivo-id"), |
| 219 |
"ivo://ivoa.net/std/ADQL#v2.0") |
| 220 |
|
| 221 |
def testADQLVersion21Present(self): |
| 222 |
el = self.cap[1].xpath("capability/language[name='ADQL']/version[.='2.1']") |
| 223 |
self.assertEqual( |
| 224 |
el[0].get("ivo-id"), |
| 225 |
"ivo://ivoa.net/std/ADQL#v2.1") |
| 226 |
|
| 227 |
def testUDFDefined(self): |
| 228 |
parent = self.cap[1].find("capability/language/languageFeatures[" |
| 229 |
"@type='ivo://ivoa.net/std/TAPRegExt#features-udf']") |
| 230 |
for feature in parent.findall("feature"): |
| 231 |
if feature.find("form").text.startswith("gavo_match(pattern"): |
| 232 |
self.assertTrue(feature.find("description").text.startswith( |
| 233 |
"gavo_match returns 1 if the POSIX regular")) |
| 234 |
break |
| 235 |
else: |
| 236 |
raise AssertionError("No gavo_match UDF declared") |
| 237 |
|
| 238 |
def testPolymorphicUDF(self): |
| 239 |
parent = self.cap[1].find("capability/language/languageFeatures[" |
| 240 |
"@type='ivo://ivoa.net/std/TAPRegExt#features-udf']") |
| 241 |
specconvs = [] |
| 242 |
for feature in parent.findall("feature"): |
| 243 |
if feature.find("form").text.startswith("gavo_specconv"): |
| 244 |
specconvs.append(feature) |
| 245 |
self.assertEqual(len(feature), 2) |
| 246 |
|
| 247 |
def testGeometryDefined(self): |
| 248 |
parent = self.cap[1].find("capability/language/languageFeatures[" |
| 249 |
"@type='ivo://ivoa.net/std/TAPRegExt#features-adqlgeo']") |
| 250 |
for feature in parent.findall("feature"): |
| 251 |
if feature.find("form").text=='CIRCLE': |
| 252 |
break |
| 253 |
else: |
| 254 |
raise AssertionError("No CIRCLE ADQL geometry found") |
| 255 |
|
| 256 |
def testBinary2Defined(self): |
| 257 |
el = self.cap[1].xpath("capability/outputFormat" |
| 258 |
"[@ivo-id='ivo://ivoa.net/std/TAPRegExt#output-votable-binary2']")[0] |
| 259 |
self.assertEqual(el.find("mime").text, |
| 260 |
"application/x-votable+xml;serialization=BINARY2") |
| 261 |
self.assertEqual(el.xpath("alias")[0].text, |
| 262 |
"votable/b2") |
| 263 |
|
| 264 |
def testVotableTDDefined(self): |
| 265 |
el = self.cap[1].xpath("capability/outputFormat" |
| 266 |
"[@ivo-id='ivo://ivoa.net/std/TAPRegExt#output-votable-td']")[0] |
| 267 |
self.assertEqual("#".join(e.text for e in el.xpath("mime")), |
| 268 |
"application/x-votable+xml;serialization=TABLEDATA") |
| 269 |
self.assertEqual(len(el.xpath("alias[.='votable/td']")), 1) |
| 270 |
|
| 271 |
def testGeojsonPresent(self): |
| 272 |
el = self.cap[1].xpath("capability/outputFormat[alias='geojson']")[0] |
| 273 |
self.assertEqual(el.xpath("mime")[0].text, "application/geo+json") |
| 274 |
|
| 275 |
|
| 276 |
class _SSACapabilityElement(testhelpers.TestResource): |
| 277 |
def make(self, deps): |
| 278 |
publication = testhelpers.getTestRD("ssatest" |
| 279 |
).getById("s").publications[0] |
| 280 |
res = vosi.CAP.capabilities[ |
| 281 |
capabilities.getCapabilityElement(publication)].render() |
| 282 |
return res, testhelpers.getXMLTree(res, debug=False)[0] |
| 283 |
|
| 284 |
|
| 285 |
class SSAPCapabilityTest(testhelpers.VerboseTest, testtricks.XSDTestMixin): |
| 286 |
resources = [("textAndTree", _SSACapabilityElement())] |
| 287 |
|
| 288 |
def testValid(self): |
| 289 |
self.assertValidates(self.textAndTree[0]) |
| 290 |
|
| 291 |
def testCapabilityAttributes(self): |
| 292 |
tree = self.textAndTree[1] |
| 293 |
self.assertEqual(tree.attrib["standardID"], 'ivo://ivoa.net/std/ssa') |
| 294 |
self.assertEqual( |
| 295 |
tree.attrib['{http://www.w3.org/2001/XMLSchema-instance}type'], |
| 296 |
'ssap:SimpleSpectralAccess') |
| 297 |
|
| 298 |
def testInterfaceIsStandard(self): |
| 299 |
intf = self.textAndTree[1].find("interface") |
| 300 |
self.assertEqual(intf.attrib["role"], "std") |
| 301 |
|
| 302 |
def testInterfaceHasStandardParam(self): |
| 303 |
for paramEl in self.textAndTree[1].findall("interface/param"): |
| 304 |
if paramEl.find("name").text=="BAND": |
| 305 |
break |
| 306 |
else: |
| 307 |
raise AssertionError("No BAND input parameter in SSAP interface") |
| 308 |
self.assertEqual(paramEl.attrib["std"], "true") |
| 309 |
self.assertEqual(paramEl.find("unit").text, "m") |
| 310 |
|
| 311 |
def testInterfaceHasLocalParam(self): |
| 312 |
for paramEl in self.textAndTree[1].findall("interface/param"): |
| 313 |
if paramEl.find("name").text=="excellence": |
| 314 |
break |
| 315 |
else: |
| 316 |
raise AssertionError("No excellence input parameter in SSAP interface") |
| 317 |
self.assertEqual(paramEl.attrib["std"], "false") |
| 318 |
self.assertEqual(paramEl.find("description").text, "random number") |
| 319 |
|
| 320 |
def testMaxRecordsReflectsConfig(self): |
| 321 |
self.assertEqual(int(self.textAndTree[1].find("maxRecords").text), |
| 322 |
base.getConfig("ivoa", "dalHardLimit")) |
| 323 |
|
| 324 |
def testTestQuery(self): |
| 325 |
self.assertEqual(self.textAndTree[1].find("testQuery/queryDataCmd").text, |
| 326 |
"TARGETNAME=alpha%20Boo") |
| 327 |
|
| 328 |
def testRecordCreationFailsOnMissingMeta(self): |
| 329 |
publication = testhelpers.getTestRD("ssatest" |
| 330 |
).getById("s").publications[0] |
| 331 |
publication.parent.delMeta("ssap.testQuery") |
| 332 |
self.assertRaisesWithMsg(base.NoMetaKey, |
| 333 |
utils.EqualingRE('On <Service s at .*data/ssatest.rd, line 150>:' |
| 334 |
' No meta item ssap.testQuery'), |
| 335 |
capabilities.getCapabilityElement, |
| 336 |
(publication,)) |
| 337 |
|
| 338 |
def testNestedMeta(self): |
| 339 |
with testtricks.testFile( |
| 340 |
os.path.join(base.getConfig("inputsDir"), "data", "tmp.rd"), |
| 341 |
"""<resource schema="test" resdir="."> |
| 342 |
<service id="t" original="data/ssatest#s"> |
| 343 |
<publish render="ssap.xml"/> |
| 344 |
<meta name="ssap"> |
| 345 |
<meta name="dataSource">you bet</meta> |
| 346 |
<meta name="testQuery">HAHA.</meta> |
| 347 |
</meta></service></resource>"""): |
| 348 |
res = capabilities.getCapabilityElement(testhelpers.getTestRD("tmp" |
| 349 |
).getById("t").publications[0]).render() |
| 350 |
self.assertTrue(b'<dataSource>you bet</dataSource>' in res) |
| 351 |
|
| 352 |
def testSimpleDataTypeUsed(self): |
| 353 |
for dt in self.textAndTree[1].findall("interface/param/dataType"): |
| 354 |
self.assertEqual( |
| 355 |
dt.attrib["{http://www.w3.org/2001/XMLSchema-instance}type"], |
| 356 |
"vs:SimpleDataType") |
| 357 |
|
| 358 |
|
| 359 |
class _SIACapabilityElement(testhelpers.TestResource): |
| 360 |
def make(self, deps): |
| 361 |
publication = testhelpers.getTestRD("test" |
| 362 |
).getById("pgsiapsvc").publications[0] |
| 363 |
res = capabilities.getCapabilityElement(publication).render() |
| 364 |
return res, testhelpers.getXMLTree(res, debug=False) |
| 365 |
|
| 366 |
|
| 367 |
class SIAPCapabilityTest(testhelpers.VerboseTest): |
| 368 |
resources = [("txNTree", _SIACapabilityElement())] |
| 369 |
|
| 370 |
def testNoEmptyMax(self): |
| 371 |
self.assertFalse(self.txNTree[1].xpath("//maxImageExtent/lat"), |
| 372 |
"maxImageExtent/lat should be empty but is not") |
| 373 |
|
| 374 |
def testNoFilledMax(self): |
| 375 |
self.assertEqual( |
| 376 |
self.txNTree[1].xpath("//maxImageExtent/long")[0].text, |
| 377 |
"10") |
| 378 |
|
| 379 |
def testImageSizeAtomic(self): |
| 380 |
children = self.txNTree[1].xpath("//maxImageSize") |
| 381 |
self.assertEqual(testhelpers.pickSingle(children).text, "3000") |
| 382 |
|
| 383 |
def testTestQuery(self): |
| 384 |
tqEl = self.txNTree[1].xpath("/capability/testQuery")[0] |
| 385 |
self.assertEqual(len(tqEl), 2) |
| 386 |
longs = tqEl.xpath("*/long") |
| 387 |
self.assertEqual([l.text for l in longs], ["10", "0.4"]) |
| 388 |
|
| 389 |
|
| 390 |
class _ObscoreCoverage(testhelpers.TestResource): |
| 391 |
resources = [("obscore", tresc.obscoreTable), ("conn", tresc.dbConnection)] |
| 392 |
|
| 393 |
def make(self, deps): |
| 394 |
# this doesn't have return a value; it just runs dachs limits |
| 395 |
from gavo.user import limits |
| 396 |
limits.updateForRD( |
| 397 |
base.caches.getRD("//obscore"), |
| 398 |
deps["conn"], |
| 399 |
100, |
| 400 |
False) |
| 401 |
base.caches.clearForName("__system__/obscore") |
| 402 |
return True |
| 403 |
|
| 404 |
|
| 405 |
class _SIA2Record(testhelpers.TestResource): |
| 406 |
resources = [("obscore_covered", _ObscoreCoverage())] |
| 407 |
|
| 408 |
def make(self, deps): |
| 409 |
base.caches.clearForName("__system__/siap2") |
| 410 |
with testhelpers.userconfigContent(""" |
| 411 |
<NXSTREAM id="sitewidesiap2-extras"> |
| 412 |
<meta name="description"> |
| 413 |
This is just an illusion. |
| 414 |
</meta> |
| 415 |
<meta> |
| 416 |
testQuery.pos.ra: 3.14 |
| 417 |
testQuery.pos.dec: 0.5 |
| 418 |
testQuery.size.ra: 0.5 |
| 419 |
testQuery.size.dec: 0.5 |
| 420 |
</meta> |
| 421 |
<meta name="creationDate">2016-08-15T12:40:00</meta> |
| 422 |
<meta name="subject">Images</meta> |
| 423 |
<meta name="shortName">unittest SIA2</meta> |
| 424 |
<meta name="title">DaCHS unittests SIAv2 service</meta> |
| 425 |
<meta name="sia.type">Pointed</meta> |
| 426 |
</NXSTREAM>"""): |
| 427 |
resOb = base.resolveCrossId("//siap2#sitewide") |
| 428 |
res = builders.getVORMetadataElement(resOb).render() |
| 429 |
return res, testhelpers.getXMLTree(res, debug=False) |
| 430 |
|
| 431 |
|
| 432 |
class SIAP2RecordTest(testhelpers.VerboseTest, testhelpers.XSDTestMixin): |
| 433 |
resources = [("txNTree", _SIA2Record())] |
| 434 |
|
| 435 |
def testNoEmptyMax(self): |
| 436 |
self.assertFalse(self.txNTree[1].xpath("//maxImageExtent/lat"), |
| 437 |
"maxImageExtent/lat should be empty but is not") |
| 438 |
|
| 439 |
def testTestQuery(self): |
| 440 |
tqEl = self.txNTree[1].xpath("capability/testQuery")[0] |
| 441 |
self.assertEqual(len(tqEl), 2) |
| 442 |
longs = tqEl.xpath("*/long") |
| 443 |
self.assertEqual([l.text for l in longs], ["3.14", "0.5"]) |
| 444 |
|
| 445 |
def testStandardId(self): |
| 446 |
self.assertEqual(self.txNTree[1].xpath("capability/@standardID")[0], |
| 447 |
"ivo://ivoa.net/std/sia#query-2.0") |
| 448 |
|
| 449 |
def testValid(self): |
| 450 |
self.assertValidates(self.txNTree[0]) |
| 451 |
|
| 452 |
def testDerivedServedByObscore(self): |
| 453 |
self.assertEqual( |
| 454 |
self.txNTree[1].xpath("content/relationship[" |
| 455 |
"relationshipType='IsServedBy']/relatedResource/@ivo-id")[0], |
| 456 |
"ivo://x-testing/__system__/obscore/obscore") |
| 457 |
|
| 458 |
def testSpatialCoverage(self): |
| 459 |
self.assertEqual( |
| 460 |
self.txNTree[1].xpath("coverage/spatial")[0].text.split()[0], |
| 461 |
"4/1087") |
| 462 |
|
| 463 |
def testTemporalCoverage(self): |
| 464 |
self.assertEqual( |
| 465 |
self.txNTree[1].xpath("coverage/temporal")[0].text, |
| 466 |
"55300 55462") |
| 467 |
|
| 468 |
def testSpectralCoverage(self): |
| 469 |
self.assertEqual( |
| 470 |
self.txNTree[1].xpath("coverage/spectral")[0].text, |
| 471 |
"1.203177382e-27 1.986445857e-18") |
| 472 |
|
| 473 |
|
| 474 |
class AuthorityTest(testhelpers.VerboseTest): |
| 475 |
# This test will fail until defaultmeta.txt has the necessary entries |
| 476 |
# and //services is published |
| 477 |
def testAuthorityResob(self): |
| 478 |
authId = "ivo://%s"%base.getConfig("ivoa", "authority") |
| 479 |
resob = registry.getResobFromIdentifier(authId) |
| 480 |
self.assertEqual(base.getMetaText(resob, "identifier"), authId) |
| 481 |
self.assertFalse(resob.getMeta("title") is None) |
| 482 |
self.assertFalse(resob.getMeta("_metadataUpdated") is None) |
| 483 |
self.assertEqual(base.getMetaText(resob, "sets"), "ivo_managed") |
| 484 |
|
| 485 |
def testAuthorityVORes(self): |
| 486 |
resob = registry.getResobFromIdentifier( |
| 487 |
"ivo://%s"%base.getConfig("ivoa", "authority")) |
| 488 |
resrec = builders.getVORMetadataElement(resob).render() |
| 489 |
tree = ElementTree.fromstring(resrec) |
| 490 |
self.assertEqual(tree.find("managingOrg").text, |
| 491 |
"Your organisation's name") |
| 492 |
self.assertTrue(b'created="' in resrec) |
| 493 |
|
| 494 |
|
| 495 |
class _StandardsRec(testhelpers.TestResource): |
| 496 |
def make(self, ignored): |
| 497 |
class Container(meta.MetaMixin): |
| 498 |
resType = "standard" |
| 499 |
rd = base.caches.getRD("//services") |
| 500 |
container = Container() |
| 501 |
container.setMetaParent(container.rd) |
| 502 |
|
| 503 |
meta.parseMetaStream(container, """ |
| 504 |
recTimestamp: 2010-10-10T10:10:10Z |
| 505 |
sets: ivo_managed |
| 506 |
status: active |
| 507 |
title: a test standard |
| 508 |
subject: testing |
| 509 |
referenceURL: http://bar |
| 510 |
identifier: ivo://foo.bar |
| 511 |
doi: 10.5072/teststuff |
| 512 |
endorsedVersion: 1.1 |
| 513 |
endorsedVersion.status: wd |
| 514 |
endorsedVersion.use: preferred |
| 515 |
endorsedVersion: 1.0 |
| 516 |
endorsedVersion.status: rec |
| 517 |
endorsedVersion.use: deprecated |
| 518 |
deprecated: rather use something else |
| 519 |
key: |
| 520 |
key.name: bar1 |
| 521 |
key.description: This one's open |
| 522 |
key: |
| 523 |
key.name: bar2 |
| 524 |
key.description: This one's closed |
| 525 |
""") |
| 526 |
return getGetRecordResponse(container) |
| 527 |
|
| 528 |
|
| 529 |
class StandardsTest(testhelpers.VerboseTest, testtricks.XSDTestMixin): |
| 530 |
resources = [("srcAndTree", _StandardsRec())] |
| 531 |
|
| 532 |
def testIsValid(self): |
| 533 |
self.assertValidates(self.srcAndTree[0]) |
| 534 |
|
| 535 |
def testTwoEndorsedVersions(self): |
| 536 |
self.assertEqual(len(self.srcAndTree[1].xpath("//endorsedVersion")), 2) |
| 537 |
|
| 538 |
def testEndorsedVersionMetaPresent(self): |
| 539 |
el = self.srcAndTree[1].xpath("//endorsedVersion")[0] |
| 540 |
self.assertEqual(el.get("status"), "wd") |
| 541 |
self.assertEqual(el.get("use"), "preferred") |
| 542 |
self.assertEqual(el.text, "1.1") |
| 543 |
|
| 544 |
def testDeprecated(self): |
| 545 |
self.assertEqual(self.srcAndTree[1].xpath("//deprecated")[0].text, |
| 546 |
"rather use something else") |
| 547 |
|
| 548 |
def testTwoKeys(self): |
| 549 |
self.assertEqual(len(self.srcAndTree[1].xpath("//key")), 2) |
| 550 |
|
| 551 |
def testKeyStructure(self): |
| 552 |
el = self.srcAndTree[1].xpath("//key")[0] |
| 553 |
self.assertEqual(el[0].tag, "name") |
| 554 |
self.assertEqual(el[0].text, "bar1") |
| 555 |
self.assertEqual(el[1].tag, "description") |
| 556 |
self.assertEqual(el[1].text, "This one's open") |
| 557 |
|
| 558 |
def testAltIdentifiers(self): |
| 559 |
els = self.srcAndTree[1].xpath("//metadata/Resource/altIdentifier") |
| 560 |
self.assertEqual([el.text for el in els], [ |
| 561 |
"doi:10.5072/teststuff"]) |
| 562 |
|
| 563 |
|
| 564 |
class _DocRec(testhelpers.TestResource): |
| 565 |
def make(self, ignored): |
| 566 |
base.setConfig("ivoa", "registerAlternative", "True") |
| 567 |
try: |
| 568 |
rd = base.parseFromString(rscdesc.RD, |
| 569 |
rf"""<resource schema="test"> |
| 570 |
<macDef name="waran">Warning: Waran</macDef> |
| 571 |
<meta name="description">We should not have any backslashes |
| 572 |
here: \waran.</meta> |
| 573 |
{tresc.A_RES_REC} |
| 574 |
</resource>""") |
| 575 |
|
| 576 |
return getGetRecordResponse(rd.getById("rec")) |
| 577 |
finally: |
| 578 |
base.setConfig("ivoa", "registerAlternative", "False") |
| 579 |
|
| 580 |
|
| 581 |
class DocumentResTest(testhelpers.VerboseTest, testtricks.XSDTestMixin): |
| 582 |
# Which we're abusing as a test for https mirror url generation, too, |
| 583 |
# because it fits so well. |
| 584 |
resources = [("srcAndTree", _DocRec())] |
| 585 |
|
| 586 |
def testIsValid(self): |
| 587 |
self.assertValidates(self.srcAndTree[0]) |
| 588 |
|
| 589 |
def testEnglishIsPrimary(self): |
| 590 |
lang = self.srcAndTree[1].xpath("//capability[1]/languageCode")[0] |
| 591 |
self.assertEqual(lang.text, "en") |
| 592 |
|
| 593 |
def testLocTitle(self): |
| 594 |
els = self.srcAndTree[1].xpath( |
| 595 |
"//capability[languageCode='de']/locTitle") |
| 596 |
self.assertEqual(testhelpers.pickSingle(els).text, "Ja, geh zu.") |
| 597 |
|
| 598 |
def testAccessRenderedURLs(self): |
| 599 |
urls = self.srcAndTree[1].xpath("//interface[@role='rendered']/accessURL") |
| 600 |
self.assertEqual(len(urls), 3) |
| 601 |
self.assertEqual(urls[1].text, "http://foo.fr/ycnaf/cod.pdf") |
| 602 |
|
| 603 |
def testExtensionInferredMediaType(self): |
| 604 |
self.assertEqual( |
| 605 |
self.srcAndTree[1].xpath( |
| 606 |
"//interface[accessURL='http://foo.fr/ycnaf/cod.pdf']" |
| 607 |
"/resultType")[0].text, |
| 608 |
"application/pdf") |
| 609 |
|
| 610 |
def testExtensionExplicitMediaType(self): |
| 611 |
self.assertEqual( |
| 612 |
self.srcAndTree[1].xpath( |
| 613 |
"//interface[accessURL='http://localhost:8080/" |
| 614 |
"fancy/doc']/resultType")[0].text, |
| 615 |
"application/msword") |
| 616 |
|
| 617 |
def testSourceURL(self): |
| 618 |
urls = self.srcAndTree[1].xpath("//interface[@role='source']/accessURL") |
| 619 |
self.assertEqual(len(urls), 2) |
| 620 |
self.assertEqual(urls[0].text, "svn://foo.us/docs/src/fancy") |
| 621 |
self.assertEqual(urls[1].text, "git+ssh://foo.fr/scod/src/ycnaf") |
| 622 |
|
| 623 |
def testRelationships(self): |
| 624 |
relations = self.srcAndTree[1].xpath("//relationship") |
| 625 |
t = testhelpers.pickSingle(relations).xpath("relationshipType")[0] |
| 626 |
|
| 627 |
self.assertEqual(t.text, "Cites") |
| 628 |
ids = relations[0].xpath("relatedResource") |
| 629 |
self.assertEqual(ids[0].text, "Sample useful resource") |
| 630 |
self.assertEqual(ids[1].attrib["ivo-id"], "ivo://crapola/work") |
| 631 |
|
| 632 |
def testAltIdentifier(self): |
| 633 |
rel = testhelpers.pickSingle(self.srcAndTree[1].xpath("//relationship[relationshipType='Cites']/relatedResource[@altIdentifier!='']")) |
| 634 |
self.assertEqual(rel.get("altIdentifier"), "ascl:1101.010") |
| 635 |
|
| 636 |
def testNewsRenderingWithRole(self): |
| 637 |
sillyDates = self.srcAndTree[1].xpath("//date[@role='silly']") |
| 638 |
self.assertEqual(testhelpers.pickSingle(sillyDates).text, "2010-10-10") |
| 639 |
|
| 640 |
def testNewsRenderingDefaultRole(self): |
| 641 |
upDates = self.srcAndTree[1].xpath("//date[@role='Updated']") |
| 642 |
# there's two updates: one from news, another from the _dataUpdated meta |
| 643 |
self.assertEqual(len(upDates), 2) |
| 644 |
self.assertEqual( |
| 645 |
set(e.text for e in upDates), |
| 646 |
set(["2011-11-11", "2015-10-10T09:09:09Z"])) |
| 647 |
|
| 648 |
def testHTTPSMirrorForUs(self): |
| 649 |
urls = self.srcAndTree[1].xpath("//interface[@role='rendered']/mirrorURL") |
| 650 |
self.assertEqual(urls[0].text, "https://localhost/fancy/doc") |
| 651 |
|
| 652 |
def testNoHTTPSMirrorForOthers(self): |
| 653 |
urls = self.srcAndTree[1].xpath("//capability[1]/interface/mirrorURL") |
| 654 |
self.assertEqual(len(urls), 0) |
| 655 |
|
| 656 |
def testSetSpec(self): |
| 657 |
self.assertEqual(set(n.text for n in |
| 658 |
self.srcAndTree[1].xpath("GetRecord/record/header/setSpec")), |
| 659 |
set(["ivo_managed", "local"])) |
| 660 |
|
| 661 |
def testMacroExpanded(self): |
| 662 |
self.assertEqual( |
| 663 |
self.srcAndTree[1].xpath( |
| 664 |
"GetRecord/record/metadata/Resource/content/description")[0].text, |
| 665 |
"We should not have any backslashes here: Warning: Waran.") |
| 666 |
|
| 667 |
def testTablesetPresent(self): |
| 668 |
self.assertEqual( |
| 669 |
{m.text for m in self.srcAndTree[1].xpath("//tableset/schema/name")}, |
| 670 |
{"test", "dc"}) |
| 671 |
self.assertEqual( |
| 672 |
self.srcAndTree[1].xpath("//table/column[name='anint']/name")[0].text, |
| 673 |
"anint") |
| 674 |
|
| 675 |
|
| 676 |
class _ResourceGrammar(testhelpers.TestResource): |
| 677 |
def make(self, ignored): |
| 678 |
return base.makeStruct(publication.RDRscRecGrammar) |
| 679 |
|
| 680 |
_resourceGrammar = _ResourceGrammar() |
| 681 |
|
| 682 |
|
| 683 |
class DataPublicationMetaTest(testhelpers.VerboseTest): |
| 684 |
# Tests concerning metadata handling with the table data registry interface |
| 685 |
resources = [("conn", tresc.dbConnection), ("resg", _resourceGrammar)] |
| 686 |
|
| 687 |
def testMinimalMeta(self): |
| 688 |
rd = base.parseFromString(rscdesc.RD, """<resource schema="data"> |
| 689 |
<table id="ronk"> |
| 690 |
<register sets="ivo_managed,local"/> |
| 691 |
</table></resource>""") |
| 692 |
self.assertRaisesWithMsg(base.MetaValidationError, |
| 693 |
'Meta structure on ronk (within IO:\'<resource schema="data"> <table id="ronk"> <register ...\', line 2)' |
| 694 |
" did not validate: Meta key creationDate missing," |
| 695 |
" Meta key description missing, Meta key subject missing", |
| 696 |
list, |
| 697 |
(self.resg.parse(rd),)) |
| 698 |
|
| 699 |
def testIterDataTable(self): |
| 700 |
rd = base.parseFromString(rscdesc.RD, f"""<resource schema="data"> |
| 701 |
{tresc.MINIMAL_META} |
| 702 |
<meta name="referenceURL">b</meta> |
| 703 |
<table id="ronk"><register sets="ivo_managed,local"/> |
| 704 |
</table></resource>""") |
| 705 |
recs = list(self.resg.parse(rd)) |
| 706 |
|
| 707 |
self.assertEqual(len(recs), 6) |
| 708 |
roles, sets = set(), set() |
| 709 |
|
| 710 |
for role, rec in recs: |
| 711 |
roles.add(role) |
| 712 |
if role=="resources": |
| 713 |
self.assertEqual(rec["resId"], "ronk") |
| 714 |
elif role=="sets": |
| 715 |
sets.add(rec["setName"]) |
| 716 |
elif role=="interfaces": |
| 717 |
self.assertEqual(rec["referenceURL"], |
| 718 |
'http://localhost:8080/tableinfo/data.ronk') |
| 719 |
self.assertEqual(rec["accessURL"], |
| 720 |
'http://localhost:8080/tableinfo/data.ronk?tapinfo=True') |
| 721 |
elif role=="subjects": |
| 722 |
self.assertEqual(rec["subject"], "a") |
| 723 |
elif role=="authors": |
| 724 |
self.assertEqual(rec["author"], "Could be same as contact.name") |
| 725 |
|
| 726 |
self.assertEqual(roles, {"authors", "subjects", "sets", "interfaces", |
| 727 |
"sets", "resources"}) |
| 728 |
self.assertEqual(sets, {"ivo_managed", "local"}) |
| 729 |
|
| 730 |
def testIterDataData(self): |
| 731 |
rd = base.parseFromString(rscdesc.RD, f"""<resource schema="data"> |
| 732 |
{tresc.MINIMAL_META} |
| 733 |
<meta name="referenceURL">b</meta> |
| 734 |
<table id="ronk"/><table id="funk"/> |
| 735 |
<data id="ronkcoll"><register sets="ivo_managed,local"/> |
| 736 |
<make table="ronk"/><make table="funk"/> |
| 737 |
</data></resource>""") |
| 738 |
rd.sourceId = "data/test" |
| 739 |
recs = list(self.resg.parse(rd)) |
| 740 |
|
| 741 |
roles, sets = set(), set() |
| 742 |
|
| 743 |
for role, rec in recs: |
| 744 |
roles.add(role) |
| 745 |
if role=="resources": |
| 746 |
self.assertEqual(rec["resId"], "ronkcoll") |
| 747 |
elif role=="sets": |
| 748 |
sets.add(rec["setName"]) |
| 749 |
elif role=="interfaces": |
| 750 |
self.assertEqual(rec["referenceURL"], |
| 751 |
'http://localhost:8080/browse/data/test') |
| 752 |
self.assertEqual(rec["accessURL"], |
| 753 |
'http://localhost:8080/browse/data/test?tapinfo=True') |
| 754 |
elif role=="subjects": |
| 755 |
self.assertEqual(rec["subject"], "a") |
| 756 |
elif role=="authors": |
| 757 |
self.assertEqual(rec["author"], "Could be same as contact.name") |
| 758 |
|
| 759 |
self.assertEqual(roles, {"authors", "subjects", "sets", "interfaces", |
| 760 |
"sets", "resources"}) |
| 761 |
self.assertEqual(sets, {"ivo_managed", "local"}) |
| 762 |
|
| 763 |
def testRejectedWithoutId(self): |
| 764 |
self.assertRaisesWithMsg(base.StructureError, |
| 765 |
'At IO:\'<resource schema="data"> <table><register sets="ivo_m...\', (3, 3):' |
| 766 |
" Published tables need an assigned id.", |
| 767 |
base.parseFromString, |
| 768 |
(rscdesc.RD, """<resource schema="data"> |
| 769 |
<table><register sets="ivo_managed,local"/> |
| 770 |
</table></resource>""")) |
| 771 |
|
| 772 |
def testDataPublicationPurged(self): |
| 773 |
# this is actually a companion to DataPublicationTest making sure |
| 774 |
# that _PublishedData's clean method has worked, possibly last time. |
| 775 |
# Sorry 'bout that funkyness, but this is tricky to do sanely. |
| 776 |
self.assertEqual(len(list( |
| 777 |
self.conn.query("SELECT * FROM dc.resources where sourcerd=%(rdId)s", |
| 778 |
{"rdId": _PublishedData.rdId}))), 0, |
| 779 |
"registrytest._PublishedData.clean failed?") |
| 780 |
self.assertEqual( |
| 781 |
common.getDependencies("__system__/services", connection=self.conn), |
| 782 |
[], |
| 783 |
"registrytest._PublishedData.clean failed?") |
| 784 |
|
| 785 |
def testContentLevelChecked(self): |
| 786 |
rec = base.parseFromString(nonservice.ResRec, |
| 787 |
f"""<resRec> |
| 788 |
{tresc.MINIMAL_META} |
| 789 |
<meta name="referenceURL">b</meta> |
| 790 |
<meta> |
| 791 |
resType: document |
| 792 |
contentLevel: University |
| 793 |
</meta></resRec>""") |
| 794 |
self.assertRaisesWithMsg( |
| 795 |
base.MetaValidationError, |
| 796 |
"Meta structure on ResRec item (within IO:'<resRec> <meta> title:x creationDate:2020-03-05T12:13...', line 1) did not validate: contentLevel meta only admits values from voresource/content_level, but 'University' is not in there.", |
| 797 |
base.validateStructure, |
| 798 |
(rec,)) |
| 799 |
|
| 800 |
|
| 801 |
class _ResobGrammarResponse(testhelpers.TestResource): |
| 802 |
"""A resource giving the records the grammar in registry.publication |
| 803 |
spits out for a simple resource. |
| 804 |
""" |
| 805 |
resources = [("resg", _resourceGrammar)] |
| 806 |
|
| 807 |
def make(self, deps): |
| 808 |
tables = {} |
| 809 |
rd = base.caches.getRD("data/ssatest") |
| 810 |
for destTable, row in deps["resg"].parse(rd): |
| 811 |
del row["parser_"] |
| 812 |
tables.setdefault(destTable, []).append(row) |
| 813 |
return tables |
| 814 |
|
| 815 |
|
| 816 |
class ResobGrammarTest(testhelpers.VerboseTest): |
| 817 |
resources = [("tables", _ResobGrammarResponse())] |
| 818 |
|
| 819 |
def testServicePresent(self): |
| 820 |
self.assertEqual(self.tables["resources"][0]["ivoid"], |
| 821 |
'ivo://x-testing/data/ssatest/s') |
| 822 |
|
| 823 |
def testSubjects(self): |
| 824 |
self.assertEqual([r for r in self.tables["subjects"] |
| 825 |
if r["sourceRD"]!="__system__/tap"], [ |
| 826 |
{'sourceRD': 'data/ssatest', 'resId': 's', 'subject': 'testing'}, |
| 827 |
{'sourceRD': 'data/ssatest', 'resId': 'c', 'subject': 'testing'}, |
| 828 |
{'resId': 'hcdtest', 'sourceRD': 'data/ssatest', 'subject': 'testing'}]) |
| 829 |
|
| 830 |
def testAuthors(self): |
| 831 |
self.assertEqual( |
| 832 |
set([r["author"] for r in self.tables["authors"]]), |
| 833 |
set(['Hendrix, J.', 'Page, J', 'The Master Tester'])) |
| 834 |
|
| 835 |
|
| 836 |
class _PublishedRD(testhelpers.TestResource): |
| 837 |
"""A resource that publishes all the stuff from an RD for while the |
| 838 |
resource exists. |
| 839 |
|
| 840 |
The RD to be published is given in the rdId class attribute. |
| 841 |
""" |
| 842 |
resources = [("conn", tresc.dbConnection)] |
| 843 |
|
| 844 |
def make(self, deps): |
| 845 |
self.conn = deps["conn"] |
| 846 |
rd = base.caches.getRD(self.rdId) |
| 847 |
publication.updateServiceList([rd], connection=self.conn) |
| 848 |
return rd |
| 849 |
|
| 850 |
def clean(self, res): |
| 851 |
publication._purgeFromServiceTables(self.rdId, self.conn) |
| 852 |
self.conn.commit() |
| 853 |
|
| 854 |
|
| 855 |
class _PublishedData(_PublishedRD): |
| 856 |
rdId = "data/testdata" |
| 857 |
|
| 858 |
|
| 859 |
class DataPublicationTest(testhelpers.VerboseTest): |
| 860 |
# Tests for a published table |
| 861 |
resources = [ |
| 862 |
("conn", tresc.dbConnection), |
| 863 |
("pubDataRD", _PublishedData())] |
| 864 |
|
| 865 |
def testPublication(self): |
| 866 |
self.assertEqual(len(list( |
| 867 |
self.conn.query("SELECT * FROM dc.resources where sourcerd=%(rdId)s", |
| 868 |
{"rdId": self.pubDataRD.sourceId}))), 1) |
| 869 |
|
| 870 |
def testAuthorExpanded(self): |
| 871 |
self.assertEqual(next( |
| 872 |
self.conn.query("SELECT author FROM dc.authors" |
| 873 |
" WHERE sourcerd='data/testdata' AND resid='barsobal'"))[0], |
| 874 |
"Your organisation's name") |
| 875 |
|
| 876 |
def testDescriptionExpanded(self): |
| 877 |
self.assertEqual(next( |
| 878 |
self.conn.query("SELECT description FROM dc.resources" |
| 879 |
" WHERE sourcerd='data/testdata' AND resid='barsobal'"))[0], |
| 880 |
"It's expanded!") |
| 881 |
|
| 882 |
def testResobGeneration(self): |
| 883 |
td = self.pubDataRD.getById("barsobal") |
| 884 |
ivoId = base.getMetaText(td, "identifier") |
| 885 |
resOb = registry.getResobFromIdentifier(ivoId) |
| 886 |
self.assertEqual(td, resOb) |
| 887 |
|
| 888 |
def testIsInDependencies(self): |
| 889 |
self.assertEqual( |
| 890 |
registry.getDependencies("__system__/services", connection=self.conn), |
| 891 |
["data/testdata"]) |
| 892 |
|
| 893 |
|
| 894 |
class _DataVORRecord(testhelpers.TestResource): |
| 895 |
def make(self, ignored): |
| 896 |
res = base.caches.getRD("data/testdata") |
| 897 |
tree = testhelpers.getXMLTree( |
| 898 |
builders.getVOResourceElement(res.getById("barsobal" |
| 899 |
)).render(), debug=False) |
| 900 |
return tree.xpath("metadata/Resource")[0] |
| 901 |
|
| 902 |
|
| 903 |
class DataVORTest(testhelpers.VerboseTest): |
| 904 |
resources = [("tree", _DataVORRecord())] |
| 905 |
|
| 906 |
def testPlainInstrument(self): |
| 907 |
self.assertEqual( |
| 908 |
self.tree.xpath("instrument")[0].text, |
| 909 |
"Instrument without identity") |
| 910 |
|
| 911 |
def testRegisteredInstrument(self): |
| 912 |
self.assertEqual( |
| 913 |
self.tree.xpath("instrument")[1].text, |
| 914 |
"Instrument with ivoid") |
| 915 |
self.assertEqual( |
| 916 |
self.tree.xpath("instrument/@ivo-id")[0], |
| 917 |
"ivo://x-example/inst1") |
| 918 |
|
| 919 |
def testPIDInstrument(self): |
| 920 |
self.assertEqual( |
| 921 |
self.tree.xpath("instrument")[2].text, |
| 922 |
"Instrument with ivoid and doi") |
| 923 |
self.assertEqual( |
| 924 |
self.tree.xpath("instrument/@ivo-id")[1], |
| 925 |
"ivo://x-example/inst2") |
| 926 |
self.assertEqual( |
| 927 |
self.tree.xpath("instrument/@altIdentifier")[0], |
| 928 |
"doi:107331/fakefake") |
| 929 |
|
| 930 |
def testDataSource(self): |
| 931 |
self.assertEqual( |
| 932 |
[n.text for n in self.tree.xpath("dataSource")], |
| 933 |
["theory", "observation"]) |
| 934 |
|
| 935 |
|
| 936 |
class _ServiceVORRecord(testhelpers.TestResource): |
| 937 |
def make(self, ignored): |
| 938 |
rd = base.parseFromString(rscdesc.RD, r"""<resource schema="data"> |
| 939 |
<meta name="creationDate">2011-03-04T11:00:00</meta> |
| 940 |
<meta name="title">A senseless service</meta> |
| 941 |
<meta name="source">1989AGAb....2...33W</meta> |
| 942 |
<meta name="type">Other</meta> |
| 943 |
<meta name="type">Simulation</meta> |
| 944 |
<meta name="_example" title="ex1">No text</meta> |
| 945 |
<meta name="_example" title="ex2">Even less</meta> |
| 946 |
<meta name="creator">\upper{f.f.f}</meta> |
| 947 |
<FEED source="//procs#license-cc-by" what="senseless data"/> |
| 948 |
<meta name="rights">Licensed CC-BY</meta> |
| 949 |
<meta name="rights.rightsURI" |
| 950 |
>http://creativecommons.org/licenses/by/3.0/</meta> |
| 951 |
<meta name="productType">spectrum</meta> |
| 952 |
<meta name="productType">timeseries</meta> |
| 953 |
<coverage> |
| 954 |
<spatial>2/12-14</spatial> |
| 955 |
</coverage> |
| 956 |
<table id="data" onDisk="True" adql="True"> |
| 957 |
<mixin>//obscore#publishSSAPMIXC</mixin> |
| 958 |
<publish/> |
| 959 |
<column name="score"/> |
| 960 |
</table> |
| 961 |
<service id="glonk"> |
| 962 |
<meta name="ssap.dataSource">pointed</meta> |
| 963 |
<meta name="ssap.testQuery">MAXREC=1</meta> |
| 964 |
<dbCore queriedTable="data"/> |
| 965 |
<publish render="form" sets="ivo_managed,local"/> |
| 966 |
<publish render="ssap.xml" sets="ivo_managed"/> |
| 967 |
</service></resource>""") |
| 968 |
rd.sourceId = "funky/town" |
| 969 |
base.caches.getRD.cacheCopy["funky/town"] = rd |
| 970 |
tree = testhelpers.getXMLTree( |
| 971 |
builders.getVOResourceElement(rd.services[0]).render(), debug=False) |
| 972 |
return tree.xpath("metadata/Resource")[0] |
| 973 |
|
| 974 |
_serviceVORRecord = _ServiceVORRecord() |
| 975 |
|
| 976 |
|
| 977 |
class ServiceRecordTest(testhelpers.VerboseTest): |
| 978 |
resources = [("rec", _serviceVORRecord)] |
| 979 |
|
| 980 |
def testVersion(self): |
| 981 |
self.assertEqual(self.rec.get("version"), "1.2") |
| 982 |
|
| 983 |
def testSourceFormatInferred(self): |
| 984 |
self.assertEqual(self.rec.xpath("content/source")[0].get("format"), |
| 985 |
"bibcode") |
| 986 |
|
| 987 |
def testContentTypePresent(self): |
| 988 |
self.assertEqual(self.rec.xpath("content/type")[0].text, |
| 989 |
"Other") |
| 990 |
self.assertEqual(self.rec.xpath("content/type")[1].text, |
| 991 |
"Simulation") |
| 992 |
|
| 993 |
def testExamplesCap(self): |
| 994 |
cap = self.rec.xpath("//capability[@standardID='ivo://ivoa.net/std" |
| 995 |
"/DALI#examples']")[0] |
| 996 |
self.assertEqual(cap.xpath("interface")[0].get( |
| 997 |
"{http://www.w3.org/2001/XMLSchema-instance}type"), |
| 998 |
"vr:WebBrowser") |
| 999 |
self.assertTrue(cap.xpath("interface/accessURL")[0].text.endswith( |
| 1000 |
"/funky/town/glonk/examples")) |
| 1001 |
|
| 1002 |
def testRights(self): |
| 1003 |
node = self.rec.xpath("//Resource/rights")[0] |
| 1004 |
self.assertEqual(node.text.strip(), "senseless data is licensed under the" |
| 1005 |
" `Creative Commons Attribution 4.0 License <http://creativecommons." |
| 1006 |
"org/licenses/by/4.0/>`_\n\n.. image:: /static/img/ccby.png" |
| 1007 |
"\n :alt: [CC-BY]") |
| 1008 |
self.assertEqual(node.get("rightsURI"), |
| 1009 |
"https://spdx.org/licenses/CC-BY-4.0.html") |
| 1010 |
|
| 1011 |
def testFootprint(self): |
| 1012 |
node = self.rec.xpath("//coverage/footprint")[0] |
| 1013 |
self.assertEqual(node.text, |
| 1014 |
"http://localhost:8080/funky/town/glonk/coverage") |
| 1015 |
self.assertEqual(node.get("ivo-id"), "ivo://ivoa.net/std/moc") |
| 1016 |
|
| 1017 |
def testUniqueTAPAux(self): |
| 1018 |
auxCaps = self.rec.xpath("capability[@standardID=" |
| 1019 |
"'ivo://ivoa.net/std/TAP#aux']") |
| 1020 |
self.assertEqual(len(auxCaps), 1) |
| 1021 |
|
| 1022 |
def testObscoreDecl(self): |
| 1023 |
self.assertEqual(len(self.rec.xpath("tableset/schema[name='ivoa']" |
| 1024 |
"/table[name='ivoa.obscore']")), 1) |
| 1025 |
|
| 1026 |
def testAuthor(self): |
| 1027 |
self.assertEqual(self.rec.xpath("curation/creator/name")[0].text, |
| 1028 |
"F.F.F") |
| 1029 |
|
| 1030 |
|
| 1031 |
class _UWSVORRecord(testhelpers.TestResource): |
| 1032 |
def make(self, ignored): |
| 1033 |
tree = testhelpers.getXMLTree( |
| 1034 |
builders.getVOResourceElement(base.resolveCrossId("data/cores#pc") |
| 1035 |
).render(), debug=False) |
| 1036 |
return tree.xpath("metadata/Resource")[0] |
| 1037 |
|
| 1038 |
_uwsVORRecord = _UWSVORRecord() |
| 1039 |
|
| 1040 |
|
| 1041 |
class UWSRecordTest(testhelpers.VerboseTest): |
| 1042 |
resources = [("rec", _uwsVORRecord)] |
| 1043 |
|
| 1044 |
def testFileDeclaration(self): |
| 1045 |
fileParam = self.rec.xpath("//param[name='UPLOAD']")[0] |
| 1046 |
dataType = fileParam.xpath("dataType")[0] |
| 1047 |
self.assertEqual(dataType.text, "char") |
| 1048 |
self.assertEqual(dataType.get("arraysize"), "*") |
| 1049 |
|
| 1050 |
def testVOSIInterfaceStandard(self): |
| 1051 |
capcap = self.rec.xpath( |
| 1052 |
"//capability[@standardID='ivo://ivoa.net/std/VOSI#capabilities']")[0] |
| 1053 |
self.assertEqual(capcap.xpath("interface")[0].get("role"), "std") |
| 1054 |
|
| 1055 |
|
| 1056 |
class _TableVORRecord(testhelpers.TestResource): |
| 1057 |
def make(self, ignored): |
| 1058 |
rd = base.parseFromString(rscdesc.RD, """<resource schema="data"> |
| 1059 |
<meta name="creationDate">2011-03-04T11:00:00</meta> |
| 1060 |
<meta name="title">My first DataCollection</meta> |
| 1061 |
<meta name="utype">http://example.edu/purefantasy</meta> |
| 1062 |
<meta name="description">Just so there's something here</meta> |
| 1063 |
<coverage> |
| 1064 |
<spectral>3.4213e-07 8.6328e-07</spectral> |
| 1065 |
<temporal>54992.06442 54992.35</temporal> |
| 1066 |
<temporal>54993.02 54993.42</temporal> |
| 1067 |
<temporal>1999-02-01T12:00:00 1999-03-15T00:00:00</temporal> |
| 1068 |
<spatial>6/20764,22787,38016,41738</spatial> |
| 1069 |
</coverage> |
| 1070 |
<meta name="coverage"> |
| 1071 |
<meta name="profile">Box ICRS 12 13 2 3</meta> |
| 1072 |
<meta name="waveband">X-Ray</meta> |
| 1073 |
<meta name="waveband">Radio</meta> |
| 1074 |
<meta name="regionOfRegard">3</meta> |
| 1075 |
</meta> |
| 1076 |
|
| 1077 |
<table id="punk" onDisk="True" adql="True"> |
| 1078 |
<column name="oink" utype="noises:animal.pig"/> |
| 1079 |
<column name="whereitsat" type="spoint" ucd="pos.eq;source"/> |
| 1080 |
<publish sets="ivo_managed,local" |
| 1081 |
services="//tap#run,data/pubtest#moribund"> |
| 1082 |
<meta name="mirrorURL">http://localhost:8080/tap</meta> |
| 1083 |
<meta name="mirrorURL">http://whereever.el.se/overview</meta> |
| 1084 |
</publish> |
| 1085 |
<meta name="utype">testing.table.name</meta> |
| 1086 |
<meta name="description">Some silly test data</meta> |
| 1087 |
<meta name="subject">testing</meta> |
| 1088 |
<meta name="subject">regressions</meta> |
| 1089 |
<meta name="format">audio/vorbis</meta> |
| 1090 |
<meta name="referenceURL">http://junk.g-vo.org</meta> |
| 1091 |
<meta name="servedBy" ivoId="ivo://org.g-vo.junk/tap" |
| 1092 |
>GAVO TAP service</meta> |
| 1093 |
<meta name="servedBy" ivoId="ivo://org.g-vo.junk/adql" |
| 1094 |
>GAVO ADQL Web</meta> |
| 1095 |
<meta name="continues" ivoId="ivo://org.g-vo.junk/zero" |
| 1096 |
>My Zeroeth Data Collection</meta> |
| 1097 |
</table></resource>""") |
| 1098 |
rd.sourceId = "funky/town" |
| 1099 |
td = rd.tables[0] |
| 1100 |
tree = testhelpers.getXMLTree( |
| 1101 |
builders.getVOResourceElement(td).render(), debug=False) |
| 1102 |
return tree.xpath("metadata/Resource")[0] |
| 1103 |
|
| 1104 |
_tableVORRecord = _TableVORRecord() |
| 1105 |
|
| 1106 |
|
| 1107 |
class TablePublicationRecordTest(testhelpers.VerboseTest): |
| 1108 |
# Tests for the registry record of a data publication |
| 1109 |
resources = [("tree", _tableVORRecord)] |
| 1110 |
|
| 1111 |
def testCreatedInherited(self): |
| 1112 |
self.assertEqual(self.tree.attrib["created"], "2011-03-04T11:00:00Z") |
| 1113 |
|
| 1114 |
def testConfigMetaPresent(self): |
| 1115 |
self.assertEqual( |
| 1116 |
self.tree.xpath("curation/contact/email")[0].text, |
| 1117 |
base.getMetaText(meta.CONFIG_META, "contact.email")) |
| 1118 |
|
| 1119 |
def testVORModelWorked(self): |
| 1120 |
self.assertEqual( |
| 1121 |
self.tree.xpath("content/description")[0].text, |
| 1122 |
"Some silly test data") |
| 1123 |
|
| 1124 |
def testVORModelWorked2(self): |
| 1125 |
self.assertEqual(self.tree.xpath("title")[0].text, |
| 1126 |
"My first DataCollection") |
| 1127 |
|
| 1128 |
def testAllSubjectsRendered(self): |
| 1129 |
self.assertEqual(len(self.tree.xpath("content/subject")), 2) |
| 1130 |
|
| 1131 |
def testCoverageProfileRendered(self): |
| 1132 |
self.assertEqual(self.tree.xpath( |
| 1133 |
"coverage/STCResourceProfile/AstroCoordArea/Box/Size/C1")[0].text, |
| 1134 |
"2.0") |
| 1135 |
|
| 1136 |
def testWavebandsPresent(self): |
| 1137 |
bands = self.tree.xpath("coverage/waveband") |
| 1138 |
self.assertEqual(len(bands), 2) |
| 1139 |
self.assertEqual(bands[0].text, "X-Ray") |
| 1140 |
|
| 1141 |
def testSpatialCoverage(self): |
| 1142 |
self.assertEqual( |
| 1143 |
self.tree.xpath("coverage/spatial")[0].text, |
| 1144 |
"6/20764,22787,38016,41738") |
| 1145 |
|
| 1146 |
def testTemporalCoverage(self): |
| 1147 |
covs = self.tree.xpath("coverage/temporal") |
| 1148 |
self.assertEqual(len(covs), 3) |
| 1149 |
self.assertEqual(covs[0].text, "54992.06442 54992.35") |
| 1150 |
self.assertEqual(covs[1].text, "54993.02 54993.42") |
| 1151 |
self.assertEqual(covs[2].text, "51210.5 51252") |
| 1152 |
|
| 1153 |
def testTemporalSpectral(self): |
| 1154 |
cov = self.tree.xpath("coverage/spectral")[0] |
| 1155 |
self.assertEqual(cov.text, "3.4213e-07 8.6328e-07") |
| 1156 |
|
| 1157 |
def testFootprintURL(self): |
| 1158 |
# tables can't have renderers on them, so they mustn't have |
| 1159 |
# a footprint URL |
| 1160 |
fp = self.tree.xpath("coverage/footprint") |
| 1161 |
self.assertFalse(fp, "Table has coverage/footprint??") |
| 1162 |
|
| 1163 |
def testRegionOfRegardPresent(self): |
| 1164 |
self.assertEqual(self.tree.xpath("coverage/regionOfRegard")[0].text, |
| 1165 |
"3") |
| 1166 |
|
| 1167 |
def testTablesetRendered(self): |
| 1168 |
self.assertEqual(self.tree.xpath("tableset/schema/table/name")[0].text, |
| 1169 |
"data.punk") |
| 1170 |
|
| 1171 |
def testSchemaUtypeInTableset(self): |
| 1172 |
self.assertEqual(self.tree.xpath("tableset/schema/utype")[0].text, |
| 1173 |
"http://example.edu/purefantasy") |
| 1174 |
|
| 1175 |
def testSchemaDescriptionInTableset(self): |
| 1176 |
self.assertEqual(self.tree.xpath("tableset/schema/description")[0].text, |
| 1177 |
"Just so there's something here") |
| 1178 |
|
| 1179 |
def testColumnMetaRendered(self): |
| 1180 |
self.assertEqual( |
| 1181 |
self.tree.xpath("tableset/schema/table/column")[0 |
| 1182 |
].xpath("name")[0].text, |
| 1183 |
"oink") |
| 1184 |
|
| 1185 |
def testRelationship(self): |
| 1186 |
par = self.tree.xpath("//relationship")[0] |
| 1187 |
self.assertEqual(par.xpath("relationshipType")[0].text, "IsServedBy") |
| 1188 |
self.assertEqual(par.xpath("relatedResource")[0].text, |
| 1189 |
"GAVO TAP service") |
| 1190 |
self.assertEqual(par.xpath("relatedResource")[0].attrib["ivo-id"], |
| 1191 |
"ivo://org.g-vo.junk/tap") |
| 1192 |
self.assertEqual(par.xpath("relatedResource")[1].attrib["ivo-id"], |
| 1193 |
"ivo://org.g-vo.junk/adql") |
| 1194 |
|
| 1195 |
def testContinues(self): |
| 1196 |
par = self.tree.xpath("//relationship")[1] |
| 1197 |
self.assertEqual(par.xpath("relationshipType")[0].text, "Continues") |
| 1198 |
self.assertEqual(par.xpath("relatedResource")[0].text, |
| 1199 |
"My Zeroeth Data Collection") |
| 1200 |
self.assertEqual(par.xpath("relatedResource")[0].attrib["ivo-id"], |
| 1201 |
"ivo://org.g-vo.junk/zero") |
| 1202 |
|
| 1203 |
def testUtype(self): |
| 1204 |
self.assertEqual(self.tree.xpath("tableset/schema/table/utype")[0].text, |
| 1205 |
"testing.table.name") |
| 1206 |
|
| 1207 |
def testTAPCapabilityPresent(self): |
| 1208 |
auxCaps = self.tree.xpath( |
| 1209 |
"capability[@standardID='ivo://ivoa.net/std/TAP#aux']") |
| 1210 |
auxCap = testhelpers.pickSingle(auxCaps) |
| 1211 |
self.assertEqual(auxCap.xpath("interface[@role='std']/accessURL")[0].text, |
| 1212 |
"http://localhost:8080/tap") |
| 1213 |
|
| 1214 |
def _testWebCapabilityPresent(self): |
| 1215 |
# that's currently not happening, as we don't create anonymous |
| 1216 |
# capabilites for data sets. Solution? |
| 1217 |
self.assertEqual(self.tree.xpath( |
| 1218 |
"//accessURL[.='http://localhost:8080/data/pubtest/moribund/form']")[0]. |
| 1219 |
get("use"), "full") |
| 1220 |
|
| 1221 |
def testVOSICapabilityCensored(self): |
| 1222 |
self.assertEqual(self.tree.xpath( |
| 1223 |
"//capability[@standardID='ivo://ivoa.net/std/VOSI#availability']"), |
| 1224 |
[]) |
| 1225 |
|
| 1226 |
def testMirrorURL(self): |
| 1227 |
mirrors = self.tree.xpath("//mirrorURL") |
| 1228 |
self.assertEqual( |
| 1229 |
testhelpers.pickSingle(mirrors).text, |
| 1230 |
"http://whereever.el.se/overview") |
| 1231 |
|
| 1232 |
def testXtypeRendered(self): |
| 1233 |
dt = self.tree.xpath("//column[name='whereitsat']/dataType")[0] |
| 1234 |
self.assertEqual(dt.get("extendedType"), "point") |
| 1235 |
self.assertEqual(dt.get("arraysize"), "2") |
| 1236 |
|
| 1237 |
|
| 1238 |
class _DataGetRecordRes(testhelpers.TestResource): |
| 1239 |
def make(self, ignored): |
| 1240 |
rd = base.parseFromString(rscdesc.RD, """<resource schema="data"> |
| 1241 |
<meta name="creationDate">2011-03-04T11:00:00</meta> |
| 1242 |
<meta name="title">My second DataCollection</meta> |
| 1243 |
<meta name="utype">ivo://some.mad.stuff/datamodel#schema-2.0</meta> |
| 1244 |
<meta name="creator.name">M.Y. Logo</meta> |
| 1245 |
<meta name="creator.logo">/static/mylogo.png</meta> |
| 1246 |
<table id="honk" onDisk="True" temporary="True" adql="True"> |
| 1247 |
<column name="col1" description="column from honk"/> |
| 1248 |
</table> |
| 1249 |
<table id="funk" onDisk="True" temporary="True" adql="True"> |
| 1250 |
<column name="oink" utype="noises:animal.pig"/> |
| 1251 |
<column name="wherep" type="spoint" ucd="pos.eq;source"/> |
| 1252 |
</table> |
| 1253 |
<data id="punk"> |
| 1254 |
<register sets="ivo_managed,local"/> |
| 1255 |
<meta name="description">Some silly test data</meta> |
| 1256 |
<meta name="subject">testing</meta> |
| 1257 |
<meta name="subject">regressions</meta> |
| 1258 |
<meta name="coverage.profile">Box ICRS 12 13 2 3</meta> |
| 1259 |
<meta name="format">audio/vorbis</meta> |
| 1260 |
<meta name="referenceURL">http://junk.g-vo.org</meta> |
| 1261 |
<make table="honk"/> |
| 1262 |
<make table="funk"/> |
| 1263 |
</data></resource>""") |
| 1264 |
rd.sourceId = "funky/town" |
| 1265 |
return getGetRecordResponse(rd.dds[0]) |
| 1266 |
|
| 1267 |
_dataGetRecordRes = _DataGetRecordRes() |
| 1268 |
|
| 1269 |
|
| 1270 |
class DataGetRecordTest(testhelpers.VerboseTest, testtricks.XSDTestMixin): |
| 1271 |
resources = [("srcAndTree", _dataGetRecordRes)] |
| 1272 |
|
| 1273 |
def testIsValid(self): |
| 1274 |
self.assertValidates(self.srcAndTree[0]) |
| 1275 |
|
| 1276 |
def testType(self): |
| 1277 |
self.assertEqual(self.srcAndTree[1].xpath("//Resource")[0].get( |
| 1278 |
"{http://www.w3.org/2001/XMLSchema-instance}type"), |
| 1279 |
"vs:CatalogResource") |
| 1280 |
|
| 1281 |
def testAutoTAPCapabilityPresent(self): |
| 1282 |
self.assertEqual(self.srcAndTree[1].xpath( |
| 1283 |
"//capability[@standardID='ivo://ivoa.net/std/TAP#aux']" |
| 1284 |
"/interface[@role='std']/accessURL")[0].text, |
| 1285 |
"http://localhost:8080/tap") |
| 1286 |
|
| 1287 |
def testReducedCapabilityElement(self): |
| 1288 |
capChildren = self.srcAndTree[1].xpath("//capability/*") |
| 1289 |
self.assertEqual(len(capChildren), 1) |
| 1290 |
|
| 1291 |
def testUtypeDeclared(self): |
| 1292 |
utypeChildren = self.srcAndTree[1].xpath("//schema/utype") |
| 1293 |
self.assertEqual(testhelpers.pickSingle(utypeChildren).text, |
| 1294 |
"ivo://some.mad.stuff/datamodel#schema-2.0") |
| 1295 |
|
| 1296 |
def testTablesetPresent(self): |
| 1297 |
tables = self.srcAndTree[1].xpath( |
| 1298 |
"//tableset/schema/table") |
| 1299 |
self.assertEqual( |
| 1300 |
set([ |
| 1301 |
tables[0].xpath("name")[0].text, |
| 1302 |
tables[1].xpath("name")[0].text]), |
| 1303 |
set(["funk", "honk"])) |
| 1304 |
|
| 1305 |
|
| 1306 |
class _BiblinkRecordRes(testhelpers.TestResource): |
| 1307 |
def make(self, ignored): |
| 1308 |
tree = testhelpers.getXMLTree( |
| 1309 |
builders.getVOResourceElement( |
| 1310 |
base.resolveCrossId("//biblinks#links")).render(), debug=False) |
| 1311 |
return tree.xpath("metadata/Resource")[0] |
| 1312 |
|
| 1313 |
class BiblinkRecordTest(testhelpers.VerboseTest): |
| 1314 |
resources = [("tree", _BiblinkRecordRes())] |
| 1315 |
|
| 1316 |
def testCapability(self): |
| 1317 |
caps = self.tree.xpath("//capability[@standardID=" |
| 1318 |
"'ivo://ivoa.net/std/BibVO#biblink-harvest-1.0']") |
| 1319 |
self.assertEqual( |
| 1320 |
testhelpers.pickSingle(caps).xpath("interface")[0].get( |
| 1321 |
"{http://www.w3.org/2001/XMLSchema-instance}type"), |
| 1322 |
"vs:ParamHTTP") |
| 1323 |
|
| 1324 |
|
| 1325 |
class _VOEventRecord(testhelpers.TestResource): |
| 1326 |
def make(self, deps): |
| 1327 |
rd = base.parseFromString(rscdesc.RD, """ |
| 1328 |
<resource schema="data"> |
| 1329 |
<meta> |
| 1330 |
shortName: chime_voe |
| 1331 |
creationDate: 2025-04-02T07:00:00Z |
| 1332 |
title: CHIME/FRB VOEvent |
| 1333 |
subject:time-domain-astronomy |
| 1334 |
description: Test. |
| 1335 |
date: 2040-01-01T00:00:00 |
| 1336 |
date.role: updated |
| 1337 |
</meta> |
| 1338 |
|
| 1339 |
<service id="s" allowed="voevent"> |
| 1340 |
<nullCore/> |
| 1341 |
<publish render="voevent" sets="ivo_managed"> |
| 1342 |
<meta name="accessURL">x-vtp://chimefrb.physics.mcgill.ca</meta> |
| 1343 |
<meta name="interfaceType">VTPInterface</meta> |
| 1344 |
</publish> |
| 1345 |
</service> |
| 1346 |
</resource>""") |
| 1347 |
rd.sourceId = "voevent/test" |
| 1348 |
return getGetRecordResponse(rd.getById("s")) |
| 1349 |
|
| 1350 |
|
| 1351 |
class VOEventRecordTest(testhelpers.VerboseTest, testhelpers.XSDTestMixin): |
| 1352 |
|
| 1353 |
resources = [("textAndTree", _VOEventRecord())] |
| 1354 |
|
| 1355 |
def testValid(self): |
| 1356 |
self.assertValidates(self.textAndTree[0]) |
| 1357 |
|
| 1358 |
def testVOEventInterface(self): |
| 1359 |
cap = testhelpers.pickSingle(self.textAndTree[1].xpath("//capability[" |
| 1360 |
"@standardID='ivo://ivoa.net/std/voevent']")) |
| 1361 |
self.assertEqual(cap.get("standardID"), "ivo://ivoa.net/std/voevent") |
| 1362 |
intf = testhelpers.pickSingle( |
| 1363 |
cap.xpath("interface")) |
| 1364 |
self.assertEqual(intf.get("role"), "std") |
| 1365 |
self.assertEqual( |
| 1366 |
intf.get("standardID"), "ivo://ivoa.net/std/voevent#acc-vtp") |
| 1367 |
self.assertEqual( |
| 1368 |
intf.get("{http://www.w3.org/2001/XMLSchema-instance}type"), |
| 1369 |
"voe:StreamEndpoint") |
| 1370 |
self.assertEqual( |
| 1371 |
testhelpers.pickSingle(intf.xpath("accessURL")).text, |
| 1372 |
"x-vtp://chimefrb.physics.mcgill.ca") |
| 1373 |
|
| 1374 |
def testCapabilitiesInterface(self): |
| 1375 |
cap = testhelpers.pickSingle(self.textAndTree[1].xpath("//capability[" |
| 1376 |
"@standardID='ivo://ivoa.net/std/VOSI#capabilities']")) |
| 1377 |
intf = testhelpers.pickSingle( |
| 1378 |
cap.xpath("interface")) |
| 1379 |
self.assertEqual( |
| 1380 |
testhelpers.pickSingle(intf.xpath("accessURL")).text, |
| 1381 |
"http://localhost:8080/voevent/test/s/capabilities") |
| 1382 |
|
| 1383 |
|
| 1384 |
class SpecialMetaRenderTest(testhelpers.VerboseTest): |
| 1385 |
resources = [("srcAndTree", _dataGetRecordRes)] |
| 1386 |
|
| 1387 |
def testLogoExpanded(self): |
| 1388 |
self.assertEqual( |
| 1389 |
self.srcAndTree[1].uniqueXpath("//creator/logo").text, |
| 1390 |
"http://localhost:8080/static/mylogo.png") |
| 1391 |
|
| 1392 |
|
| 1393 |
_NMDB_SVC_LIT = """ |
| 1394 |
<resource schema="gvo"> |
| 1395 |
<meta name="title">NMDB: Real-time Measurements</meta> |
| 1396 |
<meta name="description">NMDB serves the data</meta> |
| 1397 |
<meta name="creationDate">2015-09-17T11:45:00</meta> |
| 1398 |
<meta name="subject">Cosmic ray</meta> |
| 1399 |
<meta name="creator.name">Steigies, C.</meta> |
| 1400 |
<meta name="creator"> |
| 1401 |
<meta name="name">Wilbanks, J. |
| 1402 |
<meta name="altIdentifier">http://orcid.org/0000-0002-4510-0385</meta> |
| 1403 |
</meta> |
| 1404 |
</meta> |
| 1405 |
<meta name="contributor"> |
| 1406 |
<meta name="altIdentifier">http://orcid.org/blabla</meta>Joe Cool |
| 1407 |
</meta> |
| 1408 |
<service id="run" allowed="external"> |
| 1409 |
<nullCore/> |
| 1410 |
<meta name="shortName">nmdb web</meta> |
| 1411 |
<publish render="external" sets="ivo_managed"> |
| 1412 |
<meta |
| 1413 |
name="accessURL">http://nest.nmdb.eu</meta> |
| 1414 |
</publish> |
| 1415 |
</service> |
| 1416 |
</resource> |
| 1417 |
""" |
| 1418 |
|
| 1419 |
|
| 1420 |
class _ExternalRecordRes(testhelpers.TestResource): |
| 1421 |
def make(self, ignored): |
| 1422 |
rd = base.parseFromString(rscdesc.RD, _NMDB_SVC_LIT) |
| 1423 |
rd.sourceId = "funky/town" |
| 1424 |
return getGetRecordResponse(rd.services[0]) |
| 1425 |
|
| 1426 |
|
| 1427 |
class ExternalRecordTest(testhelpers.VerboseTest, testtricks.XSDTestMixin): |
| 1428 |
resources = [("srcAndTree", _ExternalRecordRes())] |
| 1429 |
|
| 1430 |
def testWebInterface(self): |
| 1431 |
intf = self.srcAndTree[1].xpath("//capability/interface")[0] |
| 1432 |
self.assertEqual(intf.xpath("accessURL")[0].text, "http://nest.nmdb.eu") |
| 1433 |
|
| 1434 |
def testNoTablesEndpoint(self): |
| 1435 |
self.assertEqual( |
| 1436 |
list(self.srcAndTree[1].xpath("//capability/@standardID")), |
| 1437 |
['ivo://ivoa.net/std/VOSI#capabilities']) |
| 1438 |
|
| 1439 |
def testValid(self): |
| 1440 |
self.assertValidates(self.srcAndTree[0]) |
| 1441 |
|
| 1442 |
def testCreatorAltIdentifier(self): |
| 1443 |
self.assertEqual( |
| 1444 |
self.srcAndTree[1].xpath("//creator/name/@altIdentifier")[0], |
| 1445 |
"http://orcid.org/0000-0002-4510-0385") |
| 1446 |
|
| 1447 |
def testContributorAltIdentifier(self): |
| 1448 |
self.assertEqual( |
| 1449 |
self.srcAndTree[1].xpath("//contributor/@altIdentifier")[0], |
| 1450 |
"http://orcid.org/blabla") |
| 1451 |
|
| 1452 |
|
| 1453 |
class ForeignIdentifiersRejectedTest(testhelpers.VerboseTest): |
| 1454 |
def testExternalIdsSuppressed(self): |
| 1455 |
svcMat = re.search("(?s)<service.*?</service>", _NMDB_SVC_LIT) |
| 1456 |
foreignService = re.sub("<service.*?>", |
| 1457 |
'<service><meta name="identifier">ivo://ivoa.net/foreign</meta>', |
| 1458 |
svcMat.group(0)) |
| 1459 |
rdLit = _NMDB_SVC_LIT[:svcMat.end() |
| 1460 |
]+foreignService+_NMDB_SVC_LIT[svcMat.end():] |
| 1461 |
rd = base.parseFromString(rscdesc.RD, rdLit) |
| 1462 |
rd.sourceId = "funky/town" |
| 1463 |
|
| 1464 |
grammar = base.makeStruct(publication.RDRscRecGrammar) |
| 1465 |
res = [p for (d, p) in grammar.parse(rd) if d=='resources'] |
| 1466 |
self.assertEqual( |
| 1467 |
testhelpers.pickSingle(res)["ivoid"], |
| 1468 |
'ivo://x-testing/funky/town/run') |
| 1469 |
|
| 1470 |
def testXUnregisteredForLocalIsOk(self): |
| 1471 |
base.caches.clearForName("data/test") |
| 1472 |
# test.rd doesn't have any ivo_managed resources (and must not |
| 1473 |
# grow any or this will break) |
| 1474 |
try: |
| 1475 |
with testhelpers.tempConfig(("ivoa", "authority", "x-unregistred")): |
| 1476 |
publication.updateServiceList([base.resolveCrossId("data/test")]) |
| 1477 |
finally: |
| 1478 |
base.caches.clearForName("data/test") |
| 1479 |
publication.updateServiceList( |
| 1480 |
[base.resolveCrossId("data/test")], |
| 1481 |
unpublish=True) |
| 1482 |
|
| 1483 |
def testXUnregisteredFails(self): |
| 1484 |
base.caches.clearForName("data/seeded") |
| 1485 |
with testhelpers.tempConfig(("ivoa", "authority", "x-unregistred")): |
| 1486 |
self.assertRaisesWithMsg(base.ReportableError, |
| 1487 |
"Resource data/seeded#hooray uses the authority" |
| 1488 |
" x-unregistered; this is not permitted.", |
| 1489 |
publication.updateServiceList, |
| 1490 |
([base.resolveCrossId("data/seeded")],)) |
| 1491 |
base.caches.clearForName("data/seeded") |
| 1492 |
|
| 1493 |
|
| 1494 |
class _ProductServiceRecord(testhelpers.TestResource): |
| 1495 |
def make(self, ignored): |
| 1496 |
return getGetRecordResponse(api.getRD("//products").getById("p")) |
| 1497 |
|
| 1498 |
|
| 1499 |
class ProductServiceTest(testhelpers.VerboseTest): |
| 1500 |
resources = [("srcAndTree", _ProductServiceRecord())] |
| 1501 |
|
| 1502 |
def testIdentifier(self): |
| 1503 |
self.assertEqual( |
| 1504 |
self.srcAndTree[1].xpath("//identifier")[0].text, |
| 1505 |
"ivo://x-testing/~") |
| 1506 |
|
| 1507 |
def testCreationDate(self): |
| 1508 |
self.assertEqual( |
| 1509 |
self.srcAndTree[1].xpath("//Resource")[0].get("created"), |
| 1510 |
base.getMetaText(base.MetaMixin(), "authority.creationDate")+"Z") |
| 1511 |
|
| 1512 |
def testDescriptionExpanded(self): |
| 1513 |
self.assertTrue("datasets held at\nUnittest Suite" in |
| 1514 |
self.srcAndTree[1].xpath("//content/description")[0].text, |
| 1515 |
"Product service description doesn't contain site name?") |
| 1516 |
|
| 1517 |
def testGetCapability(self): |
| 1518 |
el = self.srcAndTree[1].xpath( |
| 1519 |
"//interface[@xsi:type='vr:WebBrowser']/accessURL", |
| 1520 |
namespaces={"xsi": utils.getPrefixInfo("xsi")[0]})[0] |
| 1521 |
self.assertEqual(el.text, "http://localhost:8080/getproduct") |
| 1522 |
self.assertEqual(el.get("use"), "base") |
| 1523 |
|
| 1524 |
def testDLCapability(self): |
| 1525 |
el = self.srcAndTree[1].xpath( |
| 1526 |
"//capability[@standardID='ivo://ivoa.net/std/DataLink#links-1.1']")[0] |
| 1527 |
self.assertEqual(el.xpath("interface/accessURL")[0].text, |
| 1528 |
"http://localhost:8080/__system__/products/dl/dlmeta") |
| 1529 |
self.assertEqual(el.xpath("interface")[0].get("role"), |
| 1530 |
"std"), |
| 1531 |
self.assertEqual(el.xpath("interface/param[name='ID']")[0].get("std"), |
| 1532 |
"true") |
| 1533 |
|
| 1534 |
|
| 1535 |
class _WithDatalinkRecord(testhelpers.TestResource): |
| 1536 |
def make(self, ignored): |
| 1537 |
return getGetRecordResponse(api.resolveCrossId("data/ssatest#c")) |
| 1538 |
|
| 1539 |
|
| 1540 |
class WithDatalinkTest(testhelpers.VerboseTest): |
| 1541 |
resources = [("srcAndTree", _WithDatalinkRecord())] |
| 1542 |
|
| 1543 |
def testSODACapPresent(self): |
| 1544 |
sodaCaps = self.srcAndTree[1].xpath( |
| 1545 |
"//capability[@standardID='ivo://ivoa.net/std/SODA#sync-1.0']") |
| 1546 |
self.assertEqual(len(sodaCaps), 1) |
| 1547 |
|
| 1548 |
def testSODAAccessURL(self): |
| 1549 |
dlURLs = self.srcAndTree[1].xpath( |
| 1550 |
"//capability[@standardID='ivo://ivoa.net/std/SODA#sync-1.0']" |
| 1551 |
"/interface/accessURL") |
| 1552 |
self.assertTrue( |
| 1553 |
testhelpers.pickSingle(dlURLs).text.endswith("/data/ssatest/dl/dlget")) |
| 1554 |
|
| 1555 |
def testSODAParameters(self): |
| 1556 |
parentPath = ("//capability[@standardID=" |
| 1557 |
"'ivo://ivoa.net/std/SODA#sync-1.0']/interface") |
| 1558 |
intfEl = self.srcAndTree[1].xpath(parentPath)[0] |
| 1559 |
# can't compute them without data, so make sure we don't |
| 1560 |
# invent something. |
| 1561 |
self.assertEqual(len(intfEl.xpath("param")), 0) |
| 1562 |
|
| 1563 |
def testDatalinkCapPresent(self): |
| 1564 |
dlCaps = self.srcAndTree[1].xpath( |
| 1565 |
"//capability[@standardID='ivo://ivoa.net/std/DataLink#links-1.1']") |
| 1566 |
self.assertEqual(len(dlCaps), 1) |
| 1567 |
|
| 1568 |
def testDatalinkInterfaceDeclared(self): |
| 1569 |
dlIntfs = self.srcAndTree[1].xpath( |
| 1570 |
"//capability[@standardID='ivo://ivoa.net/std/DataLink#links-1.1']" |
| 1571 |
"/interface") |
| 1572 |
self.assertEqual(len(dlIntfs), 1) |
| 1573 |
self.assertEqual(dlIntfs[0].get( |
| 1574 |
"{http://www.w3.org/2001/XMLSchema-instance}type"), 'vs:ParamHTTP') |
| 1575 |
|
| 1576 |
def testDatalinkAccessURL(self): |
| 1577 |
dlURLs = self.srcAndTree[1].xpath( |
| 1578 |
"//capability[@standardID='ivo://ivoa.net/std/DataLink#links-1.1']" |
| 1579 |
"/interface/accessURL") |
| 1580 |
self.assertTrue( |
| 1581 |
testhelpers.pickSingle(dlURLs).text.endswith("/data/ssatest/dl/dlmeta")) |
| 1582 |
|
| 1583 |
def testDatalinkResultType(self): |
| 1584 |
dlTypes = self.srcAndTree[1].xpath( |
| 1585 |
"//capability[@standardID='ivo://ivoa.net/std/DataLink#links-1.1']" |
| 1586 |
"/interface/resultType") |
| 1587 |
self.assertEqual(testhelpers.pickSingle(dlTypes).text, |
| 1588 |
"application/x-votable+xml;content=datalink") |
| 1589 |
|
| 1590 |
def testDatalinkParameters(self): |
| 1591 |
dlParams = self.srcAndTree[1].xpath( |
| 1592 |
"//capability[@standardID='ivo://ivoa.net/std/DataLink#links-1.1']" |
| 1593 |
"/interface/param[@std='true']") |
| 1594 |
self.assertEqual(len(dlParams), 4) |
| 1595 |
self.assertEqual(dlParams[0][0].tag, "name") |
| 1596 |
self.assertEqual(dlParams[0][0].text, "ID") |
| 1597 |
self.assertEqual(dlParams[0][2].tag, "ucd") |
| 1598 |
self.assertEqual(dlParams[0][2].text, "meta.id;meta.main") |
| 1599 |
|
| 1600 |
|
| 1601 |
_PUBLISHED_RD_LIT_FRAME = f"""<resource schema="test"> |
| 1602 |
{tresc.MINIMAL_META} |
| 1603 |
|
| 1604 |
<meta name="!creator">Zwicky, F.; Schmidt, R.</meta> |
| 1605 |
|
| 1606 |
<publish sets="local,ivo_managed"/> |
| 1607 |
|
| 1608 |
{{}} |
| 1609 |
|
| 1610 |
</resource>""" |
| 1611 |
|
| 1612 |
_PUBLISHED_RD_LIT_CONTENT = """ |
| 1613 |
<table id="ispub" onDisk="True" adql="True"> |
| 1614 |
<column name="col1"/> |
| 1615 |
</table> |
| 1616 |
|
| 1617 |
<table id="nonpub" onDisk="True"> |
| 1618 |
<column name="col2"/> |
| 1619 |
</table> |
| 1620 |
|
| 1621 |
<table id="hidden" onDisk="True" adql="hidden"> |
| 1622 |
<column name="col3"/> |
| 1623 |
</table> |
| 1624 |
|
| 1625 |
<service id="svc1" allowed="form,scs.xml"> |
| 1626 |
<meta> |
| 1627 |
shortName: svc1 |
| 1628 |
testQuery.ra: 10 |
| 1629 |
testQuery.dec: 10 |
| 1630 |
testQuery.sr: 1 |
| 1631 |
</meta> |
| 1632 |
<dbCore queriedTable="ispub"/> |
| 1633 |
</service> |
| 1634 |
|
| 1635 |
<service id="svc2" allowed="hips"> |
| 1636 |
<meta name="shortName">svc2</meta> |
| 1637 |
<meta name="description">The second service</meta> |
| 1638 |
<property name="staticData">data</property> |
| 1639 |
<nullCore/> |
| 1640 |
</service> |
| 1641 |
""" |
| 1642 |
|
| 1643 |
|
| 1644 |
_PUBLISHED_RD_LIT = _PUBLISHED_RD_LIT_FRAME.format(_PUBLISHED_RD_LIT_CONTENT) |
| 1645 |
|
| 1646 |
|
| 1647 |
class _RDPubRecs(testhelpers.TestResource): |
| 1648 |
def make(self, ignored): |
| 1649 |
rd = base.parseFromString(api.RD, _PUBLISHED_RD_LIT) |
| 1650 |
rd.sourceId = "test/fake" |
| 1651 |
grammar = base.makeStruct(publication.RDRscRecGrammar) |
| 1652 |
recs = {} |
| 1653 |
for dest, row in grammar.parse(rd): |
| 1654 |
recs.setdefault(dest, []).append(row) |
| 1655 |
return recs |
| 1656 |
|
| 1657 |
|
| 1658 |
class RDPubDBTest(testhelpers.VerboseTest): |
| 1659 |
resources = [("recs", _RDPubRecs())] |
| 1660 |
|
| 1661 |
def testResource(self): |
| 1662 |
rec = testhelpers.pickSingle(self.recs["resources"]) |
| 1663 |
self.assertEqual(rec["ivoid"], 'ivo://x-testing/test/fake') |
| 1664 |
self.assertEqual(rec["shortName"], 'test/fake') |
| 1665 |
self.assertEqual(rec["resId"], 'WHOLE_RD') |
| 1666 |
self.assertEqual(rec["authors"], 'Zwicky, F.; Schmidt, R.') |
| 1667 |
self.assertEqual(rec["dateUpdated"], None) |
| 1668 |
|
| 1669 |
def testSets(self): |
| 1670 |
recs = self.recs["sets"] |
| 1671 |
self.assertEqual(len(recs), 2) |
| 1672 |
self.assertEqual(recs[0]["ivoid"], 'ivo://x-testing/test/fake') |
| 1673 |
self.assertEqual(recs[1]["sourceRD"], 'test/fake') |
| 1674 |
self.assertEqual(recs[1]["renderer"], 'rcdisplay') |
| 1675 |
self.assertEqual({r["setName"] for r in recs}, {'ivo_managed', 'local'}) |
| 1676 |
|
| 1677 |
def testSubjects(self): |
| 1678 |
rec = testhelpers.pickSingle(self.recs["subjects"]) |
| 1679 |
self.assertEqual(rec["sourceRD"], 'test/fake') |
| 1680 |
self.assertEqual(rec["subject"], 'a') |
| 1681 |
|
| 1682 |
def testAuthors(self): |
| 1683 |
recs = self.recs["authors"] |
| 1684 |
self.assertEqual(len(recs), 2) |
| 1685 |
self.assertEqual(recs[0]["author"], "Zwicky, F.") |
| 1686 |
self.assertEqual(recs[0]["sourceRD"], 'test/fake') |
| 1687 |
|
| 1688 |
def testInterface(self): |
| 1689 |
rec = testhelpers.pickSingle(self.recs["interfaces"]) |
| 1690 |
self.assertEqual(rec["sourceRD"], 'test/fake') |
| 1691 |
self.assertEqual(rec["resId"], 'WHOLE_RD') |
| 1692 |
self.assertEqual(rec['accessURL'], |
| 1693 |
'http://localhost:8080/browse/test/fake') |
| 1694 |
self.assertEqual(rec['referenceURL'], |
| 1695 |
'http://localhost:8080/browse/test/fake') |
| 1696 |
|
| 1697 |
|
| 1698 |
class _RDVOR(testhelpers.TestResource): |
| 1699 |
def make(self, ignored): |
| 1700 |
rd = base.parseFromString(api.RD, _PUBLISHED_RD_LIT) |
| 1701 |
rd.sourceId = "test/fake" |
| 1702 |
return getGetRecordResponse(rd) |
| 1703 |
|
| 1704 |
|
| 1705 |
class RDPubVORTest(testhelpers.VerboseTest, testtricks.XSDTestMixin): |
| 1706 |
resources = [("textAndTree", _RDVOR())] |
| 1707 |
|
| 1708 |
def testValid(self): |
| 1709 |
self.assertValidates(self.textAndTree[0]) |
| 1710 |
|
| 1711 |
def testIdentifier(self): |
| 1712 |
self.assertEqual( |
| 1713 |
testhelpers.pickSingle( |
| 1714 |
self.textAndTree[1].xpath("GetRecord/record/metadata/" |
| 1715 |
"Resource/identifier")).text, |
| 1716 |
"ivo://x-testing/test/fake") |
| 1717 |
|
| 1718 |
def testSCSCap(self): |
| 1719 |
cap = testhelpers.pickSingle( |
| 1720 |
self.textAndTree[1].xpath( |
| 1721 |
"//capability[@standardID='ivo://ivoa.net/std/conesearch']")) |
| 1722 |
self.assertEqual(testhelpers.pickSingle( |
| 1723 |
cap.xpath("interface/accessURL")).text, |
| 1724 |
"http://localhost:8080/test/fake/svc1/scs.xml?") |
| 1725 |
|
| 1726 |
def testBrowserCap(self): |
| 1727 |
cap = testhelpers.pickSingle( |
| 1728 |
self.textAndTree[1].xpath( |
| 1729 |
"//capability[interface/@xsi:type='vr:WebBrowser']", |
| 1730 |
namespaces={"xsi": utils.getPrefixInfo("xsi")[0]})) |
| 1731 |
self.assertEqual(testhelpers.pickSingle( |
| 1732 |
cap.xpath("interface/accessURL")).text, |
| 1733 |
"http://localhost:8080/test/fake/svc1/form") |
| 1734 |
|
| 1735 |
def testHIPSCap(self): |
| 1736 |
cap = testhelpers.pickSingle( |
| 1737 |
self.textAndTree[1].xpath( |
| 1738 |
"//capability[@standardID='ivo://ivoa.net/std/hips#hips-1.0']")) |
| 1739 |
self.assertEqual( |
| 1740 |
testhelpers.pickSingle(cap.xpath("interface/accessURL")).text, |
| 1741 |
"http://localhost:8080/test/fake/svc2/hips") |
| 1742 |
self.assertEqual( |
| 1743 |
testhelpers.pickSingle(cap.xpath("description")).text, |
| 1744 |
"The second service") |
| 1745 |
|
| 1746 |
def testTAPaux(self): |
| 1747 |
cap = testhelpers.pickSingle( |
| 1748 |
self.textAndTree[1].xpath( |
| 1749 |
"//capability[@standardID='ivo://ivoa.net/std/TAP#aux']")) |
| 1750 |
self.assertEqual(testhelpers.pickSingle( |
| 1751 |
cap.xpath("interface/accessURL")).text, |
| 1752 |
"http://localhost:8080/tap") |
| 1753 |
|
| 1754 |
def testTableset(self): |
| 1755 |
ts = testhelpers.pickSingle(self.textAndTree[1].xpath("//tableset")) |
| 1756 |
self.assertEqual( |
| 1757 |
testhelpers.pickSingle(ts.xpath("schema/table/name")).text, |
| 1758 |
"test.ispub") |
| 1759 |
|
| 1760 |
|
| 1761 |
class _ExoticRDVOR(testhelpers.TestResource): |
| 1762 |
def make(self, ignored): |
| 1763 |
rd = base.parseFromString(api.RD, _PUBLISHED_RD_LIT_FRAME.format( |
| 1764 |
""" |
| 1765 |
<table id="something"> |
| 1766 |
<column name="other"/> |
| 1767 |
</table> |
| 1768 |
<service id="s" allowed="form,static"> |
| 1769 |
<property name="publishedRenderers">form, capabilities</property> |
| 1770 |
<dbCore queriedTable="something"/> |
| 1771 |
</service> |
| 1772 |
""")) |
| 1773 |
rd.sourceId = "test/fake" |
| 1774 |
return getGetRecordResponse(rd) |
| 1775 |
|
| 1776 |
|
| 1777 |
class ExoticRDPubVORTest(testhelpers.VerboseTest): |
| 1778 |
resources = [("textAndTree", _ExoticRDVOR())] |
| 1779 |
|
| 1780 |
def testPublishedRenderersHonored(self): |
| 1781 |
caps = [c.get("standardID") |
| 1782 |
for c in self.textAndTree[1].xpath("//capability")] |
| 1783 |
self.assertEqual(caps, [None, 'ivo://ivoa.net/std/VOSI#capabilities']) |
| 1784 |
|
| 1785 |
def testNoTAPcap(self): |
| 1786 |
# no ADQL table, no aux cap |
| 1787 |
self.assertEqual(len(self.textAndTree[1].xpath( |
| 1788 |
"//capability[@standardID='ivo://ivoa.net/std/TAP#aux']")), 0) |
| 1789 |
|
| 1790 |
def testNoTableset(self): |
| 1791 |
self.assertEqual(len(self.textAndTree[1].xpath("//tableset")), 0) |
| 1792 |
|
| 1793 |
|
| 1794 |
# minimal meta for successful RR generation without a (working) RD |
| 1795 |
_fakeMeta ="""<meta name="identifier">ivo://gavo.testing</meta> |
| 1796 |
<meta name="datetimeUpdated">2000-00-00T00:00:00</meta> |
| 1797 |
<meta name="referenceURL">http://faked</meta> |
| 1798 |
<meta name="recTimestamp">2000-00-00T00:00:00</meta> |
| 1799 |
<meta name="sets">ivo_managed</meta>""" |
| 1800 |
|
| 1801 |
|
| 1802 |
class RelatedTest(testhelpers.VerboseTest): |
| 1803 |
# Tests for everything to do with the "related" meta |
| 1804 |
def _getTreeFor(self, dataBody): |
| 1805 |
rd = base.parseFromString(rscdesc.RD, |
| 1806 |
"""<resource schema="test"><table id="foo">%s%s</table></resource>"""%( |
| 1807 |
dataBody, _fakeMeta)) |
| 1808 |
td = rd.tables[0] |
| 1809 |
return testhelpers.getXMLTree( |
| 1810 |
builders.getVOResourceElement(td).render(), debug=False) |
| 1811 |
|
| 1812 |
def testNoRelations(self): |
| 1813 |
tree = self._getTreeFor("") |
| 1814 |
self.assertFalse(tree.xpath("metadata/Resource/content/relationship")) |
| 1815 |
|
| 1816 |
def testSimpleRelation(self): |
| 1817 |
tree = self._getTreeFor( |
| 1818 |
'<meta name="servedBy" ivoId="ivo://glub">The Glub Data</meta>') |
| 1819 |
relEl = tree.xpath("metadata/Resource/content/relationship") |
| 1820 |
self.assertTrue(relEl) |
| 1821 |
self.assertEqual(relEl[0].xpath("relationshipType")[0].text, |
| 1822 |
"IsServedBy") |
| 1823 |
self.assertEqual(relEl[0].xpath("relatedResource")[0].text, |
| 1824 |
"The Glub Data") |
| 1825 |
self.assertEqual(relEl[0].xpath("relatedResource")[0].attrib["ivo-id"], |
| 1826 |
"ivo://glub") |
| 1827 |
|
| 1828 |
def testRelationAltIdentifer(self): |
| 1829 |
tree = self._getTreeFor( |
| 1830 |
'<meta name="isSupplementTo" altIdentifier="doi:10.2030/glub">' |
| 1831 |
'The Glub Data</meta>') |
| 1832 |
relEl = tree.xpath("metadata/Resource/content/relationship") |
| 1833 |
self.assertTrue(relEl) |
| 1834 |
self.assertEqual(relEl[0].xpath("relationshipType")[0].text, |
| 1835 |
"IsSupplementTo") |
| 1836 |
self.assertEqual(relEl[0].xpath("relatedResource")[0].text, |
| 1837 |
"The Glub Data") |
| 1838 |
self.assertEqual(relEl[0].xpath("relatedResource" |
| 1839 |
)[0].attrib["altIdentifier"], "doi:10.2030/glub") |
| 1840 |
|
| 1841 |
def testReset(self): |
| 1842 |
self._getTreeFor( |
| 1843 |
'<meta name="servedBy" ivoId="ivo://glub">The Glub Data</meta>') |
| 1844 |
tree1 = self._getTreeFor( |
| 1845 |
'<meta name="servedBy" ivoId="ivo://frob">The Frob Data</meta>') |
| 1846 |
# we once had a bug where the builder didn't get reset, and due to |
| 1847 |
# bad arch I think it'll come again. Therefore this test -- it |
| 1848 |
# will catch this. |
| 1849 |
self.assertEqual(len(tree1.xpath( |
| 1850 |
"metadata/Resource/content/relationship/relatedResource")), 1) |
| 1851 |
|
| 1852 |
def testRegistration(self): |
| 1853 |
try: |
| 1854 |
tree = self._getTreeFor( |
| 1855 |
'<register services="//adql#query"/>') |
| 1856 |
relEl = tree.xpath("metadata/Resource/content/relationship") |
| 1857 |
self.assertTrue(relEl) |
| 1858 |
self.assertEqual(relEl[0].xpath("relationshipType")[0].text, |
| 1859 |
"IsServedBy") |
| 1860 |
self.assertEqual(relEl[0].xpath("relatedResource")[0].attrib["ivo-id"], |
| 1861 |
"ivo://%s/__system__/adql/query"%base.getConfig("ivoa", "authority")) |
| 1862 |
|
| 1863 |
# also check metadata on the exposing end |
| 1864 |
svc = base.caches.getRD("//adql").getById("query") |
| 1865 |
svcTree = testhelpers.getXMLTree( |
| 1866 |
builders.getVOResourceElement(svc).render(), debug=False) |
| 1867 |
for rel in svcTree.xpath("metadata/Resource/content/relationship"): |
| 1868 |
if rel.xpath("relationshipType")[0].text=="IsServiceFor": |
| 1869 |
for dest in rel.xpath("relatedResource"): |
| 1870 |
if dest.attrib.get("ivo-id")=="ivo://gavo.testing": |
| 1871 |
return |
| 1872 |
# Fallthrough: The reference to our test service has not been found |
| 1873 |
self.fail("Data registration did not leave isServiceFor meta") |
| 1874 |
finally: |
| 1875 |
# clear adql entry in cache since we've changed it |
| 1876 |
base.caches.clearForName("//adql") |
| 1877 |
|
| 1878 |
def testSupplement(self): |
| 1879 |
tree = self._getTreeFor( |
| 1880 |
'<meta name="isSupplementTo" ivoId="ivo://test/table">Test Table</meta>') |
| 1881 |
self.assertEqual(tree.xpath( |
| 1882 |
"metadata/Resource/content/relationship/relatedResource")[0 |
| 1883 |
].get("ivo-id"), "ivo://test/table") |
| 1884 |
self.assertEqual(tree.xpath( |
| 1885 |
"metadata/Resource/content/relationship/relatedResource")[0 |
| 1886 |
].text, "Test Table") |
| 1887 |
self.assertEqual(tree.xpath( |
| 1888 |
"metadata/Resource/content/relationship/relationshipType")[0 |
| 1889 |
].text, "IsSupplementTo") |
| 1890 |
|
| 1891 |
|
| 1892 |
class IdResolutionTest(testhelpers.VerboseTest): |
| 1893 |
auth = base.getConfig("ivoa", "authority") |
| 1894 |
|
| 1895 |
def testNormal(self): |
| 1896 |
# (id is rdid/id) |
| 1897 |
svc = registry.getResobFromIdentifier( |
| 1898 |
"ivo://%s/tap"%self.auth) |
| 1899 |
self.assertEqual( |
| 1900 |
base.getMetaText(svc, "title"), |
| 1901 |
"Unittest Suite TAP service") |
| 1902 |
|
| 1903 |
def testAuthority(self): |
| 1904 |
rec = registry.getResobFromIdentifier("ivo://%s"%self.auth) |
| 1905 |
self.assertTrue(isinstance(rec, registry.nonservice.ResRec)) |
| 1906 |
self.assertEqual(registry.getResType(rec), "authority") |
| 1907 |
self.assertTrue(base.getMetaText(rec, "description").startswith( |
| 1908 |
" UNCONFIGURED")) |
| 1909 |
|
| 1910 |
def testOrganization(self): |
| 1911 |
with testhelpers.userconfigContent(r""" |
| 1912 |
<STREAM id="registry-interfacerecords"> |
| 1913 |
<resRec id="org"> |
| 1914 |
<meta> |
| 1915 |
resType: organization |
| 1916 |
creationDate: \\metaString{authority.creationDate}{UNCONFIGURED} |
| 1917 |
title: \\metaString{authority.title}{UNCONFIGURED} |
| 1918 |
shortName: \\metaString{authority.shortName}{UNCONFIGURED} org |
| 1919 |
subject: Organisation |
| 1920 |
referenceURL: http://your.institution/home |
| 1921 |
identifier: ivo://\getConfig{ivoa}{authority}/org |
| 1922 |
sets: ivo_managed |
| 1923 |
</meta> |
| 1924 |
<meta name="description" |
| 1925 |
>A test organisation |
| 1926 |
</meta> |
| 1927 |
</resRec> |
| 1928 |
</STREAM>"""): |
| 1929 |
base.caches.clearForName("__system__/services") |
| 1930 |
publication.updateServiceList([base.resolveCrossId("//services")]) |
| 1931 |
rec = registry.getResobFromIdentifier("ivo://%s/org"%self.auth) |
| 1932 |
self.assertTrue(isinstance(rec, registry.nonservice.ResRec)) |
| 1933 |
self.assertEqual(registry.getResType(rec), "organization") |
| 1934 |
self.assertEqual(base.getMetaText(rec, "referenceURL"), |
| 1935 |
"http://your.institution/home") |
| 1936 |
self.assertEqual(base.getMetaText(rec, "description"), |
| 1937 |
"A test organisation") |
| 1938 |
self.assertEqual(base.getMetaText(rec, "sets"), |
| 1939 |
"ivo_managed") |
| 1940 |
|
| 1941 |
base.caches.clearForName("__system__/services") |
| 1942 |
publication.updateServiceList([base.resolveCrossId("//services")]) |
| 1943 |
|
| 1944 |
def testBadId(self): |
| 1945 |
self.assertRaises(registry.IdDoesNotExist, |
| 1946 |
registry.getResobFromIdentifier, |
| 1947 |
"ivo://junk/blastes") |
| 1948 |
|
| 1949 |
|
| 1950 |
class _ListIdentifiersResponse(testhelpers.TestResource): |
| 1951 |
def make(self, ignored): |
| 1952 |
return testhelpers.getXMLTree( |
| 1953 |
oaiinter.runPMH({"verb": "ListIdentifiers", "metadataPrefix": "ivo_vor"}, |
| 1954 |
oaiinter.RegistryCore.builders).render(), debug=False) |
| 1955 |
|
| 1956 |
|
| 1957 |
class ListIdentifiersTest(testhelpers.VerboseTest): |
| 1958 |
resources = [("tree", _ListIdentifiersResponse())] |
| 1959 |
|
| 1960 |
def testRegistryAndAuthorityPresent(self): |
| 1961 |
res = set(el.text for el in self.tree.xpath("//identifier")) |
| 1962 |
expected = set([ |
| 1963 |
"ivo://x-testing/__system__/services/registry", |
| 1964 |
"ivo://x-testing"]) |
| 1965 |
self.assertEqual(res&expected, expected) |
| 1966 |
|
| 1967 |
def testSetSpec(self): |
| 1968 |
sets = self.tree.xpath( |
| 1969 |
"//header[identifier='ivo://x-testing']/setSpec") |
| 1970 |
self.assertEqual(testhelpers.pickSingle(sets).text, "ivo_managed") |
| 1971 |
|
| 1972 |
|
| 1973 |
class OAIParameterTest(testhelpers.VerboseTest): |
| 1974 |
def testEqualGranularityEnforced(self): |
| 1975 |
self.assertRaisesWithMsg(oaiinter.BadArgument, |
| 1976 |
"from", |
| 1977 |
oaiinter.runPMH, |
| 1978 |
({"verb": "ListIdentifiers", "metadataPrefix": "ivo_vor", |
| 1979 |
"from": "2010-10-10", "until": "2011-10-10T10:10:10Z"}, |
| 1980 |
oaiinter.RegistryCore.builders)) |
| 1981 |
|
| 1982 |
|
| 1983 |
class ResumptionTokenTest(testhelpers.VerboseTest): |
| 1984 |
def testBasic(self): |
| 1985 |
pars = {"verb": "listSets"} |
| 1986 |
pars["resumptionToken"] = oaiinter.makeResumptionToken(pars, 20) |
| 1987 |
newPars = oaiinter.parseResumptionToken(pars) |
| 1988 |
self.assertEqual(pars["verb"], newPars["verb"]) |
| 1989 |
self.assertEqual(newPars["resumptionToken"], 20) |
| 1990 |
|
| 1991 |
def testBadTokenFailsProperly(self): |
| 1992 |
self.assertRaisesWithMsg(oaiinter.BadResumptionToken, |
| 1993 |
"Incorrect padding", |
| 1994 |
oaiinter.parseResumptionToken, |
| 1995 |
({"resumptionToken": "xyz"},)) |
| 1996 |
|
| 1997 |
|
| 1998 |
class MetaExpandedTest(testhelpers.VerboseTest): |
| 1999 |
def testWithTAPRecord(self): |
| 2000 |
rd = base.caches.getRD("//tap") |
| 2001 |
rec = publication.iterSvcRecs(rd.services[0]).__next__()[-1] |
| 2002 |
self.assertTrue(rec["description"].startswith( |
| 2003 |
"The Unittest Suite's TAP end point. The Table Access")) |
| 2004 |
self.assertEqual(rec["shortName"], "<13 chrs TAP") |
| 2005 |
|
| 2006 |
|
| 2007 |
class ResourceLocationTest(testhelpers.VerboseTest): |
| 2008 |
def testCaseyTableNamesOk(self): |
| 2009 |
self.assertEqual(registry.getTableDef("ivoa.obsCore").getQName(), |
| 2010 |
"ivoa.ObsCore") |
| 2011 |
|
| 2012 |
|
| 2013 |
class _OtherServiceRRTree(testhelpers.TestResource): |
| 2014 |
def make(self, deps): |
| 2015 |
rd = base.parseFromString(rscdesc.RD, """ |
| 2016 |
<resource schema="test"> |
| 2017 |
<meta name="datetimeUpdated">2000-01-01T00:00:00</meta> |
| 2018 |
<meta name="creationDate">2000-01-01T00:00:00</meta> |
| 2019 |
<meta name="referenceURL">http://faked</meta> |
| 2020 |
<meta name="description">All Faked</meta> |
| 2021 |
<meta name="subject">Fakes</meta> |
| 2022 |
|
| 2023 |
<meta name="productTypeServed">image</meta> |
| 2024 |
<meta name="productTypeServed">polarized-spectrum</meta> |
| 2025 |
|
| 2026 |
<dbCore id="adcore" queriedTable="data/test#adqltable"/> |
| 2027 |
<service id="web" core="adcore"> |
| 2028 |
<meta name="title">Web service</meta> |
| 2029 |
<publish render="form" sets="local"/> |
| 2030 |
</service> |
| 2031 |
<service id="scs" allowed="scs.xml" core="adcore"> |
| 2032 |
<meta name="title">SCS service</meta> |
| 2033 |
<meta name="shortName">test prot</meta> |
| 2034 |
<meta name="testQuery.ra">1</meta> |
| 2035 |
<meta name="testQuery.dec">1</meta> |
| 2036 |
<meta name="testQuery.sr">1</meta> |
| 2037 |
<publish render="scs.xml" sets="ivo_managed"> |
| 2038 |
<meta name="mirrorURL">http://somewhere.el.se/fakemirror?</meta> |
| 2039 |
<meta name="mirrorURL">http://right.the.re/fakemirror?</meta> |
| 2040 |
<meta name="mirrorURL">http://localhost:8080/k/scs/scs.xml?</meta> |
| 2041 |
</publish> |
| 2042 |
<publish render="form" sets="ivo_managed" service="web"/> |
| 2043 |
</service></resource> |
| 2044 |
""") |
| 2045 |
rd.sourceId = "k" |
| 2046 |
|
| 2047 |
from gavo.registry import publication |
| 2048 |
intfRecs, resRecs = [], [] |
| 2049 |
for key, rec in publication.iterSvcRecs(rd.services[1]): |
| 2050 |
if key=="interfaces": |
| 2051 |
intfRecs.append(rec) |
| 2052 |
elif key=="resources": |
| 2053 |
resRecs.append(rec) |
| 2054 |
|
| 2055 |
return (testhelpers.getXMLTree( |
| 2056 |
builders.getVOResourceElement(rd.services[1]).render(), debug=False), |
| 2057 |
intfRecs, resRecs) |
| 2058 |
|
| 2059 |
|
| 2060 |
class OtherServiceTest(testhelpers.VerboseTest): |
| 2061 |
# tests for having a service attribute in a publish record, |
| 2062 |
# and for automatic addition of TAP aux records. |
| 2063 |
resources = [("treeAndRecs", _OtherServiceRRTree())] |
| 2064 |
|
| 2065 |
def testSCSCapability(self): |
| 2066 |
self.assertEqual(self.treeAndRecs[0].xpath( |
| 2067 |
"//capability[1]/interface/accessURL")[0].text, |
| 2068 |
"http://localhost:8080/k/scs/scs.xml?") |
| 2069 |
self.assertEqual(self.treeAndRecs[0].xpath( |
| 2070 |
"//capability[@standardID='ivo://ivoa.net/std/conesearch']" |
| 2071 |
"/maxSR")[0].text, "180") |
| 2072 |
self.assertEqual(self.treeAndRecs[0].xpath( |
| 2073 |
"//capability[@standardID='ivo://ivoa.net/std/conesearch']" |
| 2074 |
"/testQuery/ra")[0].text, "1") |
| 2075 |
|
| 2076 |
def testWebCapability(self): |
| 2077 |
self.assertEqual(self.treeAndRecs[0].xpath( |
| 2078 |
"//capability[2]/interface/accessURL")[0].text, |
| 2079 |
"http://localhost:8080/k/web/form") |
| 2080 |
|
| 2081 |
def testTAPAuxCap(self): |
| 2082 |
self.assertEqual(self.treeAndRecs[0].xpath( |
| 2083 |
"//capability[@standardID='ivo://ivoa.net/std/TAP#aux']" |
| 2084 |
"/interface/accessURL")[0].text, |
| 2085 |
"http://localhost:8080/tap") |
| 2086 |
|
| 2087 |
def testDBFormLink(self): |
| 2088 |
webIntf = [r for r in self.treeAndRecs[1] if r["browseable"]] |
| 2089 |
assert len(webIntf)==1 |
| 2090 |
self.assertEqual(webIntf[0]["referenceURL"], |
| 2091 |
"http://localhost:8080/k/web/info") |
| 2092 |
self.assertEqual(webIntf[0]["accessURL"], |
| 2093 |
"/k/web/form") |
| 2094 |
|
| 2095 |
def testDBCSLink(self): |
| 2096 |
csIntf = [r for r in self.treeAndRecs[1] if r["renderer"]=="scs.xml"] |
| 2097 |
assert len(csIntf)==1 |
| 2098 |
self.assertFalse(csIntf[0]["browseable"]) |
| 2099 |
self.assertEqual(csIntf[0]["referenceURL"], |
| 2100 |
"http://localhost:8080/k/scs/info") |
| 2101 |
self.assertEqual(csIntf[0]["accessURL"], |
| 2102 |
"/k/scs/scs.xml?") |
| 2103 |
|
| 2104 |
def testMirrors(self): |
| 2105 |
intf = self.treeAndRecs[0].xpath( |
| 2106 |
"//capability[@standardID='ivo://ivoa.net/std/conesearch']/" |
| 2107 |
"interface[@role='std']")[0] |
| 2108 |
self.assertEqual(intf.xpath("mirrorURL")[0].text, |
| 2109 |
"http://somewhere.el.se/fakemirror?") |
| 2110 |
self.assertEqual(intf.xpath("mirrorURL")[1].text, |
| 2111 |
"http://right.the.re/fakemirror?") |
| 2112 |
|
| 2113 |
def testSetSpec(self): |
| 2114 |
self.assertEqual([n.text for n in |
| 2115 |
self.treeAndRecs[0].xpath("header/setSpec")], |
| 2116 |
["ivo_managed"]) |
| 2117 |
|
| 2118 |
def testTitle(self): |
| 2119 |
self.assertEqual(self.treeAndRecs[2][0]["title"], "SCS service") |
| 2120 |
|
| 2121 |
def testProductType(self): |
| 2122 |
self.assertEqual( |
| 2123 |
[el.text for el in self.treeAndRecs[0].xpath("//productTypeServed")], |
| 2124 |
['image', 'polarized-spectrum']) |
| 2125 |
|
| 2126 |
|
| 2127 |
class TAPDateBumpingTest(testhelpers.VerboseTest): |
| 2128 |
def setUp(self): |
| 2129 |
with base.getWritableAdminConn() as conn: |
| 2130 |
conn.execute("UPDATE dc.resources" |
| 2131 |
" SET rectimestamp='2000-01-01'" |
| 2132 |
" WHERE sourcerd='__system__/tap'") |
| 2133 |
|
| 2134 |
def testTAPTimestampUpdatedWithADQL(self): |
| 2135 |
publication.updateServiceList([base.caches.getRD("data/ssatest")]) |
| 2136 |
updated = [getattr(o, "getFullId", lambda: "junk")() |
| 2137 |
for o in oaiinter.getMatchingResobs( |
| 2138 |
{"from": datetime.date.today().isoformat()})] |
| 2139 |
self.assertTrue('data/ssatest#c' in updated) |
| 2140 |
self.assertTrue('__system__/tap#run' in updated) |
| 2141 |
|
| 2142 |
def testTAPTimestampConstantWithoutADQL(self): |
| 2143 |
# data/cores has no adql-published tables in it: no TAP record |
| 2144 |
publication.updateServiceList([base.caches.getRD("data/cores")]) |
| 2145 |
updated = [getattr(o, "getFullId", lambda: "no-full-id-sorry")() |
| 2146 |
for o in oaiinter.getMatchingResobs( |
| 2147 |
{"from": datetime.date.today().isoformat()})] |
| 2148 |
self.assertTrue('data/cores#pc' in updated) |
| 2149 |
self.assertFalse('__system__/tap#run' in updated) |
| 2150 |
|
| 2151 |
|
| 2152 |
class TablesetComputationTest(testhelpers.VerboseTest): |
| 2153 |
@staticmethod |
| 2154 |
def _getTablesetTreeFor(rdCls, rdSrc, resId=None): |
| 2155 |
res = api.parseFromString(rdCls, rdSrc) |
| 2156 |
if resId: |
| 2157 |
res = res.getById(resId) |
| 2158 |
ts = tableset.getTablesetForService(res) |
| 2159 |
return testhelpers.getXMLTree(ts.render(), debug=False) |
| 2160 |
|
| 2161 |
def testTablesetWithOutputTable(self): |
| 2162 |
tree = self._getTablesetTreeFor(svcs.Service, |
| 2163 |
"""<service id="a"><dbCore queriedTable="//tap#tables"/> |
| 2164 |
<outputTable><column name="x"/></outputTable> |
| 2165 |
</service>""") |
| 2166 |
self.assertEqual(len(tree.xpath("//table")), 1) |
| 2167 |
self.assertEqual(len(tree.xpath("//table[@type='output']")), 1) |
| 2168 |
|
| 2169 |
def testTablesetWithDbCore(self): |
| 2170 |
tree = self._getTablesetTreeFor(svcs.Service, |
| 2171 |
"""<service id="a"><dbCore queriedTable="//tap#tables"/> |
| 2172 |
</service>""") |
| 2173 |
self.assertEqual(len(tree.xpath("//table")), 1) |
| 2174 |
self.assertEqual(tree.xpath("//table/name")[0].text, "tap_schema.tables") |
| 2175 |
|
| 2176 |
def testTablesetWithTAPCore(self): |
| 2177 |
tree = self._getTablesetTreeFor(svcs.Service, |
| 2178 |
"""<service id="a"><tapCore/></service>""") |
| 2179 |
self.assertTrue(len(tree.xpath("//table"))>5) # at least TAP_SCHEMA |
| 2180 |
self.assertEqual( |
| 2181 |
len(tree.xpath("//table[name='tap_schema.key_columns']/column")), |
| 2182 |
4) |
| 2183 |
self.assertEqual(tree.xpath("//table[name='tap_schema.tables']" |
| 2184 |
"/foreignKey[targetTable='tap_schema.schemas']" |
| 2185 |
"/fkColumn/fromColumn")[0].text, |
| 2186 |
"schema_name") |
| 2187 |
|
| 2188 |
def testTablesetForData(self): |
| 2189 |
tree = self._getTablesetTreeFor(api.RD, """<resource schema="test"> |
| 2190 |
<table id="helper" onDisk="True" adql="hidden"> |
| 2191 |
<column name="hidethis"/></table> |
| 2192 |
<table id="data" onDisk="True" adql="True"> |
| 2193 |
<column name="visthis"/></table> |
| 2194 |
<data id="pub"> |
| 2195 |
<publish/> |
| 2196 |
<make table="helper"/> |
| 2197 |
<make table="data"/> |
| 2198 |
</data></resource>""", "pub") |
| 2199 |
self.assertEqual(len(tree.xpath("//table")), 1) |
| 2200 |
self.assertEqual(tree.xpath("//table/name")[0].text, "test.data") |
| 2201 |
|
| 2202 |
def testTablePublishedEvenNonTAP(self): |
| 2203 |
# It's not altogether clear if it's useful to publish a table |
| 2204 |
# schema when it's not tap-queriable, and perhaps we ought to |
| 2205 |
# qualify that; but then again, if folks explicitly order |
| 2206 |
# table publication, I guess I should honour that. |
| 2207 |
tree = self._getTablesetTreeFor(api.RD, """<resource schema="test"> |
| 2208 |
<table id="pub" onDisk="True"> |
| 2209 |
<publish/> |
| 2210 |
<column name="notinvisible"/></table> |
| 2211 |
</resource>""", "pub") |
| 2212 |
self.assertEqual(len(tree.xpath("//tableset")), 1) |
| 2213 |
self.assertEqual(len(tree.xpath("//column[name='notinvisible']")), 1) |
| 2214 |
|
| 2215 |
|
| 2216 |
if __name__=="__main__": |
| 2217 |
testhelpers.main(OtherServiceTest) |