def make_literal_input(self): literal = inout.inputs.LiteralInput( identifier="complexinput", title='MyComplex', data_type='string', workdir=self.tmp_dir, abstract="some description", keywords=['kw1', 'kw2'], metadata=[Metadata("special data")], uoms=['metre', 'unity'], min_occurs=2, max_occurs=5, mode=MODE.STRICT, allowed_values=[ AllowedValue(value='something'), AllowedValue(value='something else'), AnyValue() ], default="something else", default_type=SOURCE_TYPE.DATA, ) literal.data = 'something' literal.uom = UOM('unity') literal.as_reference = False return literal
def from_json(cls, json_input): allowed_values = [] for allowed_value in json_input['allowed_values']: if allowed_value['type'] == 'anyvalue': allowed_values.append(AnyValue()) elif allowed_value['type'] == 'novalue': allowed_values.append(NoValue()) elif allowed_value['type'] == 'valuesreference': allowed_values.append(ValuesReference.from_json(allowed_value)) elif allowed_value['type'] == 'allowedvalue': allowed_values.append(AllowedValue.from_json(allowed_value)) json_input_copy = deepcopy(json_input) json_input_copy['allowed_values'] = allowed_values json_input_copy['uoms'] = [ basic.UOM(uom.get('uom')) for uom in json_input.get('uoms', []) ] data = json_input_copy.pop('data', None) uom = json_input_copy.pop('uom', None) metadata = json_input_copy.pop('metadata', []) json_input_copy.pop('type') json_input_copy.pop('any_value', None) json_input_copy.pop('values_reference', None) instance = cls(**json_input_copy) instance.metadata = [Metadata.from_json(d) for d in metadata] instance.data = data if uom: instance.uom = basic.UOM(uom['uom']) return instance
def test_json_in(self): obj = { 'operation': 'getcapabilities', 'version': '1.0.0', 'language': 'eng', 'identifier': 'ahoj', 'identifiers': 'ahoj', # TODO: why identifierS? 'store_execute': True, 'status': True, 'lineage': True, 'inputs': { 'myin': [{ 'identifier': 'myin', 'type': 'complex', 'supported_formats': [{ 'mime_type': 'tralala' }], 'file': self.tempfile, 'data_format': { 'mime_type': 'tralala' } }], 'myliteral': [{ 'identifier': 'myliteral', 'type': 'literal', 'data_type': 'integer', 'allowed_values': [{ 'type': 'anyvalue' }], 'data': 1 }] }, 'outputs': {}, 'raw': False } self.request = WPSRequest() self.request.json = obj self.assertEqual(self.request.inputs['myliteral'][0].data, 1, 'Data are in the file') self.assertEqual(self.request.inputs['myin'][0].data, 'ahoj', 'Data are in the file') self.assertListEqual( self.request.inputs['myliteral'][0].allowed_values, [AnyValue()], 'Any value not set') self.assertTrue(self.request.inputs['myliteral'][0].any_value, 'Any value set')
def from_json(cls, json_input): allowed_values = [] for allowed_value in json_input['allowed_values']: if allowed_value['type'] == 'anyvalue': allowed_values.append(AnyValue()) elif allowed_value['type'] == 'novalue': allowed_values.append(NoValue()) elif allowed_value['type'] == 'valuesreference': allowed_values.append(ValuesReference()) elif allowed_value['type'] == 'allowedvalue': allowed_values.append( AllowedValue(allowed_type=allowed_value['allowed_type'], value=allowed_value['value'], minval=allowed_value['minval'], maxval=allowed_value['maxval'], spacing=allowed_value['spacing'], range_closure=allowed_value['range_closure'])) json_input['allowed_values'] = allowed_values json_input['uoms'] = [ basic.UOM(uom.get('uom')) for uom in json_input.get('uoms', []) ] data = json_input.pop('data', None) uom = json_input.pop('uom', None) metadata = json_input.pop('metadata', []) json_input.pop('type') json_input.pop('any_value', None) json_input.pop('values_reference', None) instance = cls(**json_input) instance.metadata = [Metadata.from_json(d) for d in metadata] instance.data = data if uom: instance.uom = basic.UOM(uom['uom']) return instance
def json(self, value): """init this request from json back again :param value: the json (not string) representation """ self.operation = value['operation'] self.version = value['version'] self.language = value['language'] self.identifier = value['identifier'] self.identifiers = value['identifiers'] self.store_execute = value['store_execute'] self.status = value['status'] self.lineage = value['lineage'] self.outputs = value['outputs'] self.raw = value['raw'] self.inputs = {} for identifier in value['inputs']: inpt = None inpt_defs = value['inputs'][identifier] for inpt_def in inpt_defs: if inpt_def['type'] == 'complex': inpt = ComplexInput( identifier=inpt_def['identifier'], title=inpt_def.get('title'), abstract=inpt_def.get('abstract'), workdir=inpt_def.get('workdir'), data_format=Format( schema=inpt_def['data_format'].get('schema'), extension=inpt_def['data_format'].get('extension'), mime_type=inpt_def['data_format']['mime_type'], encoding=inpt_def['data_format'].get('encoding')), supported_formats=[ Format(schema=infrmt.get('schema'), extension=infrmt.get('extension'), mime_type=infrmt['mime_type'], encoding=infrmt.get('encoding')) for infrmt in inpt_def['supported_formats'] ], mode=MODE.NONE) inpt.file = inpt_def['file'] elif inpt_def['type'] == 'literal': allowed_values = [] for allowed_value in inpt_def['allowed_values']: if allowed_value['type'] == 'anyvalue': allowed_values.append(AnyValue()) elif allowed_value['type'] == 'novalue': allowed_values.append(NoValue()) elif allowed_value['type'] == 'valuesreference': allowed_values.append(ValuesReference()) elif allowed_value['type'] == 'allowedvalue': allowed_values.append( AllowedValue( allowed_type=allowed_value['allowed_type'], value=allowed_value['value'], minval=allowed_value['minval'], maxval=allowed_value['maxval'], spacing=allowed_value['spacing'], range_closure=allowed_value[ 'range_closure'])) inpt = LiteralInput(identifier=inpt_def['identifier'], title=inpt_def.get('title'), abstract=inpt_def.get('abstract'), data_type=inpt_def.get('data_type'), workdir=inpt_def.get('workdir'), allowed_values=AnyValue, uoms=inpt_def.get('uoms'), mode=inpt_def.get('mode')) inpt.uom = inpt_def.get('uom') inpt.data = inpt_def.get('data') elif inpt_def['type'] == 'bbox': inpt = BBoxInput(identifier=inpt_def['identifier'], title=inpt_def['title'], abstract=inpt_def['abstract'], crss=inpt_def['crs'], dimensions=inpt_def['dimensions'], workdir=inpt_def['workdir'], mode=inpt_def['mode']) inpt.ll = inpt_def['bbox'][0] inpt.ur = inpt_def['bbox'][1] if identifier in self.inputs: self.inputs[identifier].append(inpt) else: self.inputs[identifier] = [inpt]
def __init__(self): inputs = [ LiteralInput('string', 'String', data_type='string', abstract='Enter a simple string.', default="This is just a string", mode=MODE.SIMPLE), LiteralInput( 'int', 'Integer', data_type='integer', abstract='Choose an integer number from allowed values.', default="7", allowed_values=[1, 2, 3, 5, 7, 11]), LiteralInput('float', 'Float', data_type='float', abstract='Enter a float number.', default="3.14", min_occurs=0, max_occurs=5), # TODO: boolean default is not displayed in phoenix LiteralInput('boolean', 'Boolean', data_type='boolean', abstract='Make your choice :)', default='1'), LiteralInput('angle', 'Angle', data_type='angle', abstract='Enter an angle [0, 360] :)', default='90'), LiteralInput('time', 'Time', data_type='time', abstract='Enter a time like 12:00:00', default='12:00:00'), LiteralInput('date', 'Date', data_type='date', abstract='Enter a date like 2012-05-01', default='2012-05-01'), LiteralInput('datetime', 'Datetime', data_type='dateTime', abstract='Enter a datetime like 2016-09-02T12:00:00Z', default='2016-09-02T12:00:00Z'), LiteralInput('string_choice', 'String Choice', data_type='string', abstract='Choose one item form list.', allowed_values=['rock', 'paper', 'scissor'], default='scissor'), LiteralInput('string_multiple_choice', 'String Multiple Choice', abstract='Choose one or two items from list.', data_type='string', allowed_values=[ 'sitting duck', 'flying goose', 'happy pinguin', 'gentle albatros' ], min_occurs=0, max_occurs=2, default='gentle albatros'), LiteralInput( 'int_range', 'Integer Range', abstract= 'Choose number from range: 1-10 (step 1), 100-200 (step 10)', metadata=[ Metadata( 'AllowedValue PyWPS Docs', 'https://pywps.readthedocs.io/en/master/api.html#pywps.inout.literaltypes.AllowedValue' ), # noqa Metadata( 'AllowedValue Example', 'http://docs.opengeospatial.org/is/14-065/14-065.html#98' ), # noqa ], data_type='integer', default='1', allowed_values=[ AllowedValue(minval=1, maxval=10), AllowedValue(minval=100, maxval=200, spacing=10) ], mode=MODE.SIMPLE, ), LiteralInput( 'any_value', 'Any Value', abstract='Enter any value.', metadata=[ Metadata( 'AnyValue PyWPS Docs', 'https://pywps.readthedocs.io/en/master/api.html#pywps.inout.literaltypes.AnyValue' ), # noqa ], allowed_values=AnyValue(), default='any value', mode=MODE.SIMPLE, ), LiteralInput( 'ref_value', 'Referenced Value', abstract='Choose a referenced value', metadata=[ Metadata( 'PyWPS Docs', 'https://pywps.readthedocs.io/en/master/_modules/pywps/inout/literaltypes.html' ), # noqa ], data_type='string', allowed_values=ValuesReference( reference= "https://en.wikipedia.org/w/api.php?action=opensearch&search=scotland&format=json" ), # noqa default='Scotland', mode=MODE.SIMPLE, ), # TODO: bbox is not supported yet by owslib # BoundingBoxInput('bbox', 'Bounding Box', # abstract='Bounding Box with EPSG:4326 and EPSG:3035.', # crss=['epsg:4326', 'epsg:3035'], # min_occurs=0), ComplexInput( 'text', 'Text', abstract='Enter a URL pointing to a text document (optional)', metadata=[Metadata('Info')], min_occurs=0, supported_formats=[Format('text/plain')]), ComplexInput( 'dataset', 'Dataset', abstract="Enter a URL pointing to a NetCDF file (optional)", metadata=[ Metadata( 'NetCDF Format', 'https://en.wikipedia.org/wiki/NetCDF', role= 'http://www.opengis.net/spec/wps/2.0/def/process/description/documentation' ) ], min_occurs=0, supported_formats=[FORMATS.NETCDF]), ] outputs = [ LiteralOutput('string', 'String', data_type='string'), LiteralOutput('int', 'Integer', data_type='integer'), LiteralOutput('float', 'Float', data_type='float'), LiteralOutput('boolean', 'Boolean', data_type='boolean'), LiteralOutput('angle', 'Angle', data_type='angle'), LiteralOutput('time', 'Time', data_type='time'), LiteralOutput('date', 'Date', data_type='date'), LiteralOutput('datetime', 'DateTime', data_type='dateTime'), LiteralOutput('string_choice', 'String Choice', data_type='string'), LiteralOutput('string_multiple_choice', 'String Multiple Choice', data_type='string'), LiteralOutput('int_range', 'Integer Range', data_type='integer'), LiteralOutput('any_value', 'Any Value', data_type='string'), LiteralOutput('ref_value', 'Referenced Value', data_type='string'), ComplexOutput('text', 'Text', abstract='Copy of input text file.', as_reference=False, supported_formats=[ FORMATS.TEXT, ]), ComplexOutput('dataset', 'Dataset', abstract='Copy of input netcdf file.', as_reference=True, supported_formats=[FORMATS.NETCDF, FORMATS.TEXT]), BoundingBoxOutput('bbox', 'Bounding Box', crss=['epsg:4326']), ] super(InOut, self).__init__( self._handler, identifier="inout", title="In and Out", version="1.0", abstract="Testing all WPS input and output parameters.", # profile=['birdhouse'], metadata=[ Metadata('Birdhouse', 'http://bird-house.github.io/'), MetadataUrl( 'User Guide', 'http://emu.readthedocs.io/en/latest/', role= 'http://www.opengis.net/spec/wps/2.0/def/process/description/documentation', anonymous=True), ], inputs=inputs, outputs=outputs, status_supported=True, store_supported=True)
def test_anyvalue_validator(self): """Test anyvalue validator""" inpt = get_input(allowed_values=AnyValue()) self.assertTrue(validate_anyvalue(inpt, MODE.SIMPLE))