Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_number_records(request):
parsed = etree.fromstring(request.content,
etree.XMLParser(resolve_entities=False))
search_param = '{http://www.opengis.net/cat/csw/2.0.2}SearchResults'
search_results = parsed.findall(search_param)[0]
return int(search_results.attrib['numberOfRecordsMatched'])
def test_bbox2wktpolygon(bbox, expected):
result = util.bbox2wktpolygon(bbox)
assert result == expected
def test_wkt2geom(wkt, bounds, expected):
result = util.wkt2geom(wkt, bounds=bounds)
assert result == expected
def test_clear_records(client):
response = client.delete('/catalog/{0}/csw'.format(catalog_slug))
assert 200 == response.status_code
assert 'removed' in response.content.decode('utf-8')
# Delete records in pycsw database.
context = config.StaticContext()
delete_records(context,
registry.PYCSW['repository']['database'],
registry.PYCSW['repository']['table'])
# Delete a catalog that has not been created previosuly.
response = client.delete('/catalog/boom/csw')
assert 404 == response.status_code
assert 'does not exist' in response.content.decode('utf-8')
normalize_identifier_fields: bool
Whether to normalize the identifier fields in responses. This
parameter is used only in the 'harvesting' and 'manager' suites
use_xml_canonicalisation: bool
Whether to compare results with their expected values by using xml
canonicalisation or simply by doing a diff.
save_results_directory: str
Path to a directory where to test results should be saved to. A value
of ``None`` (the default) means that results will not get saved to
disk.
"""
request_environment = _prepare_wsgi_test_environment(request_method,
request_data)
pycsw_server = server.Csw(rtconfig=configuration, env=request_environment)
encoding = "utf-8"
status, raw_contents = pycsw_server.dispatch_wsgi()
contents = raw_contents.decode(encoding)
with codecs.open(expected_result, encoding=encoding) as fh:
expected = fh.read()
normalized_result = _normalize(
contents,
normalize_identifiers=normalize_identifier_fields
)
if use_xml_canonicalisation:
print("Comparing results using XML canonicalization...")
matches_expected = _compare_with_xml_canonicalisation(
normalized_result, expected)
else:
print("Comparing results using diffs...")
matches_expected = _compare_without_xml_canonicalisation(
def test_get_version_integer_invalid_version(invalid_version):
with pytest.raises(RuntimeError):
util.get_version_integer(invalid_version)
dlang = etree.SubElement(slang,
util.nspath_eval('inspire_common:DefaultLanguage', self.inspire_namespaces))
etree.SubElement(dlang,
util.nspath_eval('inspire_common:Language', self.inspire_namespaces)).text = self.inspire_config['default_language']
for l in self.inspire_config['languages_supported'].split(','):
lang = etree.SubElement(slang,
util.nspath_eval('inspire_common:SupportedLanguage', self.inspire_namespaces))
etree.SubElement(lang,
util.nspath_eval('inspire_common:Language', self.inspire_namespaces)).text = l
clang = etree.SubElement(ex_caps,
util.nspath_eval('inspire_common:ResponseLanguage', self.inspire_namespaces))
etree.SubElement(clang,
util.nspath_eval('inspire_common:Language', self.inspire_namespaces)).text = self.inspire_config['current_language']
return ex_caps
if val is not None:
couplingtype = etree.SubElement(resident, util.nspath_eval('srv:couplingType', self.namespaces))
etree.SubElement(couplingtype, util.nspath_eval('srv:SV_CouplingType', self.namespaces), codeListValue=val, codeList='%s#SV_CouplingType' % CODELIST).text = val
if esn in ['summary', 'full']:
# all service resources as coupled resources
coupledresources = util.getqattr(result, queryables['apiso:OperatesOn']['dbcol'])
operations = util.getqattr(result, queryables['apiso:Operation']['dbcol'])
if coupledresources:
for val2 in coupledresources.split(','):
coupledres = etree.SubElement(resident, util.nspath_eval('srv:coupledResource', self.namespaces))
svcoupledres = etree.SubElement(coupledres, util.nspath_eval('srv:SV_CoupledResource', self.namespaces))
opname = etree.SubElement(svcoupledres, util.nspath_eval('srv:operationName', self.namespaces))
etree.SubElement(opname, util.nspath_eval('gco:CharacterString', self.namespaces)).text = _get_resource_opname(operations)
sid = etree.SubElement(svcoupledres, util.nspath_eval('srv:identifier', self.namespaces))
etree.SubElement(sid, util.nspath_eval('gco:CharacterString', self.namespaces)).text = val2
# service operations
if operations:
for i in operations.split(','):
oper = etree.SubElement(resident, util.nspath_eval('srv:containsOperations', self.namespaces))
tmp = etree.SubElement(oper, util.nspath_eval('srv:SV_OperationMetadata', self.namespaces))
tmp2 = etree.SubElement(tmp, util.nspath_eval('srv:operationName', self.namespaces))
etree.SubElement(tmp2, util.nspath_eval('gco:CharacterString', self.namespaces)).text = i
tmp3 = etree.SubElement(tmp, util.nspath_eval('srv:DCP', self.namespaces))
etree.SubElement(tmp3, util.nspath_eval('srv:DCPList', self.namespaces), codeList='%s#DCPList' % CODELIST, codeListValue='HTTPGet').text = 'HTTPGet'
tmp4 = etree.SubElement(tmp, util.nspath_eval('srv:DCP', self.namespaces))
etree.SubElement(tmp4, util.nspath_eval('srv:DCPList', self.namespaces), codeList='%s#DCPList' % CODELIST, codeListValue='HTTPPost').text = 'HTTPPost'
# Metadata Point of Contact
poc = etree.SubElement(ex_caps,
util.nspath_eval('inspire_common:MetadataPointOfContact', self.inspire_namespaces))
etree.SubElement(poc,
util.nspath_eval('inspire_common:OrganisationName', self.inspire_namespaces)).text = self.inspire_config['contact_name']
etree.SubElement(poc,
util.nspath_eval('inspire_common:EmailAddress', self.inspire_namespaces)).text = self.inspire_config['contact_email']
# Metadata Date
etree.SubElement(ex_caps,
util.nspath_eval('inspire_common:MetadataDate', self.inspire_namespaces)).text = self.inspire_config['date']
# Spatial Data Service Type
etree.SubElement(ex_caps,
util.nspath_eval('inspire_common:SpatialDataServiceType', self.inspire_namespaces)).text = 'discovery'
# Mandatory Keyword
mkey = etree.SubElement(ex_caps,
util.nspath_eval('inspire_common:MandatoryKeyword', self.inspire_namespaces))
mkey.attrib[util.nspath_eval('xsi:type', self.context.namespaces)] = 'inspire_common:classificationOfSpatialDataService'
etree.SubElement(mkey,
util.nspath_eval('inspire_common:KeywordValue', self.inspire_namespaces)).text = 'infoCatalogueService'
# Gemet Keywords
for gkw in self.inspire_config['gemet_keywords'].split(','):
gkey = etree.SubElement(ex_caps,
util.nspath_eval('inspire_common:Keyword', self.inspire_namespaces))
self.parent.context.namespaces)).text = value
elif 'elementsetname' in self.parent.kvp:
if (self.parent.kvp['elementsetname'] == 'full' and
util.getqattr(recobj, self.parent.context.md_core_model['mappings']\
['pycsw:Typename']) == 'csw:Record' and
util.getqattr(recobj, self.parent.context.md_core_model['mappings']\
['pycsw:Schema']) == 'http://www.opengis.net/cat/csw/2.0.2' and
util.getqattr(recobj, self.parent.context.md_core_model['mappings']\
['pycsw:Type']) != 'service'):
# dump record as is and exit
return etree.fromstring(util.getqattr(recobj,
self.parent.context.md_core_model['mappings']['pycsw:XML']), self.parent.context.parser)
etree.SubElement(record,
util.nspath_eval('dc:identifier', self.parent.context.namespaces)).text = \
util.getqattr(recobj,
self.parent.context.md_core_model['mappings']['pycsw:Identifier'])
for i in ['dc:title', 'dc:type']:
val = util.getqattr(recobj, queryables[i]['dbcol'])
if not val:
val = ''
etree.SubElement(record, util.nspath_eval(i,
self.parent.context.namespaces)).text = val
if self.parent.kvp['elementsetname'] in ['summary', 'full']:
# add summary elements
keywords = util.getqattr(recobj, queryables['dc:subject']['dbcol'])
if keywords is not None:
for keyword in keywords.split(','):
etree.SubElement(record,
util.nspath_eval('dc:subject',