[ckan-changes] commit/ckan: 4 new changesets
Bitbucket
commits-noreply at bitbucket.org
Fri Jun 24 10:45:01 UTC 2011
4 new changesets in ckan:
http://bitbucket.org/okfn/ckan/changeset/6432d10da7b8/
changeset: 6432d10da7b8
branch: feature-1198-mailer
user: pudo
date: 2011-06-23 22:29:17
summary: [lib] remove old code files not used any longer
affected #: 7 files (0 bytes)
--- a/ckan/lib/ckan-to-talis.py Thu Jun 23 16:45:20 2011 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-import sys
-from optparse import OptionParser
-
-import ckanclient
-import talis
-
-class TalisLoader:
- def __init__(self, ckan_host, store, talisuser, talispassword):
- api_key = None
-
- # ckan connection
- if not ckan_host.startswith('http://'):
- ckan_host = 'http://' + ckan_host
- ckan_host = ckan_host + '/api'
- self.ckan = ckanclient.CkanClient(base_location=ckan_host,
- api_key=api_key)
-
- # talis connection
- talis.TalisLogin.init(store, talisuser, talispassword)
- self._talis = talis.Talis()
-
- def get_package_names(self):
- res = self.ckan.package_register_get()
- assert self.ckan.last_status == 200, 'Error accessing \'%s\': %s' % (self.ckan.last_location, self.ckan.last_status)
- packages = res
- return packages
-
- def load_to_talis(self, pkg_name):
- print '=== Loading %s ===' % pkg_name
- res = self.ckan.package_entity_get(pkg_name)
- if self.ckan.last_status != 200:
- print 'Failed to read CKAN package %s: %s' % (pkg_name, self.ckan.last_status)
- return
- pkg_dict = res
- res = self._talis.post_pkg(pkg_dict)
- if res:
- print 'Failed to post package %s to Talis: %s' % (pkg_name, res)
- return
-## res = self._talis.get_pkg(pkg_name)
-## assert res, res
-## print 'Done!'
-
-
-if __name__ == '__main__':
- usage = 'usage: %prog [options] talis-password'
- parser = OptionParser(usage=usage)
-# parser.add_option('-k', '--apikey', dest='apikey', help='API key')
- parser.add_option('-c', '--ckanhost', dest='ckanhost', help='CKAN host name', default='www.ckan.net')
- parser.add_option('-s', '--store', dest='store', help='Talis store name', default='ckan-dev1')
- parser.add_option('-u', '--talisusername', dest='talisuser', help='Talis user name', default='ckan')
- parser.add_option('', '--startfrompackage', dest='startpackage', help='Package to start from', default='')
- parser.add_option('-p', '--packages', dest='packages', help='Quoted list of packages to upload', default='')
-
- (options, args) = parser.parse_args()
- if len(args) != 1:
- parser.print_help()
- sys.exit(0)
-
- talispassword = args[0]
-
- te = TalisLoader(options.ckanhost, options.store, options.talisuser, talispassword)
-
- pkg_names = te.get_package_names()
- start_index = 0
- if options.startpackage:
- start_index = pkg_names.index(options.startpackage)
- assert start_index
- pkg_names = pkg_names[start_index:]
- elif options.packages:
- pkgs = options.packages.replace(',', ' ')
- pkg_names = pkgs.split() if ' ' in pkgs else [pkgs]
- for pkg_name in pkg_names:
- te.load_to_talis(pkg_name)
-
--- a/ckan/lib/cswclient.py Thu Jun 23 16:45:20 2011 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,243 +0,0 @@
-#!/usr/bin/env python
-import urllib
-import urllib2
-import cookielib
-from lxml import etree
-
-class CswError(Exception): pass
-
-class CswRequest(object):
-
- template = ""
-
- def __init__(self, **kwds):
- self.params = kwds
-
- def get_params(self):
- return self.params
-
- def get_xml(self):
- if self.template == None:
- raise CswError, "No template attribute on class %s." % self.__class__
- return self.template % self.get_params()
-
-
-class CswGetCapabilities(CswRequest):
-
- template = """<?xml version="1.0"?>
-<csw:GetCapabilities xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW">
- <ows:AcceptVersions xmlns:ows="http://www.opengis.net/ows">
- <ows:Version>2.0.2</ows:Version>
- </ows:AcceptVersions>
- <ows:AcceptFormats xmlns:ows="http://www.opengis.net/ows">
- <ows:OutputFormat>application/xml</ows:OutputFormat>
- </ows:AcceptFormats>
-</csw:GetCapabilities>"""
-
-
-class CswGetRecords(CswRequest):
-
- template = """<?xml version="1.0"?>
-<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2"
- xmlns:gmd="http://www.isotc211.org/2005/gmd" service="CSW" version="2.0.2" resultType="%(result_type)s">
- <csw:Query typeNames="gmd:MD_Metadata">
- <csw:ElementName>dc:identifier</csw:ElementName>
- <csw:Constraint version="1.1.0">
- <Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"/>
- </csw:Constraint>
- </csw:Query>
-</csw:GetRecords>"""
-
- def __init__(self, result_type='results'):
- super(CswGetRecords, self).__init__(result_type=result_type)
-
-
-class CswGetRecordById(CswRequest):
-
- template = """<?xml version="1.0"?>
-<csw:GetRecordById xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2"
- outputSchema="csw:IsoRecord">
- <csw:Id>%(identifier)s</csw:Id>
-</csw:GetRecordById>"""
-
- def __init__(self, identifier):
- super(CswGetRecordById, self).__init__(identifier=identifier)
-
-
-class CswClient(object):
-
- namespaces = {
- "csw": "http://www.opengis.net/cat/csw/2.0.2",
- "xsi": "http://www.w3.org/2001/XMLSchema-instance",
- "geonet": "http://www.fao.org/geonetwork",
- "dc": "http://purl.org/dc/elements/1.1/",
- "dct": "http://purl.org/dc/terms/",
- "gmd": "http://www.isotc211.org/2005/gmd",
- }
-
- def __init__(self, base_url, csw_uri='', login_uri='', logout_uri='', username=None, password=None):
- self.base_url = base_url
- self.csw_uri = csw_uri
- self.login_uri = login_uri
- self.logout_uri = logout_uri
- self.username = username
- self.password = password
- self.login_url = self.base_url + self.login_uri
- self.logout_url = self.base_url + self.logout_uri
- self.csw_url = self.base_url + self.csw_uri
- self.opener = None
-
- def assert_capabilities(self):
- xml = self.send_get_capabilities()
- # Check document type is csw:Capabilities.
- if "<csw:Capabilities" not in xml:
- msg = "Doesn't look like a capabilities response: %s" % xml
- raise CswError, msg
- # Check service type is CSW.
- if "<ows:ServiceType>CSW</ows:ServiceType>" not in xml:
- msg = "Doesn't look like a CSW service: %s" % xml
- raise CswError, msg
- # Check is capable of GetRecords operation.
- if "<ows:Operation name=\"GetRecords\">" not in xml:
- msg = "Doesn't look like GetRecords operation is supported: %s" % xml
- raise CswError, msg
- # Check is capable of GetRecordById operation.
- if "<ows:Operation name=\"GetRecordById\">" not in xml:
- msg = "Doesn't look like GetRecordById operation is supported: %s" % xml
- raise CswError, msg
- # Todo: Change above code to use XPaths?
-
- #def iter_records(self, max_records=None):
- # records = []
- # for id in self.get_identifiers():
- # record = self.get_record_by_id(id)
- # records.append(record)
- # if max_records and len(records) == max_records:
- # break
- # return records
-
- def get_records(self, max_records=None):
- records = []
- for id in self.get_identifiers():
- record = self.get_record_by_id(id)
- records.append(record)
- if max_records and len(records) == max_records:
- break
- return records
-
- def get_identifiers(self):
- response = self.send_get_records()
- return self.extract_identifiers(response)
-
- def get_record_by_id(self, identifier):
- response = self.send_get_record_by_id(identifier)
- return self.extract_metadata(response)
-
- def send_get_capabilities(self):
- return self.send(CswGetCapabilities())
-
- def send_get_records(self):
- return self.send(CswGetRecords())
-
- def send_get_record_by_id(self, identifier):
- return self.send(CswGetRecordById(identifier=identifier))
-
- def send(self, csw_request):
- csw_request_xml = self.get_xml_from_csw_request(csw_request)
- http_header = {"Content-type": "application/xml", "Accept": "text/plain"}
- http_request = urllib2.Request(self.csw_url, csw_request_xml, http_header)
- try:
- http_response = self.urlopen(http_request)
- except Exception, inst:
- msg = "Couldn't send CSW request to CSW server: %s: %s: %s" % (
- self.base_url, inst, csw_request_xml
- )
- raise CswError, msg
- csw_response_xml = http_response.read()
- return csw_response_xml
-
- def get_xml_from_csw_request(self, csw_request):
- if isinstance(csw_request, CswRequest):
- csw_request_xml = csw_request.get_xml()
- else:
- csw_request_xml = csw_request
- return csw_request_xml
-
- def extract_identifiers(self, get_records_response):
- parser = etree.XMLParser(remove_blank_text=True)
- tree = etree.fromstring(get_records_response, parser=parser)
- xpath = '//csw:Record/dc:identifier/text()'
- return tree.xpath(xpath, namespaces=self.namespaces)
-
- def extract_metadata(self, get_record_by_id_response):
- parser = etree.XMLParser(remove_blank_text=True)
- tree = etree.fromstring(get_record_by_id_response, parser=parser)
- xpath = 'gmd:MD_Metadata'
- elems = tree.xpath(xpath, namespaces=self.namespaces)
- if isinstance(elems, list) and len(elems) == 1:
- elem = elems[0]
- else:
- msg = "Unexpected return value from etree.xpath: %s" % repr(elems)
- raise CswError, msg
- return etree.tostring(elem)
-
- def login(self):
- if not (self.username and self.password):
- return
- self.logout()
- http_params = urllib.urlencode({"username": self.username, "password": self.password})
- http_header = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
- http_request = urllib2.Request(self.login_url, http_params, http_header)
- try:
- http_response = self.urlopen(http_request)
- except Exception, inst:
- msg = "Couldn't login to CSW with given credentials: %s" % inst
- raise CswError, msg
- cookie_jar = cookielib.CookieJar()
- cookie_jar.extract_cookies(http_response, http_request)
- cookie_handler= urllib2.HTTPCookieProcessor(cookie_jar)
- redirect_handler= urllib2.HTTPRedirectHandler()
- self.opener = urllib2.build_opener(redirect_handler, cookie_handler)
-
- def logout(self):
- if not (self.username and self.password):
- return
- http_request = urllib2.Request(self.logout_url)
- try:
- http_response = self.urlopen(http_request)
- except Exception, inst:
- msg = "Couldn't logout from CSW server %s: %s" % (
- self.base_url, inst)
- raise CswError, msg
- xml_response = http_response.read()
- if "<ok />" not in xml_response:
- msg = "Couldn't logout from CSW server %s: %s" % (
- self.base_url, xml_response)
- raise CswError, msg
-
- def urlopen(self, http_request):
- try:
- if self.opener:
- http_response = self.opener.open(http_request)
- else:
- http_response = urllib2.urlopen(http_request)
- except urllib2.URLError, inst:
- msg = 'Error making CSW server request: %s' % inst
- raise CswError, msg
- else:
- return http_response
-
-
-class GeoNetworkClient(CswClient):
-
- def __init__(self, base_url, username='', password=''):
- login_uri = '/../xml.user.login'
- logout_uri = '/../xml.user.logout'
- super(GeoNetworkClient, self).__init__(
- base_url=base_url,
- login_uri=login_uri,
- logout_uri=logout_uri,
- username=username,
- password=password,
- )
-
--- a/ckan/lib/monitor.py Thu Jun 23 16:45:20 2011 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-from ckan.lib.async_notifier import AsyncConsumer
-
-class Monitor(AsyncConsumer):
- '''Monitor for asynchronous notifications. Prints any notifications.
- NB Doesn\'t work when carrot backend configured to use Python Queue - needs rabbitmq
- or similar.
- '''
- def __init__(self):
- queue_name = 'monitor'
- routing_key = '*'
- super(Monitor, self).__init__(queue_name, routing_key)
- print 'Monitoring notifications'
- print 'Options:'
- options = self.consumer_options.items() + {'host':self.conn.host,
- 'userid':self.conn.userid,
- 'password':self.conn.password}.items()
- for key, value in options:
- print ' %s: %s' % (key, value)
- print '...'
- self.run()
-
- def callback(self, notification):
- print '%s: %r\n' % (notification.__class__.__name__, notification['payload'])
--- a/ckan/lib/rdf.py Thu Jun 23 16:45:20 2011 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,73 +0,0 @@
-import surf
-
-DOMAIN = 'http://ckan.net'
-CKAN_NAMESPACE = 'http://ckan.net/#'
-CKAN_SUBJECT_BASE = DOMAIN + '/package/'
-
-class RdfExporter(object):
- def __init__(self):
- surf.ns.register(ckan=CKAN_NAMESPACE)
- surf.ns.register(dc='http://purl.org/dc/elements/1.1/') # old, allows literals
- #surf.ns.register(dc='http://purl.org/dc/terms/') # new one
-
- def export_package(self, pkg):
- assert isinstance(pkg, dict)
-
- store = surf.Store(reader='rdflib',
- writer='rdflib',
- rdflib_store='IOMemory')
-
- self._rdf_session = surf.Session(store)
-
- PackageRdf = self._web_resource(surf.ns.CKAN['Package'])[0]
-
- pkg_rdf = PackageRdf(subject=CKAN_SUBJECT_BASE + pkg['name'])
-
- pkg_rdf.foaf_isPrimaryTopicOf = self._web_resource(DOMAIN + '/package/read/%s' % pkg['name'])
-
-
- if pkg['download_url']:
- pkg_rdf.ckan_downloadUrl = self._web_resource(pkg['download_url'])
-
- if pkg['title']:
- pkg_rdf.dc_title = pkg['title']
-
- if pkg['url']:
- pkg_rdf.foaf_homepage = self._web_resource(pkg['url'])
-
- if pkg['tags']:
- pkg_rdf.dc_subject = pkg['tags']
-
- if pkg['author'] or pkg['author_email']:
-## pkg_rdf.dc_creator = pkg['author'].strip()
-## if pkg['author_email']:
-## pkg_rdf.dc_creator = [pkg['author'].strip(), self._web_resource('mailto:' + pkg['author_email'])]
- pkg_rdf.dc_creator = ((pkg['author'] or '') + ' ' + (pkg['author_email'] or '')).strip()
-
- if pkg['maintainer'] or pkg['maintainer_email']:
- pkg_rdf.dc_contributor = ((pkg['maintainer'] or '') + ' ' + (pkg['maintainer_email'] or '')).strip()
-
- if pkg['license']:
- pkg_rdf.dc_rights = pkg['license']
-
- if pkg['notes']:
- pkg_rdf.dc_description = pkg['notes']
-
- self._rdf_session.commit()
-
- return pkg_rdf.serialize()
-
- def _web_resource(self, url):
- # cope with multiple urls in string
- url = url.replace(',', ' ')
- urls = url.split()
-
- url_classes = []
- for url in urls:
- try:
- url_classes.append(self._rdf_session.get_class(url))
- except ValueError, e:
- url_classes.append(url)
-
- return url_classes
-
--- a/ckan/lib/talis.py Thu Jun 23 16:45:20 2011 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,137 +0,0 @@
-import urllib2
-import os
-
-import rdf
-
-TALIS_REALM = 'bigfoot'
-TALIS_URI = 'http://api.talis.com/stores/'
-
-class TalisLogin:
- storename = 'ckan-dev1'
- username = 'ckan'
- password = None
-
- @staticmethod
- def init(storename, username, password):
- TalisLogin.storename = storename
- TalisLogin.username = username
- TalisLogin.password = password
-
- @staticmethod
- def get_password():
- if TalisLogin.password is None:
- TalisLogin.password = os.environ['TALIS_PASSWORD']
- return TalisLogin.password
-
- @staticmethod
- def get_username():
- return TalisLogin.username
-
- @staticmethod
- def get_storename():
- return TalisLogin.storename
-
-class Talis:
- def __init__(self):
- self.rdf = rdf.RdfExporter()
-
- def get_field_predicate_map(self, store):
- fp_map_base = \
-'''
-<?xml version="1.0" encoding="utf-8"?>
-<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:bf="http://schemas.talis.com/2006/bigfoot/configuration#" xmlns:frm="http://schemas.talis.com/2006/frame/schema#" >
- <bf:FieldPredicateMap rdf:about="http://api.talis.com/stores/$(store)s/indexes/default/fpmaps/default">
- %(mapped_properties)s
- </bf:FieldPredicateMap>
-</rdf:RDF>
-'''
-
- mapped_property = \
-'''
- <frm:mappedDatatypeProperty>
- <rdf:Description rdf:about="http://api.talis.com/stores/$(store)s/indexes/default/fpmaps/default#%(property)s">
- <frm:property rdf:resource="%(namespace)s%(property)s"/>
- <frm:name>%(property)</frm:name>
- </rdf:Description>
- </frm:mappedDatatypeProperty>
-'''
- namespaces = {'dc':'http://purl.org/dc/elements/1.1/',
- 'foaf':'http://xmlns.com/foaf/0.1/',
- 'ckan':'http://ckan.net/ns#',
- }
- map = [('isPrimaryTopicOf', 'foaf'),
- ('title', 'dc'),
- ('description', 'dc'),
- ('foaf', 'homepage'),
- ('downloadUrl', 'ckan'),
- ('contributor', 'dc'),
- ('rights', 'dc'),
- ('subject', 'dc'),
- ]
-
- mapped_properties = []
- for property, ns_abbreviation in map:
- mp = mapped_property % {'namespace':namespaces[ns_abbreviation],
- 'property':property}
- mapped_properties.append(mp)
- return fp_map_base % {'mapped_properties':'\n'.join(mapped_properties), 'store': store}
-
- def post_pkg(self, pkg_dict):
- rdf_xml = self.rdf.export_package(pkg_dict)
- service = '/meta'
- return self.post(service, rdf_xml, with_password=True)
-
- def post(self, service, rdf_xml, with_password=False):
- uri = TALIS_URI + TalisLogin.get_storename() + service
- if with_password:
- talis_password = TalisLogin.get_password()
- talis_username = TalisLogin.get_username()
- authhandler = urllib2.HTTPDigestAuthHandler()
- authhandler.add_password(TALIS_REALM, uri, talis_username, talis_password)
- opener = urllib2.build_opener(authhandler)
- urllib2.install_opener(opener)
- headers = {"User-Agent":"ckan-rdf", "Content-Type":"application/rdf+xml"}
- request = urllib2.Request(uri, rdf_xml, headers)
- try:
- response = urllib2.urlopen(request)
- except urllib2.HTTPError, arg:
- return arg
- return response.read()
-
- def get_pkg(self, package_name):
- uri = TALIS_URI + TalisLogin.get_storename() + '/meta?about=%s&output=rdf' % (rdf.CKAN_SUBJECT_BASE + package_name)
- return self.get(uri)
-
- def get_pkg_list(self):
- uri = TALIS_URI + TalisLogin.get_storename() + '/meta?about=%s&output=rdf' % (rdf.CKAN_SUBJECT_BASE)
- return self.get(uri)
-
- def get(self, uri):
- headers = {"User-Agent":"ckan-rdf"}
- request = urllib2.Request(uri, None, headers)
- try:
- response = urllib2.urlopen(request)
- except urllib2.HTTPError, arg:
- return arg
- return response.read()
-
- def send_rdf(self, talis_store, username, password):
- import ckan.model as model
- TalisLogin.storename = talis_store
- TalisLogin.username = username
- TalisLogin.password = password
-
- err = None
- for pkg in model.Session.query(model.Package).all():
- pkg_dict = pkg.as_dict()
- err = self.post_pkg(pkg_dict)
- if err:
- print "error"
- print err
- break
- return err
-
-
-
- def dump(self):
- pass
--- a/ckan/tests/lib/mock_cswclient.py Thu Jun 23 16:45:20 2011 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1007 +0,0 @@
-from ckan.lib.cswclient import GeoNetworkClient
-
-class MockGeoNetworkClient(GeoNetworkClient):
-
- get_capabilities_request_xml = """<?xml version="1.0"?>
-<csw:GetCapabilities xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW">
- <ows:AcceptVersions xmlns:ows="http://www.opengis.net/ows">
- <ows:Version>2.0.2</ows:Version>
- </ows:AcceptVersions>
- <ows:AcceptFormats xmlns:ows="http://www.opengis.net/ows">
- <ows:OutputFormat>application/xml</ows:OutputFormat>
- </ows:AcceptFormats>
-</csw:GetCapabilities>"""
-
- get_capabilities_response_xml = """
-<?xml version="1.0" encoding="UTF-8"?>
-<csw:Capabilities xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:gml="http://www.opengis.net/gml" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:ows="http://www.opengis.net/ows" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0.2" xsi:schemaLocation="http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd">
- <ows:ServiceIdentification>
- <ows:Title />
- <ows:Abstract />
- <ows:Keywords>
- <!-- Keywords are automatically added by GeoNetwork
- according to catalogue content. -->
- <ows:Type>theme</ows:Type>
- </ows:Keywords>
- <ows:ServiceType>CSW</ows:ServiceType>
- <ows:ServiceTypeVersion>2.0.2</ows:ServiceTypeVersion>
- <ows:Fees />
- <ows:AccessConstraints />
- </ows:ServiceIdentification>
- <ows:ServiceProvider>
- <ows:ProviderName>GeoNetwork opensource</ows:ProviderName>
- <ows:ProviderSite xlink:href="http://localhost:8080/geonetwork" />
- <ows:ServiceContact>
- <ows:IndividualName />
- <ows:PositionName />
- <ows:ContactInfo>
- <ows:Phone>
- <ows:Voice />
- <ows:Facsimile />
- </ows:Phone>
- <ows:Address>
- <ows:DeliveryPoint />
- <ows:City />
- <ows:AdministrativeArea />
- <ows:PostalCode />
- <ows:Country />
- <ows:ElectronicMailAddress />
- </ows:Address>
- <ows:HoursOfService />
- <ows:ContactInstructions />
- </ows:ContactInfo>
- <ows:Role />
- </ows:ServiceContact>
- </ows:ServiceProvider>
- <ows:OperationsMetadata>
- <ows:Operation name="GetCapabilities">
- <ows:DCP>
- <ows:HTTP>
- <ows:Get xlink:href="http://localhost:8080/geonetwork/srv/en/csw" />
- <ows:Post xlink:href="http://localhost:8080/geonetwork/srv/en/csw" />
- </ows:HTTP>
- </ows:DCP>
- <ows:Parameter name="sections">
- <ows:Value>ServiceIdentification</ows:Value>
- <ows:Value>ServiceProvider</ows:Value>
- <ows:Value>OperationsMetadata</ows:Value>
- <ows:Value>Filter_Capabilities</ows:Value>
- </ows:Parameter>
- <ows:Constraint name="PostEncoding">
- <ows:Value>XML</ows:Value>
- </ows:Constraint>
- </ows:Operation>
- <ows:Operation name="DescribeRecord">
- <ows:DCP>
- <ows:HTTP>
- <ows:Get xlink:href="http://localhost:8080/geonetwork/srv/en/csw" />
- <ows:Post xlink:href="http://localhost:8080/geonetwork/srv/en/csw">
- <ows:Constraint name="PostEncoding">
- <ows:Value>XML</ows:Value>
- <ows:Value>SOAP</ows:Value>
- </ows:Constraint>
- </ows:Post>
- </ows:HTTP>
- </ows:DCP>
- <ows:Parameter name="typeName">
- <ows:Value>csw:Record</ows:Value>
- <ows:Value>gmd:MD_Metadata</ows:Value>
- </ows:Parameter>
- <ows:Parameter name="outputFormat">
- <ows:Value>application/xml</ows:Value>
- </ows:Parameter>
- <ows:Parameter name="schemaLanguage">
- <ows:Value>http://www.w3.org/TR/xmlschema-1/</ows:Value>
- </ows:Parameter>
- <ows:Parameter name="typeName">
- <ows:Value>csw:Record</ows:Value>
- <ows:Value>gmd:MD_Metadata</ows:Value>
- </ows:Parameter>
- <ows:Constraint name="PostEncoding">
- <ows:Value>XML</ows:Value>
- </ows:Constraint>
- </ows:Operation>
- <ows:Operation name="GetDomain">
- <ows:DCP>
- <ows:HTTP>
- <ows:Get xlink:href="http://localhost:8080/geonetwork/srv/en/csw" />
- <ows:Post xlink:href="http://localhost:8080/geonetwork/srv/en/csw" />
- </ows:HTTP>
- </ows:DCP>
- </ows:Operation>
- <ows:Operation name="GetRecords">
- <ows:DCP>
- <ows:HTTP>
- <ows:Get xlink:href="http://localhost:8080/geonetwork/srv/en/csw" />
- <ows:Post xlink:href="http://localhost:8080/geonetwork/srv/en/csw">
- <ows:Constraint name="PostEncoding">
- <ows:Value>XML</ows:Value>
- <ows:Value>SOAP</ows:Value>
- </ows:Constraint>
- </ows:Post>
- </ows:HTTP>
- </ows:DCP>
- <!-- FIXME : Gets it from enum or conf -->
- <ows:Parameter name="resultType">
- <ows:Value>hits</ows:Value>
- <ows:Value>results</ows:Value>
- <ows:Value>validate</ows:Value>
- </ows:Parameter>
- <ows:Parameter name="outputFormat">
- <ows:Value>application/xml</ows:Value>
- </ows:Parameter>
- <ows:Parameter name="outputSchema">
- <ows:Value>http://www.opengis.net/cat/csw/2.0.2</ows:Value>
- <ows:Value>http://www.isotc211.org/2005/gmd</ows:Value>
- </ows:Parameter>
- <ows:Parameter name="typeNames">
- <ows:Value>csw:Record</ows:Value>
- <ows:Value>gmd:MD_Metadata</ows:Value>
- </ows:Parameter>
- <ows:Parameter name="CONSTRAINTLANGUAGE">
- <ows:Value>FILTER</ows:Value>
- <ows:Value>CQL_TEXT</ows:Value>
- </ows:Parameter>
- <ows:Constraint name="PostEncoding">
- <ows:Value>XML</ows:Value>
- </ows:Constraint>
- <ows:Constraint name="SupportedISOQueryables">
- <ows:Value>Operation</ows:Value>
- <ows:Value>Format</ows:Value>
- <ows:Value>OrganisationName</ows:Value>
- <ows:Value>Type</ows:Value>
- <ows:Value>ServiceType</ows:Value>
- <ows:Value>DistanceValue</ows:Value>
- <ows:Value>ResourceLanguage</ows:Value>
- <ows:Value>RevisionDate</ows:Value>
- <ows:Value>OperatesOn</ows:Value>
- <ows:Value>GeographicDescriptionCode</ows:Value>
- <ows:Value>AnyText</ows:Value>
- <ows:Value>Modified</ows:Value>
- <ows:Value>PublicationDate</ows:Value>
- <ows:Value>ResourceIdentifier</ows:Value>
- <ows:Value>ParentIdentifier</ows:Value>
- <ows:Value>Identifier</ows:Value>
- <ows:Value>CouplingType</ows:Value>
- <ows:Value>TopicCategory</ows:Value>
- <ows:Value>OperatesOnIdentifier</ows:Value>
- <ows:Value>ServiceTypeVersion</ows:Value>
- <ows:Value>TempExtent_end</ows:Value>
- <ows:Value>Subject</ows:Value>
- <ows:Value>CreationDate</ows:Value>
- <ows:Value>OperatesOnName</ows:Value>
- <ows:Value>Title</ows:Value>
- <ows:Value>DistanceUOM</ows:Value>
- <ows:Value>Denominator</ows:Value>
- <ows:Value>AlternateTitle</ows:Value>
- <ows:Value>Language</ows:Value>
- <ows:Value>TempExtent_begin</ows:Value>
- <ows:Value>HasSecurityConstraints</ows:Value>
- <ows:Value>KeywordType</ows:Value>
- <ows:Value>Abstract</ows:Value>
- </ows:Constraint>
- <ows:Constraint name="AdditionalQueryables">
- <ows:Value>SpecificationDate</ows:Value>
- <ows:Value>ConditionApplyingToAccessAndUse</ows:Value>
- <ows:Value>AccessConstraints</ows:Value>
- <ows:Value>OnlineResourceMimeType</ows:Value>
- <ows:Value>MetadataPointOfContact</ows:Value>
- <ows:Value>SpecificationDateType</ows:Value>
- <ows:Value>Classification</ows:Value>
- <ows:Value>OtherConstraints</ows:Value>
- <ows:Value>OnlineResourceType</ows:Value>
- <ows:Value>Degree</ows:Value>
- <ows:Value>Lineage</ows:Value>
- <ows:Value>SpecificationTitle</ows:Value>
- </ows:Constraint>
- </ows:Operation>
- <ows:Operation name="GetRecordById">
- <ows:DCP>
- <ows:HTTP>
- <ows:Get xlink:href="http://localhost:8080/geonetwork/srv/en/csw" />
- <ows:Post xlink:href="http://localhost:8080/geonetwork/srv/en/csw">
- <ows:Constraint name="PostEncoding">
- <ows:Value>XML</ows:Value>
- <ows:Value>SOAP</ows:Value>
- </ows:Constraint>
- </ows:Post>
- </ows:HTTP>
- </ows:DCP>
- <ows:Parameter name="outputSchema">
- <ows:Value>http://www.opengis.net/cat/csw/2.0.2</ows:Value>
- <ows:Value>http://www.isotc211.org/2005/gmd</ows:Value>
- </ows:Parameter>
- <ows:Parameter name="outputFormat">
- <ows:Value>application/xml</ows:Value>
- </ows:Parameter>
- <ows:Parameter name="resultType">
- <ows:Value>hits</ows:Value>
- <ows:Value>results</ows:Value>
- <ows:Value>validate</ows:Value>
- </ows:Parameter>
- <ows:Parameter name="ElementSetName">
- <ows:Value>brief</ows:Value>
- <ows:Value>summary</ows:Value>
- <ows:Value>full</ows:Value>
- </ows:Parameter>
- <ows:Constraint name="PostEncoding">
- <ows:Value>XML</ows:Value>
- </ows:Constraint>
- </ows:Operation>
- <ows:Operation name="Transaction">
- <ows:DCP>
- <ows:HTTP>
- <ows:Get xlink:href="http://localhost:8080/geonetwork/srv/en/csw" />
- <ows:Post xlink:href="http://localhost:8080/geonetwork/srv/en/csw" />
- </ows:HTTP>
- </ows:DCP>
- </ows:Operation>
- <!--
- <ows:Operation name="Harvest">
- <ows:DCP>
- <ows:HTTP>
- <ows:Get xlink:href="http://$HOST:$PORT$SERVLET/srv/en/csw" />
- <ows:Post xlink:href="http://$HOST:$PORT$SERVLET/srv/en/csw" />
- </ows:HTTP>
- </ows:DCP>
- </ows:Operation>
--->
- <ows:Parameter name="service">
- <ows:Value>http://www.opengis.net/cat/csw/2.0.2</ows:Value>
- </ows:Parameter>
- <ows:Parameter name="version">
- <ows:Value>2.0.2</ows:Value>
- </ows:Parameter>
- <ows:Constraint name="IsoProfiles">
- <ows:Value>http://www.isotc211.org/2005/gmd</ows:Value>
- </ows:Constraint>
- <ows:Constraint name="PostEncoding">
- <ows:Value>SOAP</ows:Value>
- </ows:Constraint>
- </ows:OperationsMetadata>
- <ogc:Filter_Capabilities>
- <ogc:Spatial_Capabilities>
- <ogc:GeometryOperands>
- <ogc:GeometryOperand>gml:Envelope</ogc:GeometryOperand>
- <ogc:GeometryOperand>gml:Point</ogc:GeometryOperand>
- <ogc:GeometryOperand>gml:LineString</ogc:GeometryOperand>
- <ogc:GeometryOperand>gml:Polygon</ogc:GeometryOperand>
- </ogc:GeometryOperands>
- <ogc:SpatialOperators>
- <ogc:SpatialOperator name="BBOX" />
- <ogc:SpatialOperator name="Equals" />
- <ogc:SpatialOperator name="Overlaps" />
- <ogc:SpatialOperator name="Disjoint" />
- <ogc:SpatialOperator name="Intersects" />
- <ogc:SpatialOperator name="Touches" />
- <ogc:SpatialOperator name="Crosses" />
- <ogc:SpatialOperator name="Within" />
- <ogc:SpatialOperator name="Contains" />
- <!--
- <ogc:SpatialOperator name="Beyond"/>
- <ogc:SpatialOperator name="DWithin"/>
- The 'SpatialOperator' element can have a GeometryOperands child -->
- </ogc:SpatialOperators>
- </ogc:Spatial_Capabilities>
- <ogc:Scalar_Capabilities>
- <ogc:LogicalOperators />
- <ogc:ComparisonOperators>
- <ogc:ComparisonOperator>EqualTo</ogc:ComparisonOperator>
- <ogc:ComparisonOperator>Like</ogc:ComparisonOperator>
- <ogc:ComparisonOperator>LessThan</ogc:ComparisonOperator>
- <ogc:ComparisonOperator>GreaterThan</ogc:ComparisonOperator>
- <!-- LessThanOrEqualTo is in OGC Filter Spec, LessThanEqualTo is in OGC CSW schema -->
- <ogc:ComparisonOperator>LessThanEqualTo</ogc:ComparisonOperator>
- <ogc:ComparisonOperator>LessThanOrEqualTo</ogc:ComparisonOperator>
- <!-- GreaterThanOrEqualTo is in OGC Filter Spec, GreaterThanEqualTo is in OGC CSW schema -->
- <ogc:ComparisonOperator>GreaterThanEqualTo</ogc:ComparisonOperator>
- <ogc:ComparisonOperator>GreaterThanOrEqualTo</ogc:ComparisonOperator>
- <ogc:ComparisonOperator>NotEqualTo</ogc:ComparisonOperator>
- <ogc:ComparisonOperator>Between</ogc:ComparisonOperator>
- <ogc:ComparisonOperator>NullCheck</ogc:ComparisonOperator>
- <!-- FIXME : Check NullCheck operation is available -->
- </ogc:ComparisonOperators>
- </ogc:Scalar_Capabilities>
- <ogc:Id_Capabilities>
- <ogc:EID />
- <ogc:FID />
- </ogc:Id_Capabilities>
- </ogc:Filter_Capabilities>
-</csw:Capabilities>"""
-
- get_records_request_xml = """<?xml version="1.0"?>
-<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2"
- xmlns:gmd="http://www.isotc211.org/2005/gmd" service="CSW" version="2.0.2" resultType="results">
- <csw:Query typeNames="gmd:MD_Metadata">
- <csw:ElementName>dc:identifier</csw:ElementName>
- <csw:Constraint version="1.1.0">
- <Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"/>
- </csw:Constraint>
- </csw:Query>
-</csw:GetRecords>"""
-
- get_records_response_xml = """<?xml version="1.0" encoding="UTF-8"?>
-<csw:GetRecordsResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd">
- <csw:SearchStatus timestamp="2010-10-21T14:54:45" />
- <csw:SearchResults numberOfRecordsMatched="3" numberOfRecordsReturned="3" elementSet="summary" nextRecord="0">
- <csw:Record xmlns:geonet="http://www.fao.org/geonetwork" xmlns:ows="http://www.opengis.net/ows" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dct="http://purl.org/dc/terms/">
- <dc:identifier>521ca63d-dad9-43fe-aebe-1138ffee530f</dc:identifier>
- </csw:Record>
- <csw:Record xmlns:geonet="http://www.fao.org/geonetwork" xmlns:ows="http://www.opengis.net/ows" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dct="http://purl.org/dc/terms/">
- <dc:identifier>8dc2dddd-e483-4c1a-9482-eb05e8e4314d</dc:identifier>
- </csw:Record>
- <csw:Record xmlns:geonet="http://www.fao.org/geonetwork" xmlns:ows="http://www.opengis.net/ows" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dct="http://purl.org/dc/terms/">
- <dc:identifier>8d2aaadd-6ad8-41e0-9cd3-ef743ba19887</dc:identifier>
- </csw:Record>
- </csw:SearchResults>
-</csw:GetRecordsResponse>"""
-
- get_record_by_id_request_xml1 = """<?xml version="1.0"?>
-<csw:GetRecordById xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2"
- outputSchema="csw:IsoRecord">
- <csw:Id>8dc2dddd-e483-4c1a-9482-eb05e8e4314d</csw:Id>
-</csw:GetRecordById>"""
-
- get_record_by_id_response_xml1 = """<?xml version="1.0" encoding="UTF-8"?>
-<csw:GetRecordByIdResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2">
- <gmd:MD_Metadata xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gsr="http://www.isotc211.org/2005/gsr" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gss="http://www.isotc211.org/2005/gss" xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:geonet="http://www.fao.org/geonetwork">
- <gmd:fileIdentifier xmlns:gml="http://www.opengis.net/gml" xmlns:srv="http://www.isotc211.org/2005/srv">
- <gco:CharacterString>8dc2dddd-e483-4c1a-9482-eb05e8e4314d</gco:CharacterString>
- </gmd:fileIdentifier>
- <gmd:language>
- <gmd:LanguageCode codeList="http://www.loc.gov/standards/iso639-2/php/code_list.php" codeListValue="eng">eng</gmd:LanguageCode>
- </gmd:language>
- <gmd:hierarchyLevel>
- <gmd:MD_ScopeCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#MD_ScopeCode" codeListValue="dataset" />
- </gmd:hierarchyLevel>
- <gmd:dateStamp>
- <gco:DateTime xmlns:gml="http://www.opengis.net/gml" xmlns:srv="http://www.isotc211.org/2005/srv">2010-10-18T18:51:08</gco:DateTime>
- </gmd:dateStamp>
- <gmd:referenceSystemInfo>
- <gmd:MD_ReferenceSystem>
- <gmd:referenceSystemIdentifier>
- <gmd:RS_Identifier>
- <gmd:code>
- <gco:CharacterString>urn:ogc:def:crs:EPSG::4258</gco:CharacterString>
- </gmd:code>
- </gmd:RS_Identifier>
- </gmd:referenceSystemIdentifier>
- </gmd:MD_ReferenceSystem>
- </gmd:referenceSystemInfo>
- <gmd:identificationInfo>
- <gmd:MD_DataIdentification>
- <gmd:citation>
- <gmd:CI_Citation>
- <gmd:title>
- <gco:CharacterString>CKAN Dataset Example 1</gco:CharacterString>
- </gmd:title>
- <gmd:date>
- <gmd:CI_Date>
- <gmd:date>
- <gco:Date>2010-07-16</gco:Date>
- </gmd:date>
- <gmd:dateType>
- <gmd:CI_DateTypeCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#CI_DateTypeCode" codeListValue="revision" />
- </gmd:dateType>
- </gmd:CI_Date>
- </gmd:date>
- <gmd:identifier>
- <gmd:RS_Identifier>
- <gmd:code>
- <gco:CharacterString>Please enter the unique identifier of the dataset</gco:CharacterString>
- </gmd:code>
- <gmd:codeSpace>
- <gco:CharacterString>Please enter the code space of the unique identifier of the dataset</gco:CharacterString>
- </gmd:codeSpace>
- </gmd:RS_Identifier>
- </gmd:identifier>
- </gmd:CI_Citation>
- </gmd:citation>
- <gmd:abstract>
- <gco:CharacterString>This is just an example metadata record, created for the purpose of developing CKAN CSW client capabilities.</gco:CharacterString>
- </gmd:abstract>
- <gmd:pointOfContact>
- <gmd:CI_ResponsibleParty>
- <gmd:organisationName>
- <gco:CharacterString>Please enter an organisation name for responsible organisation one</gco:CharacterString>
- </gmd:organisationName>
- <gmd:positionName>
- <gco:CharacterString>Please enter a position name for responsible organisation one</gco:CharacterString>
- </gmd:positionName>
- <gmd:contactInfo>
- <gmd:CI_Contact>
- <gmd:address>
- <gmd:CI_Address>
- <gmd:electronicMailAddress>
- <gco:CharacterString>john.bywater at appropriatesoftware.net</gco:CharacterString>
- </gmd:electronicMailAddress>
- </gmd:CI_Address>
- </gmd:address>
- </gmd:CI_Contact>
- </gmd:contactInfo>
- <gmd:role>
- <gmd:CI_RoleCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#CI_RoleCode" codeListValue="distributor" />
- </gmd:role>
- </gmd:CI_ResponsibleParty>
- </gmd:pointOfContact>
- <gmd:pointOfContact>
- <gmd:CI_ResponsibleParty>
- <gmd:organisationName>
- <gco:CharacterString>Please enter an organisation name for responsible organisation two</gco:CharacterString>
- </gmd:organisationName>
- <gmd:contactInfo>
- <gmd:CI_Contact>
- <gmd:address>
- <gmd:CI_Address>
- <gmd:electronicMailAddress>
- <gco:CharacterString>john.bywater at appropriatesoftware.net</gco:CharacterString>
- </gmd:electronicMailAddress>
- </gmd:CI_Address>
- </gmd:address>
- </gmd:CI_Contact>
- </gmd:contactInfo>
- <gmd:role>
- <gmd:CI_RoleCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#CI_RoleCode" codeListValue="pointOfContact" />
- </gmd:role>
- </gmd:CI_ResponsibleParty>
- </gmd:pointOfContact>
- <gmd:resourceConstraints>
- <gmd:MD_LegalConstraints>
- <gmd:accessConstraints>
- <gmd:MD_RestrictionCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#MD_RestrictionCode" codeListValue="otherRestrictions" />
- </gmd:accessConstraints>
- </gmd:MD_LegalConstraints>
- </gmd:resourceConstraints>
- <gmd:resourceConstraints>
- <gmd:MD_Constraints>
- <gmd:useLimitation>
- <gco:CharacterString>Use limitation</gco:CharacterString>
- </gmd:useLimitation>
- </gmd:MD_Constraints>
- </gmd:resourceConstraints>
- <gmd:spatialResolution>
- <gmd:MD_Resolution>
- <gmd:distance>
- <gco:Distance uom="m">1</gco:Distance>
- </gmd:distance>
- </gmd:MD_Resolution>
- </gmd:spatialResolution>
- <gmd:spatialResolution>
- <gmd:MD_Resolution>
- <gmd:equivalentScale>
- <gmd:MD_RepresentativeFraction>
- <gmd:denominator>
- <gco:Integer>5000</gco:Integer>
- </gmd:denominator>
- </gmd:MD_RepresentativeFraction>
- </gmd:equivalentScale>
- </gmd:MD_Resolution>
- </gmd:spatialResolution>
- <gmd:language>
- <gmd:LanguageCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#LanguageCode" codeListValue="eng" />
- </gmd:language>
- <gmd:topicCategory>
- <gmd:MD_TopicCategoryCode>intelligenceMilitary</gmd:MD_TopicCategoryCode>
- </gmd:topicCategory>
- <gmd:extent>
- <gmd:EX_Extent>
- <gmd:geographicElement>
- <gmd:EX_GeographicBoundingBox>
- <gmd:westBoundLongitude>
- <gco:Decimal>-5.4457177734375</gco:Decimal>
- </gmd:westBoundLongitude>
- <gmd:southBoundLatitude>
- <gco:Decimal>50.115576171875</gco:Decimal>
- </gmd:southBoundLatitude>
- <gmd:eastBoundLongitude>
- <gco:Decimal>-5.0721826171875</gco:Decimal>
- </gmd:eastBoundLongitude>
- <gmd:northBoundLatitude>
- <gco:Decimal>50.428686523437</gco:Decimal>
- </gmd:northBoundLatitude>
- </gmd:EX_GeographicBoundingBox>
- </gmd:geographicElement>
- </gmd:EX_Extent>
- </gmd:extent>
- </gmd:MD_DataIdentification>
- </gmd:identificationInfo>
- <gmd:distributionInfo>
- <gmd:MD_Distribution>
- <gmd:distributionFormat>
- <gmd:MD_Format>
- <gmd:name>
- <gco:CharacterString>Please enter the name of the format of the service</gco:CharacterString>
- </gmd:name>
- <gmd:version>
- <gco:CharacterString>Please enter the version of the format of the service</gco:CharacterString>
- </gmd:version>
- </gmd:MD_Format>
- </gmd:distributionFormat>
- <gmd:transferOptions>
- <gmd:MD_DigitalTransferOptions>
- <gmd:onLine>
- <gmd:CI_OnlineResource>
- <gmd:linkage>
- <gmd:URL>http://appropriatesoftware.net/</gmd:URL>
- </gmd:linkage>
- </gmd:CI_OnlineResource>
- </gmd:onLine>
- <gmd:onLine>
- <gmd:CI_OnlineResource>
- <gmd:linkage>
- <gmd:URL>http://appropriatesoftware.net/</gmd:URL>
- </gmd:linkage>
- </gmd:CI_OnlineResource>
- </gmd:onLine>
- </gmd:MD_DigitalTransferOptions>
- </gmd:transferOptions>
- </gmd:MD_Distribution>
- </gmd:distributionInfo>
- <gmd:dataQualityInfo>
- <gmd:DQ_DataQuality>
- <gmd:lineage>
- <gmd:LI_Lineage>
- <gmd:statement>
- <gco:CharacterString>Please enter a statement describing the events or sources used in the construction of this dataset</gco:CharacterString>
- </gmd:statement>
- </gmd:LI_Lineage>
- </gmd:lineage>
- </gmd:DQ_DataQuality>
- </gmd:dataQualityInfo>
- </gmd:MD_Metadata>
-</csw:GetRecordByIdResponse>"""
-
- get_record_by_id_request_xml2 = """<?xml version="1.0"?>
-<csw:GetRecordById xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2"
- outputSchema="csw:IsoRecord">
- <csw:Id>521ca63d-dad9-43fe-aebe-1138ffee530f</csw:Id>
-</csw:GetRecordById>"""
-
- get_record_by_id_response_xml2 = """<?xml version="1.0" encoding="UTF-8"?>
-<csw:GetRecordByIdResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2">
- <gmd:MD_Metadata xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:gsr="http://www.isotc211.org/2005/gsr" xmlns:gss="http://www.isotc211.org/2005/gss" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:geonet="http://www.fao.org/geonetwork">
- <gmd:fileIdentifier xmlns:gml="http://www.opengis.net/gml" xmlns:srv="http://www.isotc211.org/2005/srv">
- <gco:CharacterString>521ca63d-dad9-43fe-aebe-1138ffee530f</gco:CharacterString>
- </gmd:fileIdentifier>
- <gmd:language>
- <gmd:LanguageCode codeList="http://www.loc.gov/standards/iso639-2/php/code_list.php" codeListValue="eng">eng</gmd:LanguageCode>
- </gmd:language>
- <gmd:hierarchyLevel>
- <gmd:MD_ScopeCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#MD_ScopeCode" codeListValue="dataset" />
- </gmd:hierarchyLevel>
- <gmd:dateStamp>
- <gco:DateTime xmlns:gml="http://www.opengis.net/gml" xmlns:srv="http://www.isotc211.org/2005/srv">2010-10-12T16:02:48</gco:DateTime>
- </gmd:dateStamp>
- <gmd:referenceSystemInfo>
- <gmd:MD_ReferenceSystem>
- <gmd:referenceSystemIdentifier>
- <gmd:RS_Identifier>
- <gmd:code>
- <gco:CharacterString>urn:ogc:def:crs:EPSG::4258</gco:CharacterString>
- </gmd:code>
- </gmd:RS_Identifier>
- </gmd:referenceSystemIdentifier>
- </gmd:MD_ReferenceSystem>
- </gmd:referenceSystemInfo>
- <gmd:identificationInfo>
- <gmd:MD_DataIdentification>
- <gmd:citation>
- <gmd:CI_Citation>
- <gmd:title>
- <gco:CharacterString>Justin's Initial Demo Record.</gco:CharacterString>
- </gmd:title>
- <gmd:date>
- <gmd:CI_Date>
- <gmd:date>
- <gco:Date>2010-07-16</gco:Date>
- </gmd:date>
- <gmd:dateType>
- <gmd:CI_DateTypeCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#CI_DateTypeCode" codeListValue="revision" />
- </gmd:dateType>
- </gmd:CI_Date>
- </gmd:date>
- <gmd:identifier>
- <gmd:RS_Identifier>
- <gmd:code>
- <gco:CharacterString>Please enter the unique identifier of the dataset</gco:CharacterString>
- </gmd:code>
- <gmd:codeSpace>
- <gco:CharacterString>Please enter the code space of the unique identifier of the dataset</gco:CharacterString>
- </gmd:codeSpace>
- </gmd:RS_Identifier>
- </gmd:identifier>
- </gmd:CI_Citation>
- </gmd:citation>
- <gmd:abstract>
- <gco:CharacterString>Please enter an abstract, describing the data set more fully</gco:CharacterString>
- </gmd:abstract>
- <gmd:pointOfContact>
- <gmd:CI_ResponsibleParty>
- <gmd:organisationName>
- <gco:CharacterString>Please enter an organisation name for responsible organisation one</gco:CharacterString>
- </gmd:organisationName>
- <gmd:positionName>
- <gco:CharacterString>Please enter a position name for responsible organisation one</gco:CharacterString>
- </gmd:positionName>
- <gmd:contactInfo>
- <gmd:CI_Contact>
- <gmd:address>
- <gmd:CI_Address>
- <gmd:electronicMailAddress>
- <gco:CharacterString>Please enter an email address for responsible organisation one</gco:CharacterString>
- </gmd:electronicMailAddress>
- </gmd:CI_Address>
- </gmd:address>
- </gmd:CI_Contact>
- </gmd:contactInfo>
- <gmd:role>
- <gmd:CI_RoleCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#CI_RoleCode" codeListValue="distributor" />
- </gmd:role>
- </gmd:CI_ResponsibleParty>
- </gmd:pointOfContact>
- <gmd:pointOfContact>
- <gmd:CI_ResponsibleParty>
- <gmd:organisationName>
- <gco:CharacterString>Please enter an organisation name for responsible organisation two</gco:CharacterString>
- </gmd:organisationName>
- <gmd:contactInfo>
- <gmd:CI_Contact>
- <gmd:address>
- <gmd:CI_Address>
- <gmd:electronicMailAddress>
- <gco:CharacterString>Please enter an email address for responsible organisation two</gco:CharacterString>
- </gmd:electronicMailAddress>
- </gmd:CI_Address>
- </gmd:address>
- </gmd:CI_Contact>
- </gmd:contactInfo>
- <gmd:role>
- <gmd:CI_RoleCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#CI_RoleCode" codeListValue="pointOfContact" />
- </gmd:role>
- </gmd:CI_ResponsibleParty>
- </gmd:pointOfContact>
- <gmd:resourceConstraints>
- <gmd:MD_LegalConstraints>
- <gmd:accessConstraints>
- <gmd:MD_RestrictionCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#MD_RestrictionCode" codeListValue="otherRestrictions" />
- </gmd:accessConstraints>
- </gmd:MD_LegalConstraints>
- </gmd:resourceConstraints>
- <gmd:resourceConstraints>
- <gmd:MD_Constraints>
- <gmd:useLimitation>
- <gco:CharacterString>Use limitation</gco:CharacterString>
- </gmd:useLimitation>
- </gmd:MD_Constraints>
- </gmd:resourceConstraints>
- <gmd:spatialResolution>
- <gmd:MD_Resolution>
- <gmd:distance>
- <gco:Distance uom="urn:ogc:def:uom:EPSG::9001">Please enter the spatial resolution in metres</gco:Distance>
- </gmd:distance>
- </gmd:MD_Resolution>
- </gmd:spatialResolution>
- <gmd:spatialResolution>
- <gmd:MD_Resolution>
- <gmd:equivalentScale>
- <gmd:MD_RepresentativeFraction>
- <gmd:denominator>
- <gco:Integer>Please enter the denominator of the equivalent scale</gco:Integer>
- </gmd:denominator>
- </gmd:MD_RepresentativeFraction>
- </gmd:equivalentScale>
- </gmd:MD_Resolution>
- </gmd:spatialResolution>
- <gmd:language>
- <gmd:LanguageCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#LanguageCode" codeListValue="eng" />
- </gmd:language>
- <gmd:topicCategory>
- <gmd:MD_TopicCategoryCode />
- </gmd:topicCategory>
- <gmd:extent>
- <gmd:EX_Extent>
- <gmd:geographicElement>
- <gmd:EX_GeographicBoundingBox>
- <gmd:westBoundLongitude>
- <gco:Decimal>-8.17</gco:Decimal>
- </gmd:westBoundLongitude>
- <gmd:southBoundLatitude>
- <gco:Decimal>49.96</gco:Decimal>
- </gmd:southBoundLatitude>
- <gmd:eastBoundLongitude>
- <gco:Decimal>1.75</gco:Decimal>
- </gmd:eastBoundLongitude>
- <gmd:northBoundLatitude>
- <gco:Decimal>60.84</gco:Decimal>
- </gmd:northBoundLatitude>
- </gmd:EX_GeographicBoundingBox>
- </gmd:geographicElement>
- </gmd:EX_Extent>
- </gmd:extent>
- </gmd:MD_DataIdentification>
- </gmd:identificationInfo>
- <gmd:distributionInfo>
- <gmd:MD_Distribution>
- <gmd:distributionFormat>
- <gmd:MD_Format>
- <gmd:name>
- <gco:CharacterString>Please enter the name of the format of the service</gco:CharacterString>
- </gmd:name>
- <gmd:version>
- <gco:CharacterString>Please enter the version of the format of the service</gco:CharacterString>
- </gmd:version>
- </gmd:MD_Format>
- </gmd:distributionFormat>
- <gmd:transferOptions>
- <gmd:MD_DigitalTransferOptions>
- <gmd:onLine>
- <gmd:CI_OnlineResource>
- <gmd:linkage>
- <gmd:URL>Please enter the url for further information about the dataset</gmd:URL>
- </gmd:linkage>
- </gmd:CI_OnlineResource>
- </gmd:onLine>
- <gmd:onLine>
- <gmd:CI_OnlineResource>
- <gmd:linkage>
- <gmd:URL>Please enter the url for the dataset</gmd:URL>
- </gmd:linkage>
- </gmd:CI_OnlineResource>
- </gmd:onLine>
- </gmd:MD_DigitalTransferOptions>
- </gmd:transferOptions>
- </gmd:MD_Distribution>
- </gmd:distributionInfo>
- <gmd:dataQualityInfo>
- <gmd:DQ_DataQuality>
- <gmd:lineage>
- <gmd:LI_Lineage>
- <gmd:statement>
- <gco:CharacterString>Please enter a statement describing the events or sources used in the construction of this dataset</gco:CharacterString>
- </gmd:statement>
- </gmd:LI_Lineage>
- </gmd:lineage>
- </gmd:DQ_DataQuality>
- </gmd:dataQualityInfo>
- </gmd:MD_Metadata>
-</csw:GetRecordByIdResponse>"""
-
- get_record_by_id_request_xml3 = """<?xml version="1.0"?>
-<csw:GetRecordById xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2"
- outputSchema="csw:IsoRecord">
- <csw:Id>8d2aaadd-6ad8-41e0-9cd3-ef743ba19887</csw:Id>
-</csw:GetRecordById>"""
-
- get_record_by_id_response_xml3 = """<?xml version="1.0" encoding="UTF-8"?>
-<csw:GetRecordByIdResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2">
- <gmd:MD_Metadata xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:gsr="http://www.isotc211.org/2005/gsr" xmlns:gss="http://www.isotc211.org/2005/gss" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:geonet="http://www.fao.org/geonetwork">
- <gmd:fileIdentifier xmlns:gml="http://www.opengis.net/gml" xmlns:srv="http://www.isotc211.org/2005/srv">
- <gco:CharacterString>8d2aaadd-6ad8-41e0-9cd3-ef743ba19887</gco:CharacterString>
- </gmd:fileIdentifier>
- <gmd:language>
- <gmd:LanguageCode codeList="http://www.loc.gov/standards/iso639-2/php/code_list.php" codeListValue="eng">eng</gmd:LanguageCode>
- </gmd:language>
- <gmd:hierarchyLevel>
- <gmd:MD_ScopeCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#MD_ScopeCode" codeListValue="dataset" />
- </gmd:hierarchyLevel>
- <gmd:dateStamp>
- <gco:DateTime xmlns:gml="http://www.opengis.net/gml" xmlns:srv="http://www.isotc211.org/2005/srv">2010-10-21T11:44:10</gco:DateTime>
- </gmd:dateStamp>
- <gmd:referenceSystemInfo>
- <gmd:MD_ReferenceSystem>
- <gmd:referenceSystemIdentifier>
- <gmd:RS_Identifier>
- <gmd:code>
- <gco:CharacterString>urn:ogc:def:crs:EPSG::4258</gco:CharacterString>
- </gmd:code>
- </gmd:RS_Identifier>
- </gmd:referenceSystemIdentifier>
- </gmd:MD_ReferenceSystem>
- </gmd:referenceSystemInfo>
- <gmd:identificationInfo>
- <gmd:MD_DataIdentification>
- <gmd:citation>
- <gmd:CI_Citation>
- <gmd:title>
- <gco:CharacterString>Testing bug 62 - temporal extents</gco:CharacterString>
- </gmd:title>
- <gmd:date>
- <gmd:CI_Date>
- <gmd:date>
- <gco:Date>2010-07-16</gco:Date>
- </gmd:date>
- <gmd:dateType>
- <gmd:CI_DateTypeCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#CI_DateTypeCode" codeListValue="revision" />
- </gmd:dateType>
- </gmd:CI_Date>
- </gmd:date>
- <gmd:identifier>
- <gmd:RS_Identifier>
- <gmd:code>
- <gco:CharacterString>Please enter the unique identifier of the dataset</gco:CharacterString>
- </gmd:code>
- <gmd:codeSpace>
- <gco:CharacterString>Please enter the code space of the unique identifier of the dataset</gco:CharacterString>
- </gmd:codeSpace>
- </gmd:RS_Identifier>
- </gmd:identifier>
- </gmd:CI_Citation>
- </gmd:citation>
- <gmd:abstract>
- <gco:CharacterString>Please enter an abstract, describing the data set more fully</gco:CharacterString>
- </gmd:abstract>
- <gmd:pointOfContact>
- <gmd:CI_ResponsibleParty>
- <gmd:organisationName>
- <gco:CharacterString>Please enter an organisation name for responsible organisation one</gco:CharacterString>
- </gmd:organisationName>
- <gmd:positionName>
- <gco:CharacterString>Please enter a position name for responsible organisation one</gco:CharacterString>
- </gmd:positionName>
- <gmd:contactInfo>
- <gmd:CI_Contact>
- <gmd:address>
- <gmd:CI_Address>
- <gmd:electronicMailAddress>
- <gco:CharacterString>Please enter an email address for responsible organisation one</gco:CharacterString>
- </gmd:electronicMailAddress>
- </gmd:CI_Address>
- </gmd:address>
- </gmd:CI_Contact>
- </gmd:contactInfo>
- <gmd:role>
- <gmd:CI_RoleCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#CI_RoleCode" codeListValue="distributor" />
- </gmd:role>
- </gmd:CI_ResponsibleParty>
- </gmd:pointOfContact>
- <gmd:pointOfContact>
- <gmd:CI_ResponsibleParty>
- <gmd:organisationName>
- <gco:CharacterString>Please enter an organisation name for responsible organisation two</gco:CharacterString>
- </gmd:organisationName>
- <gmd:contactInfo>
- <gmd:CI_Contact>
- <gmd:address>
- <gmd:CI_Address>
- <gmd:electronicMailAddress>
- <gco:CharacterString>Please enter an email address for responsible organisation two</gco:CharacterString>
- </gmd:electronicMailAddress>
- </gmd:CI_Address>
- </gmd:address>
- </gmd:CI_Contact>
- </gmd:contactInfo>
- <gmd:role>
- <gmd:CI_RoleCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#CI_RoleCode" codeListValue="pointOfContact" />
- </gmd:role>
- </gmd:CI_ResponsibleParty>
- </gmd:pointOfContact>
- <gmd:resourceConstraints>
- <gmd:MD_LegalConstraints>
- <gmd:accessConstraints>
- <gmd:MD_RestrictionCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#MD_RestrictionCode" codeListValue="otherRestrictions" />
- </gmd:accessConstraints>
- </gmd:MD_LegalConstraints>
- </gmd:resourceConstraints>
- <gmd:resourceConstraints>
- <gmd:MD_Constraints>
- <gmd:useLimitation>
- <gco:CharacterString>Use limitation</gco:CharacterString>
- </gmd:useLimitation>
- </gmd:MD_Constraints>
- </gmd:resourceConstraints>
- <gmd:spatialResolution>
- <gmd:MD_Resolution>
- <gmd:distance>
- <gco:Distance uom="urn:ogc:def:uom:EPSG::9001">Please enter the spatial resolution in metres</gco:Distance>
- </gmd:distance>
- </gmd:MD_Resolution>
- </gmd:spatialResolution>
- <gmd:spatialResolution>
- <gmd:MD_Resolution>
- <gmd:equivalentScale>
- <gmd:MD_RepresentativeFraction>
- <gmd:denominator>
- <gco:Integer>Please enter the denominator of the equivalent scale</gco:Integer>
- </gmd:denominator>
- </gmd:MD_RepresentativeFraction>
- </gmd:equivalentScale>
- </gmd:MD_Resolution>
- </gmd:spatialResolution>
- <gmd:language>
- <gmd:LanguageCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#LanguageCode" codeListValue="eng" />
- </gmd:language>
- <gmd:topicCategory>
- <gmd:MD_TopicCategoryCode />
- </gmd:topicCategory>
- <gmd:extent>
- <gmd:EX_Extent>
- <gmd:geographicElement>
- <gmd:EX_GeographicBoundingBox>
- <gmd:westBoundLongitude>
- <gco:Decimal>-8.17</gco:Decimal>
- </gmd:westBoundLongitude>
- <gmd:southBoundLatitude>
- <gco:Decimal>49.96</gco:Decimal>
- </gmd:southBoundLatitude>
- <gmd:eastBoundLongitude>
- <gco:Decimal>1.75</gco:Decimal>
- </gmd:eastBoundLongitude>
- <gmd:northBoundLatitude>
- <gco:Decimal>60.84</gco:Decimal>
- </gmd:northBoundLatitude>
- </gmd:EX_GeographicBoundingBox>
- </gmd:geographicElement>
- </gmd:EX_Extent>
- </gmd:extent>
- </gmd:MD_DataIdentification>
- </gmd:identificationInfo>
- <gmd:distributionInfo>
- <gmd:MD_Distribution>
- <gmd:distributionFormat>
- <gmd:MD_Format>
- <gmd:name>
- <gco:CharacterString>Please enter the name of the format of the service</gco:CharacterString>
- </gmd:name>
- <gmd:version>
- <gco:CharacterString>Please enter the version of the format of the service</gco:CharacterString>
- </gmd:version>
- </gmd:MD_Format>
- </gmd:distributionFormat>
- <gmd:transferOptions>
- <gmd:MD_DigitalTransferOptions>
- <gmd:onLine>
- <gmd:CI_OnlineResource>
- <gmd:linkage>
- <gmd:URL>Please enter the url for further information about the dataset</gmd:URL>
- </gmd:linkage>
- </gmd:CI_OnlineResource>
- </gmd:onLine>
- <gmd:onLine>
- <gmd:CI_OnlineResource>
- <gmd:linkage>
- <gmd:URL>Please enter the url for the dataset</gmd:URL>
- </gmd:linkage>
- </gmd:CI_OnlineResource>
- </gmd:onLine>
- </gmd:MD_DigitalTransferOptions>
- </gmd:transferOptions>
- </gmd:MD_Distribution>
- </gmd:distributionInfo>
- <gmd:dataQualityInfo>
- <gmd:DQ_DataQuality>
- <gmd:lineage>
- <gmd:LI_Lineage>
- <gmd:statement>
- <gco:CharacterString>Please enter a statement describing the events or sources used in the construction of this dataset</gco:CharacterString>
- </gmd:statement>
- </gmd:LI_Lineage>
- </gmd:lineage>
- </gmd:DQ_DataQuality>
- </gmd:dataQualityInfo>
- </gmd:MD_Metadata>
-</csw:GetRecordByIdResponse>"""
-
- map = {
- get_capabilities_request_xml: get_capabilities_response_xml,
- get_records_request_xml: get_records_response_xml,
- get_record_by_id_request_xml1: get_record_by_id_response_xml1,
- get_record_by_id_request_xml2: get_record_by_id_response_xml2,
- get_record_by_id_request_xml3: get_record_by_id_response_xml3,
- }
-
- def check_capabilities(self): pass
-
- def login(self): pass
-
- def logout(self): pass
-
- def send(self, csw_request):
- csw_request_xml = self.get_xml_from_csw_request(csw_request)
- if csw_request_xml in self.map:
- csw_response_xml = self.map[csw_request_xml]
- else:
- msg = "Mock send() method can't handle request: %s" % csw_request_xml
- raise Exception, msg
- return csw_response_xml
-
-
--- a/ckan/tests/lib/test_cswclient.py Thu Jun 23 16:45:20 2011 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,251 +0,0 @@
-from ckan.tests import CheckMethods
-from ckan.tests import SkipTest
-from pylons import config
-
-from ckan.lib.cswclient import CswError
-from ckan.lib.cswclient import CswGetCapabilities
-from ckan.lib.cswclient import CswGetRecords
-from ckan.lib.cswclient import CswGetRecordById
-from ckan.lib.cswclient import CswClient
-from ckan.lib.cswclient import GeoNetworkClient
-from mock_cswclient import MockGeoNetworkClient
-
-import socket
-socket.setdefaulttimeout(1)
-
-class CswRequestTestCase(CheckMethods):
-
- request_class = None
- request_params = {}
- expect_xml = ""
-
- def setup(self):
- self.request = self.make_request()
-
- def teardown(self):
- self.request = None
-
- def make_request(self):
- if not self.request_class:
- msg = "Test case '%s' has no request_class." % self.__class__
- raise Exception, msg
- return self.request_class(**self.request_params)
-
- def test_msg(self):
- request_xml = self.request.get_xml()
- self.assert_equal(request_xml, self.expect_xml)
-
-
-class TestCswGetCapabilities(CswRequestTestCase):
-
- request_class = CswGetCapabilities
- request_params = {}
- expect_xml = """<?xml version="1.0"?>
-<csw:GetCapabilities xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW">
- <ows:AcceptVersions xmlns:ows="http://www.opengis.net/ows">
- <ows:Version>2.0.2</ows:Version>
- </ows:AcceptVersions>
- <ows:AcceptFormats xmlns:ows="http://www.opengis.net/ows">
- <ows:OutputFormat>application/xml</ows:OutputFormat>
- </ows:AcceptFormats>
-</csw:GetCapabilities>"""
-
-
-class TestCswGetRecords(CswRequestTestCase):
-
- request_class = CswGetRecords
- request_params = {"result_type": "results"}
- expect_xml = """<?xml version="1.0"?>
-<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2"
- xmlns:gmd="http://www.isotc211.org/2005/gmd" service="CSW" version="2.0.2" resultType="results">
- <csw:Query typeNames="gmd:MD_Metadata">
- <csw:ElementName>dc:identifier</csw:ElementName>
- <csw:Constraint version="1.1.0">
- <Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"/>
- </csw:Constraint>
- </csw:Query>
-</csw:GetRecords>"""
-
-
-class TestCswGetRecordById(CswRequestTestCase):
-
- request_class = CswGetRecordById
- request_params = {"identifier": "000000000000000000000000000000000000000"}
- expect_xml = """<?xml version="1.0"?>
-<csw:GetRecordById xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2"
- outputSchema="csw:IsoRecord">
- <csw:Id>000000000000000000000000000000000000000</csw:Id>
-</csw:GetRecordById>"""
-
-
-class CswClientTestCase(CheckMethods):
-
- csw_client_class = CswClient
- base_url = ""
- username = ""
- password = ""
- max_records = 10
- expected_id = '8dc2dddd-e483-4c1a-9482-eb05e8e4314d'
-
- def setup(self):
- self.client = None
- self.client = self.create_csw_client()
- if self.username and self.password:
- self.client.login()
-
- def teardown(self):
- if self.username and self.password:
- if hasattr(self, 'client') and self.client:
- self.client.logout()
- self.client = None
-
- def create_csw_client(self):
- return self.csw_client_class(
- base_url=self.base_url,
- username=self.username,
- password=self.password,
- )
-
- def test_send_get_capabilities(self):
- xml = self.client.send_get_capabilities()
- self.assert_contains(xml, "csw:Capabilities")
-
- def test_assert_capabilities(self):
- self.client.assert_capabilities()
-
- def test_send_get_records(self):
- xml = self.client.send_get_records()
- self.assert_contains(xml, "GetRecordsResponse")
-
- def test_send_get_record_by_id(self):
- xml = self.client.send_get_record_by_id("8dc2dddd-e483-4c1a-9482-eb05e8e4314d")
- self.assert_contains(xml, "GetRecordByIdResponse")
-
- def test_get_record_by_id(self):
- xml = self.client.get_record_by_id("8dc2dddd-e483-4c1a-9482-eb05e8e4314d")
- self.assert_contains(xml, "gmd:MD_Metadata")
-
- def test_get_identifiers(self):
- ids = self.client.get_identifiers()
- self.assert_contains(ids, self.expected_id)
-
- def test_get_records(self):
- records = self.client.get_records(max_records=self.max_records)
- self.assert_true(len(records))
-
- def test_extract_identifiers(self):
- get_records_response = """<?xml version="1.0" encoding="UTF-8"?>
-<csw:GetRecordsResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd">
- <csw:SearchStatus timestamp="2010-10-21T23:38:53" />
- <csw:SearchResults numberOfRecordsMatched="3" numberOfRecordsReturned="3" elementSet="full" nextRecord="0">
- <csw:Record xmlns:geonet="http://www.fao.org/geonetwork" xmlns:ows="http://www.opengis.net/ows" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dct="http://purl.org/dc/terms/">
- <dc:identifier>521ca63d-dad9-43fe-aebe-1138ffee530f</dc:identifier>
- </csw:Record>
- <csw:Record xmlns:geonet="http://www.fao.org/geonetwork" xmlns:ows="http://www.opengis.net/ows" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dct="http://purl.org/dc/terms/">
- <dc:identifier>8dc2dddd-e483-4c1a-9482-eb05e8e4314d</dc:identifier>
- </csw:Record>
- <csw:Record xmlns:geonet="http://www.fao.org/geonetwork" xmlns:ows="http://www.opengis.net/ows" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dct="http://purl.org/dc/terms/">
- <dc:identifier>8d2aaadd-6ad8-41e0-9cd3-ef743ba19887</dc:identifier>
- </csw:Record>
- </csw:SearchResults>
-</csw:GetRecordsResponse>"""
- ids = self.client.extract_identifiers(get_records_response)
- self.assert_isinstance(ids, list)
- self.assert_len(ids, 3)
- self.assert_contains(ids, "521ca63d-dad9-43fe-aebe-1138ffee530f")
- self.assert_contains(ids, "8dc2dddd-e483-4c1a-9482-eb05e8e4314d")
- self.assert_contains(ids, "8d2aaadd-6ad8-41e0-9cd3-ef743ba19887")
-
-
-class BlankTests(CswClientTestCase):
-
- def test_send_get_capabilities(self): pass
-
- def test_assert_capabilities(self): pass
-
- def test_send_get_records(self): pass
-
- def test_send_get_record_by_id(self): pass
-
- def test_get_record_by_id(self): pass
-
- def test_get_identifiers(self): pass
-
- def test_get_records(self): pass
-
- def test_extract_identifiers(self): pass
-
-
-
-class GeoNetworkClientTestCase(CswClientTestCase):
-
- csw_client_class = GeoNetworkClient
-
-
-class TestGeoNetworkClient(GeoNetworkClientTestCase):
-
- csw_client_class = MockGeoNetworkClient
-
-
-class TestGeoNetworkClientSite(GeoNetworkClientTestCase):
-
- # Test with real example GeoNetwork site.
- base_url=config.get('example_csw_url', '')
- username=config.get('example_csw_username', '')
- password=config.get('example_csw_password', '')
-
- def setup(self):
- if not self.base_url:
- raise SkipTest
- super(TestGeoNetworkClientSite, self).setup()
-
-
-class TestGeoNetworkClientSiteNoAuth(TestGeoNetworkClientSite):
-
- # Test with real example GeoNetwork site.
- username = ''
- password = ''
- expected_id = '8d2aaadd-6ad8-41e0-9cd3-ef743ba19887'
-
-
-class TestGeoNetworkClientSiteBadAuth(BlankTests, TestGeoNetworkClientSite):
-
- username = 'mickey'
- password = 'mouse'
- expected_id = '8d2aaadd-6ad8-41e0-9cd3-ef743ba19887'
-
- # Since there is a bad username and password, setup will fail.
- def setup(self):
- super_method = super(TestGeoNetworkClientSiteBadAuth, self).setup
- self.assert_raises(CswError, super_method)
-
-
-class TestGeoNetworkClientSiteDown(BlankTests, GeoNetworkClientTestCase):
-
- base_url = 'http://128.0.0.1:44444'
- username = 'a'
- password = 'b'
-
- # Since there is a username and password, setup and teardown will fail.
- def setup(self):
- super_method = super(TestGeoNetworkClientSiteDown, self).setup
- self.assert_raises(CswError, super_method)
-
- def teardown(self):
- super_method = super(TestGeoNetworkClientSiteDown, self).teardown
- self.assert_raises(CswError, super_method)
-
-
-class TestGeoNetworkClientSiteDownNoAuth(BlankTests, GeoNetworkClientTestCase):
-
- base_url = 'http://128.0.0.1:44444'
- username = ''
- password = ''
-
- # Since there is no username and password, setup and teardown won't error.
-
- # However, the send methods won't work....
- def test_send_get_record_by_id(self):
- super_method = GeoNetworkClientTestCase.test_send_get_record_by_id
- self.assert_raises(CswError, super_method, self)
-
http://bitbucket.org/okfn/ckan/changeset/f24228ecdfac/
changeset: f24228ecdfac
branch: feature-1198-mailer
user: pudo
date: 2011-06-23 22:32:35
summary: [tests] and their tests..
affected #: 1 file (0 bytes)
--- a/ckan/tests/test_rdf.py Thu Jun 23 22:29:17 2011 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-from pylons import config
-import ckan.lib.helpers as h
-
-if 0: # DISABLED IMPORTS AND ALL TESTS
- import ckan.lib.rdf as rdf
- import ckan.lib.talis as talis
- from ckan.tests import *
- import ckan.model as model
-
-TALIS_STORE_NAME = 'ckan-dev1'
-
-class _TestRdf:
- @classmethod
- def setup_class(self):
- CreateTestData.create_search_test_data()
- self.rdf = rdf.RdfExporter()
- self.talis = talis.Talis()
- self.pkg_name = u'usa-courts-gov'
-
- @classmethod
- def teardown_class(self):
- model.Session.remove()
- model.repo.rebuild_db()
-
- def test_1_package(self):
- pkg = model.Package.by_name(self.pkg_name)
- out = self.rdf.export_package(pkg)
- assert pkg.name in out, out
-
- def test_2_post(self):
- pkg = model.Package.by_name(self.pkg_name)
- rdf_xml = self.rdf.export_package(pkg)
- service = '/meta'
- err = self.talis.post(service, rdf_xml, with_password=True)
- assert not err, err
-
- def test_2_upload_package(self):
- pkg = model.Package.by_name(self.pkg_name)
- err = self.talis.post_pkg(pkg)
- assert not err, err
-
- def test_3_download_package(self):
- res = self.talis.get_pkg(self.pkg_name)
- assert not isinstance(res, Exception), res
-
- pkg = model.Package.by_name(self.pkg_name)
- assert pkg.name in res, res
- assert pkg.title in res, res
-
- def test_3_get(self):
- uri = talis.TALIS_URI + TALIS_STORE_NAME + '/meta?about=%s&output=rdf' % (rdf.CKAN_SUBJECT_BASE + self.pkg_name)
- res = self.talis.get(uri)
- assert not isinstance(res, Exception), res
-
- pkg = model.Package.by_name(self.pkg_name)
- assert pkg.name in res, res
- assert pkg.title in res, res
-
-
http://bitbucket.org/okfn/ckan/changeset/582b7cfd394e/
changeset: 582b7cfd394e
branch: feature-1198-mailer
user: pudo
date: 2011-06-24 11:23:58
summary: [lib][s] basic mailer class
affected #: 2 files (2.9 KB)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ckan/lib/mailer.py Fri Jun 24 11:23:58 2011 +0200
@@ -0,0 +1,55 @@
+from datetime import datetime, timedelta
+import smtplib
+import logging
+from time import time
+
+from email.mime.text import MIMEText
+from email.header import Header
+from email import Utils
+
+from pylons.i18n.translation import _
+from pylons import config, g
+from ckan import __version__
+
+log = logging.getLogger(__name__)
+
+class MailerException(Exception):
+ pass
+
+def _mail_recipient(recipient_name, recipient_email,
+ sender_name, sender_url, subject,
+ body, headers={}):
+ mail_from = config.get('ckan.mail_from')
+ body = _(u"Dear %s,") % recipient_name \
+ + u"\r\n\r\n%s\r\n\r\n" % body \
+ + u"--\r\n%s (%s)" % (sender_name, sender_url)
+ msg = MIMEText(body.encode('utf-8'), 'plain', 'utf-8')
+ for k, v in headers.items(): msg[k] = v
+ subject = Header(subject.encode('utf-8'), 'utf-8')
+ msg['Subject'] = subject
+ msg['From'] = _("%s <%s>") % (sender_url, mail_from)
+ recipient = u"%s <%s>" % (recipient_name, recipient_email)
+ msg['To'] = Header(recipient, 'utf-8')
+ msg['Date'] = Utils.formatdate(time())
+ msg['X-Mailer'] = "CKAN %s" % __version__
+ try:
+ server = smtplib.SMTP(config.get('smtp_server', 'localhost'))
+ server.set_debuglevel(1)
+ server.sendmail(mail_from, [recipient_email], msg.as_string())
+ server.quit()
+ except Exception, e:
+ log.exception(e)
+ raise MailerException(e.message)
+
+def mail_recipient(recipient_name, recipient_email, subject,
+ body, headers={}):
+ return _mail_recipient(recipient_name, recipient_email,
+ g.site_title, g.site_url, subject, body, headers=headers)
+
+def mail_user(recipient, subject, body, headers={}):
+ if (recipient.email is None) and len(recipient.email):
+ raise MailerException(_("No recipient email address available!"))
+ mail_recipient(recipient.display_name, recipient.email, subject,
+ body, headers=headers)
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ckan/tests/test_mailer.py Fri Jun 24 11:23:58 2011 +0200
@@ -0,0 +1,29 @@
+"""
+"""
+from pylons import config
+from ckan.lib.mailer import _mail_recipient
+from ckan.tests import *
+
+from smtpd import SMTPServer
+
+class TestMailer(TestController):
+
+ def setup(self):
+ config['smtp_server'] = 'localhost:667511'
+ config['ckan.mail_from'] = 'info at ckan.net'
+ class TestSMTPServer(SMTPServer):
+ def process_message(zelf, peer, mailfrom, rcpttos, data):
+ print "FOO"
+ return self.process_message(peer, mailfrom, rcpttos, data)
+ self.server = TestSMTPServer(('localhost', 6675), None)
+
+ def test_mail_recipient(self):
+ # def tests(s, peer, mailfrom, rcpttos, data):
+ # assert 'info at ckan.net' in mailfrom
+ # assert 'foo at bar.com' in recpttos
+ # assert 'i am a banana' in data
+ # #self.process_message = tests
+ # _mail_recipient('fooman', 'foo at localhost',
+ # 'banaman', 'http://banana.com',
+ # 'i am a banana', 'this is a test')
+ pass
http://bitbucket.org/okfn/ckan/changeset/38ce50edc688/
changeset: 38ce50edc688
branch: feature-1198-mailer
user: pudo
date: 2011-06-24 12:44:47
summary: [controllers,templates,migration] web frontend for token-based password reset
affected #: 8 files (4.7 KB)
--- a/ckan/config/routing.py Fri Jun 24 11:23:58 2011 +0200
+++ b/ckan/config/routing.py Fri Jun 24 12:44:47 2011 +0200
@@ -230,10 +230,12 @@
# Note: openid users have slashes in their ids, so need the wildcard
# in the route.
map.connect('/user/edit/{id:.*}', controller='user', action='edit')
+ map.connect('/user/reset/{id:.*}', controller='user', action='perform_reset')
map.connect('/user/register', controller='user', action='register')
map.connect('/user/login', controller='user', action='login')
map.connect('/user/logged_in', controller='user', action='logged_in')
map.connect('/user/logged_out', controller='user', action='logged_out')
+ map.connect('/user/reset', controller='user', action='request_reset')
map.connect('/user/me', controller='user', action='me')
map.connect('/user/{id:.*}', controller='user', action='read')
map.connect('/user', controller='user', action='index')
--- a/ckan/controllers/user.py Fri Jun 24 11:23:58 2011 +0200
+++ b/ckan/controllers/user.py Fri Jun 24 12:44:47 2011 +0200
@@ -1,4 +1,3 @@
-import re
import logging
import genshi
@@ -7,6 +6,7 @@
import ckan.misc
from ckan.lib.base import *
+from ckan.lib import mailer
log = logging.getLogger(__name__)
@@ -183,7 +183,40 @@
h.redirect_to(controller='user', action='read', id=user.id)
return render('user/edit.html')
-
+
+ def request_reset(self):
+ if request.method == 'POST':
+ id = request.params.get('user')
+ user = model.User.get(id)
+ if user is None:
+ h.flash_error(_('No such user: %s') % id)
+ try:
+ mailer.send_reset_link(user)
+ h.flash_success(_('Please check your inbox for a reset code.'))
+ redirect('/')
+ except mailer.MailerException, e:
+ h.flash_error(_('Could not send reset link: %s') % unicode(e))
+ return render('user/request_reset.html')
+
+ def perform_reset(self, id):
+ user = model.User.get(id)
+ if user is None:
+ abort(404)
+ c.reset_key = request.params.get('key')
+ if not mailer.verify_reset_link(user, c.reset_key):
+ h.flash_error(_('Invalid reset key. Please try again.'))
+ abort(403)
+ if request.method == 'POST':
+ try:
+ user.password = self._get_form_password()
+ model.Session.add(user)
+ model.Session.commit()
+ h.flash_success(_("Your password has been reset."))
+ redirect('/')
+ except ValueError, ve:
+ h.flash_error(unicode(ve))
+ return render('user/perform_reset.html')
+
def _format_about(self, about):
about_formatted = ckan.misc.MarkdownFormat().to_html(about)
try:
--- a/ckan/lib/mailer.py Fri Jun 24 11:23:58 2011 +0200
+++ b/ckan/lib/mailer.py Fri Jun 24 12:44:47 2011 +0200
@@ -1,15 +1,16 @@
-from datetime import datetime, timedelta
import smtplib
import logging
+import uuid
from time import time
-
from email.mime.text import MIMEText
from email.header import Header
from email import Utils
+from urlparse import urljoin
from pylons.i18n.translation import _
from pylons import config, g
-from ckan import __version__
+from ckan import model, __version__
+from ckan.lib.helpers import url_for
log = logging.getLogger(__name__)
@@ -27,14 +28,14 @@
for k, v in headers.items(): msg[k] = v
subject = Header(subject.encode('utf-8'), 'utf-8')
msg['Subject'] = subject
- msg['From'] = _("%s <%s>") % (sender_url, mail_from)
+ msg['From'] = _("%s <%s>") % (sender_name, mail_from)
recipient = u"%s <%s>" % (recipient_name, recipient_email)
msg['To'] = Header(recipient, 'utf-8')
msg['Date'] = Utils.formatdate(time())
msg['X-Mailer'] = "CKAN %s" % __version__
try:
server = smtplib.SMTP(config.get('smtp_server', 'localhost'))
- server.set_debuglevel(1)
+ #server.set_debuglevel(1)
server.sendmail(mail_from, [recipient_email], msg.as_string())
server.quit()
except Exception, e:
@@ -53,3 +54,33 @@
body, headers=headers)
+def make_key():
+ return uuid.uuid4().hex[:10]
+
+RESET_LINK_MESSAGE = _(
+'''You have requested your password on %(site_title)s to be reset.
+
+Please click the following link to confirm this request:
+
+ %(reset_link)s
+''')
+
+def send_reset_link(user):
+ user.reset_key = make_key()
+ model.Session.add(user)
+ model.Session.commit()
+ d = {
+ 'reset_link': urljoin(g.site_url, url_for(controller='user',
+ action='perform_reset', id=user.id, key=user.reset_key)),
+ 'site_title': g.site_title
+ }
+ body = RESET_LINK_MESSAGE % d
+ mail_user(user, _('Reset your password'), body)
+
+def verify_reset_link(user, key):
+ if not user.reset_key or len(user.reset_key) < 5:
+ return False
+ return key.strip() == user.reset_key
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ckan/migration/versions/040_reset_key_on_user.py Fri Jun 24 12:44:47 2011 +0200
@@ -0,0 +1,13 @@
+from sqlalchemy import *
+from migrate import *
+
+def upgrade(migrate_engine):
+ metadata = MetaData()
+ metadata.bind = migrate_engine
+ user_table = Table('user', metadata, autoload=True)
+ reset_key_col = Column('reset_key', UnicodeText)
+ reset_key_col.create(user_table)
+
+def downgrade(migrate_engine):
+ raise NotImplementedError()
+
--- a/ckan/model/user.py Fri Jun 24 11:23:58 2011 +0200
+++ b/ckan/model/user.py Fri Jun 24 12:44:47 2011 +0200
@@ -18,6 +18,7 @@
Column('email', UnicodeText),
Column('apikey', UnicodeText, default=make_uuid),
Column('created', DateTime, default=datetime.datetime.now),
+ Column('reset_key', UnicodeText),
Column('about', UnicodeText),
)
--- a/ckan/templates/user/login.html Fri Jun 24 11:23:58 2011 +0200
+++ b/ckan/templates/user/login.html Fri Jun 24 12:44:47 2011 +0200
@@ -23,6 +23,7 @@
</p><ul><li>${h.link_to(_('Register'), h.url_for(action='register'))}</li>
+ <li>${h.link_to(_('Reset your password'), h.url_for(action='request_reset'))}</li><li>${h.link_to(_('Privacy Policy'), 'http://www.okfn.org/privacy-policy/')}</li></ul></li>
@@ -44,7 +45,8 @@
<input type="password" name="password" value="" /><br/></fieldset>
- ${h.submit('s', _('Login'))}
+ ${h.submit('s', _('Login'))} —
+ <a href="${h.url_for('reset')}">Forgot your password?</a></form><!-- Simple OpenID Selector -->
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ckan/templates/user/perform_reset.html Fri Jun 24 12:44:47 2011 +0200
@@ -0,0 +1,34 @@
+<html xmlns:py="http://genshi.edgewall.org/"
+ xmlns:i18n="http://genshi.edgewall.org/i18n"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ py:strip="">
+
+ <py:def function="page_title">Reset your password</py:def>
+
+ <py:def function="optional_head">
+ <link rel="stylesheet" href="${g.site_url}/css/forms.css" type="text/css" media="screen, print" />
+ </py:def>
+
+ <div py:match="content">
+ <form id="user-reset" action="" method="post" class="simple-form"
+ xmlns:py="http://genshi.edgewall.org/"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ >
+ <fieldset>
+ <legend>Reset your password</legend>
+ <label for="password1">Password:</label>
+ <input type="password" name="password1" value="" />
+ <br/>
+ <label for="password2">Password (repeat):</label>
+ <input type="password" name="password2" value="" />
+ <br/>
+ </fieldset>
+ <div>
+ ${h.submit('save', _('Save'))}
+ </div>
+ </form>
+ </div>
+
+ <xi:include href="layout.html" />
+</html>
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ckan/templates/user/request_reset.html Fri Jun 24 12:44:47 2011 +0200
@@ -0,0 +1,35 @@
+<html xmlns:py="http://genshi.edgewall.org/"
+ xmlns:i18n="http://genshi.edgewall.org/i18n"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ py:strip="">
+
+ <py:def function="page_title">Reset password</py:def>
+
+ <py:def function="optional_head">
+ <link rel="stylesheet" href="${g.site_url}/css/forms.css" type="text/css" media="screen, print" />
+ </py:def>
+
+ <div py:match="content">
+ <h2>
+ Request a password reset
+ </h2>
+
+ <form id="user-edit" action="" method="post" class="simple-form"
+ xmlns:py="http://genshi.edgewall.org/"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ >
+ <fieldset>
+ <legend>Reset password</legend>
+ <label for="user">User name:</label>
+ <input name="user" value="" /><br/>
+ </fieldset>
+
+ <div>
+ ${h.submit('save', _('Reset password'))}
+ </div>
+ </form>
+ </div>
+
+ <xi:include href="layout.html" />
+</html>
+
Repository URL: https://bitbucket.org/okfn/ckan/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the ckan-changes
mailing list