def test(self, md): rep = Inspirobot.MdUnitTestReport(self.name, self.abstract) # responsible party noderp = md.xpath(self.xpath['mailResponsibleParty'], namespaces=self.cfg['ns']) nodect = md.xpath(self.xpath['mailMDContact'], namespaces=self.cfg['ns']) if len(noderp) > 0: if re.match(self.re['mail'], noderp[0], re.I): rep.addResult('debug', u'partie responsable %s' % noderp[0]) else: rep.addResult( 'error', u'mail contact pour la ressource mal formé : %s' % noderp[0]) else: rep.addResult('error', u'mail contact pour la ressource manquant') if len(nodect) > 0: if re.match(self.re['mail'], nodect[0], re.I): rep.addResult('debug', u'contact %s' % nodect[0]) else: rep.addResult( 'error', u'mail contact pour les métadonnées mal formé : %s' % nodect[0]) else: rep.addResult('error', u'mail contact pour les métadonnées manquant') self.addReport(rep)
def test(self, md): rep = Inspirobot.MdUnitTestReport(self.name, self.abstract) md_identifier = md.xpath(self.xpath['MD_Identifier'], namespaces=self.cfg['ns']) if len(md_identifier) != 1: rep.addResult('error', u'nb de MD_Identifier incorrect : %s' % len(md_identifier)) elif not(re.match(self.re['MD_Identifier'], md_identifier[0], re.I)): rep.addResult('warning', u'format MD_Identifier incorrect : %s' % md_identifier[0]) else: rep.addResult('debug', u'MD_Identifier OK') self.addReport(rep)
def test(self, md): rep = Inspirobot.MdUnitTestReport(self.name, self.abstract) searched_regex = "^-- " nb_default_values = sum( [len(re.findall(searched_regex, t)) for t in md.itertext()]) if nb_default_values > 0: rep.addResult( 'error', u'%s valeurs par défaut trouvées' % nb_default_values) self.addReport(rep)
def test(self, md): # limitations and restriction check rep2 = Inspirobot.MdUnitTestReport(self.name, self.abstract) uselimitation = md.xpath(self.xpath['uselimitation'], namespaces=self.cfg['ns']) restriction = md.xpath(self.xpath['restrictions'], namespaces=self.cfg['ns']) if len(uselimitation) > 0: rep2.setNameAbstract( u'LIMIT', u'useLimitation. Vérifie la longueur de ce champ.') if len(uselimitation[0]) > 25: rep2.addResult('debug', u'useLimitation : %s' % uselimitation[0]) else: rep2.addResult( 'debug', u'useLimitation < 25 char : %s' % uselimitation[0]) else: rep2.setNameAbstract( u'LIC', u'Licence. Vérifie la présence de useLimitation.') rep2.addResult('error', u'useLimitation manquant') if len(restriction) > 0: rep2.addResult('debug', u'otherRestrictions : %s' % restriction[0]) else: rep2.addResult('error', u'otherRestrictions manquant') self.addReport(rep2) # open licence check node_kwol = md.xpath(self.xpath['opendata'], namespaces=self.cfg['ns']) if len(node_kwol) == 1: rep1 = Inspirobot.MdUnitTestReport(self.name, self.abstract) rep1.setNameAbstract( 'OPEN', u'Données ouvertes. Recherche la présence du mot-clé.') rep1.addResult('info', u'keyword données ouvertes détecté') if len( md.xpath(self.xpath['constraints'], namespaces=self.cfg['ns'])) != 1: rep1.addResult('warning', u'otherConstraints incorrect') self.addReport(rep1)
def test(self, md): rep = Inspirobot.MdUnitTestReport(self.name, self.abstract) node = md.xpath(self.xpath['lineage'], namespaces=self.cfg['ns']) if len(node) == 1: if len(node[0]) > 25: rep.addResult('debug', node[0]) else: rep.addResult( 'warning', u'généalogie trop courte : %s chars' % len(node[0])) else: rep.addResult('error', u'généalogie présente %s fois' % len(node)) self.addReport(rep)
def test(self, md): rep = Inspirobot.MdUnitTestReport(self.name, self.abstract) node = md.xpath(self.xpath['inspire'], namespaces=self.cfg['ns']) if len(node) > 1: rep.addResult('warning', u'mot-clés INSPIRE utilisés %s fois' % len(node)) self.addReport(rep) elif len(node) == 1: kw = node[0].xpath(self.xpath['subKeyword'], namespaces=self.cfg['ns'])[0] if kw in self.values['inspireKw']: rep.addResult('info', u'INSPIRE/%s' % kw) else: rep.addResult('warning', u'INSPIRE/%s incorrect' % kw) self.addReport(rep)
def test(self, md): rep = Inspirobot.MdUnitTestReport(self.name, self.abstract) node_den = md.xpath(self.xpath['denominator'], namespaces=self.cfg['ns']) node_dis = md.xpath(self.xpath['distance'], namespaces=self.cfg['ns']) if len(node_den) > 1: rep.addResult('error', u'Dénominateur fourni %s fois' % len(node_den)) self.addReport(rep) if len(node_dis) > 1: rep.addResult('warning', u'Distance fournie %s fois' % len(node_dis)) self.addReport(rep) if len(node_dis) > 0 and len(node_den) > 0: rep.addResult('error', u'Distance et résolution fournis simultanément') self.addReport(rep) if len(node_dis) == 0 and len(node_den) == 0: rep.addResult('warning', u'Aucune résolution fournie') self.addReport(rep)
def test(self, md): view = False download = False # iterates over digital transfert options for olnode in md.xpath(self.xpath['DTO_OnlineResource'], namespaces=self.cfg['ns']): protocol = olnode.xpath(self.xpath['protocol'], namespaces=self.cfg['ns']) uri = olnode.xpath(self.xpath['URL'], namespaces=self.cfg['ns']) # results in our test results class rep = Inspirobot.MdUnitTestReport( 'DTO', u'Vérification digitalTransferOption') if protocol and uri: rep.setUrl(uri[0]) # DTO WMS if protocol[0] == 'OGC:WMS': rep.setNameAbstract( 'WMS', u'WMS. Vérifie le renseignement des liens WMS.') if re.match(self.re['url'], uri[0]): cap_found = False # dictionary of query params with lowercased keys query_params = \ {k.lower():v[0] for k,v in parse_qs(urlparse(uri[0]).query).items() if len(v) > 0} if query_params.get("service", "") == "WMS" \ and query_params.get("request", "") == "GetCapabilities": cap_found = True rep.addResult('debug', u'getCapabilities trouvé') elif query_params.get("service", "").lower() == "wms" \ and query_params.get("request", "").lower() == "getcapabilities": cap_found = True rep.addResult( 'warning', u'Non respect de la casse des valeurs des paramètres' u'de la requête GetCapabilities') layername = olnode.xpath(self.xpath['layername'], namespaces=self.cfg['ns']) if cap_found: if len(layername) == 1: rep.addResult( 'debug', u'layername trouvé : %s' % layername[0]) view = True else: rep.addResult('error', u'layername non trouvé') else: rep.addResult( 'error', u"getCapabilities n'est pas une URL : %s" % rep.url) # DTO WFS elif protocol[0] == 'OGC:WFS': rep.setNameAbstract( 'WFS', u'WFS. Vérifie le renseignement des liens WFS.') if re.match(self.re['url'], uri[0]): cap_found = False # dictionary of query params with lowercased keys query_params = \ {k.lower():v[0] for k,v in parse_qs(urlparse(uri[0]).query).items() if len(v) > 0} if query_params.get("service", "") == "WFS" \ and query_params.get("request", "") == "GetCapabilities": cap_found = True rep.addResult('debug', u'getCapabilities trouvé') elif query_params.get("service", "").lower() == "wfs" \ and query_params.get("request", "").lower() == "getcapabilities": cap_found = True rep.addResult( 'warning', u'Non respect de la casse des valeurs des paramètres' u'de la requête GetCapabilities') featuretype = olnode.xpath(self.xpath['featuretype'], namespaces=self.cfg['ns']) if cap_found: if len(featuretype) == 1: rep.addResult( 'debug', u'featuretype trouvé : %s' % featuretype[0]) download = True else: rep.addResult('error', u'featuretype non trouvé') else: rep.addResult( 'error', u"getCapabilities n'est pas une URL : %s" % rep.url) # DTO WCS elif protocol[0] == 'OGC:WCS': rep.setNameAbstract( 'WCS', u'WCS. Vérifie le renseignement des liens WCS.') if re.match(self.re['url'], uri[0]): cap_found = False # dictionary of query params with lowercased keys query_params = \ {k.lower():v[0] for k,v in parse_qs(urlparse(uri[0]).query).items() if len(v) > 0} if query_params.get("service", "") == "WCS" \ and query_params.get("request", "") == "GetCapabilities": cap_found = True rep.addResult('debug', u'getCapabilities trouvé') elif query_params.get("service", "").lower() == "wcs" \ and query_params.get("request", "").lower() == "getcapabilities": cap_found = True rep.addResult( 'warning', u'Non respect de la casse des valeurs des paramètres' u'de la requête GetCapabilities') if cap_found: download = True else: rep.addResult( 'error', u"getCapabilities n'est pas une URL : %s" % rep.url) # DTO download elif protocol[0] == 'WWW:DOWNLOAD-1.0-http--download': if re.match(self.re['url'], uri[0]): rep.setNameAbstract( u'DL', u'Vérifie la conformité des liens de téléchargement' ) rep.addResult('debug', u'URL téléchargement trouvée') download = True else: rep.addResult('error', 'mauvaise URL : %s' % rep.url) # DTO web elif protocol[0] == 'WWW:LINK-1.0-http--link': rep.setNameAbstract( 'WWW', u'Vérifie la conformité des liens vers des pages web') if re.match(self.re['url'], uri[0]): rep.addResult('debug', u'URL trouvée') else: rep.addResult('error', u'mauvaise URL : %s' % rep.url) # DTO unknown else: rep.setNameAbstract( u'WW?', u'Vérifie la conformité des autres URL') if re.match(self.re['url'], uri[0]): rep.addResult('debug', u'URL trouvée') else: rep.addResult('error', u'mauvaise URL : %s' % rep.url) else: rep.addResult('warning', u'protocole manquant') self.addReport(rep) rep = Inspirobot.MdUnitTestReport( 'view', u"Vérifie la présence d'un service de visualisation") if view: rep.addResult('info', u'service visualisation trouvé') else: rep.addResult('error', u'service visualisation non trouvé') self.addReport(rep) rep = Inspirobot.MdUnitTestReport( 'download', u"Vérifie la présence d'un service de téléchargement") if download: rep.addResult('info', u'service téléchargement trouvé') else: rep.addResult('error', u'service téléchargement non trouvé') self.addReport(rep)