def test_allowedvalues_values_validator(self): """Test allowed values - values""" allowed_value = AllowedValue() allowed_value.allowed_type = ALLOWEDVALUETYPE.VALUE allowed_value.value = 1 inpt = get_input(allowed_values=[allowed_value]) self.assertTrue(validate_allowed_values(inpt, MODE.SIMPLE), 'Allowed value 1 allowed') inpt.data = 2 self.assertFalse(validate_allowed_values(inpt, MODE.SIMPLE), 'Allowed value 2 NOT allowed')
def test_literal_allowed_values_input(): """Test all around allowed_values """ literal = LiteralInput( 'foo', 'Foo', data_type='integer', uoms=['metre'], allowed_values=(1, 2, (5, 10), (12, 4, 24), AllowedValue(allowed_type=ALLOWEDVALUETYPE.RANGE, minval=30, maxval=33, range_closure='closed-open'))) doc = literal.describe_xml() allowed_values = xpath_ns(doc, './LiteralData/ows:AllowedValues') assert len(allowed_values) == 1 allowed_value = allowed_values[0] values = xpath_ns(allowed_value, './ows:Value') ranges = xpath_ns(allowed_value, './ows:Range') assert len(values) == 2 assert len(ranges) == 3
def test_allowedvalues_ranges_validator(self): """Test allowed values - ranges""" allowed_value = AllowedValue() allowed_value.allowed_type = ALLOWEDVALUETYPE.RANGE allowed_value.minval = 1 allowed_value.maxval = 11 allowed_value.spacing = 2 allowed_value.range_closure = RANGECLOSURETYPE.CLOSED inpt = get_input(allowed_values=[allowed_value]) inpt.data = 1 self.assertTrue(validate_allowed_values(inpt, MODE.SIMPLE), 'Range CLOSED closure') inpt.data = 12 self.assertFalse(validate_allowed_values(inpt, MODE.SIMPLE), 'Value too big') inpt.data = 5 self.assertTrue(validate_allowed_values(inpt, MODE.SIMPLE), 'Spacing not fit') inpt.data = 4 self.assertFalse(validate_allowed_values(inpt, MODE.SIMPLE), 'Spacing fits') inpt.data = 11 allowed_value.range_closure = RANGECLOSURETYPE.CLOSED self.assertTrue(validate_allowed_values(inpt, MODE.SIMPLE), 'Open Range') allowed_value.range_closure = RANGECLOSURETYPE.CLOSEDOPEN self.assertFalse(validate_allowed_values(inpt, MODE.SIMPLE), 'CLOSEDOPEN Range') inpt.data = 1 allowed_value.range_closure = RANGECLOSURETYPE.OPENCLOSED self.assertFalse(validate_allowed_values(inpt, MODE.SIMPLE), 'OPENCLOSED Range')
def test_combined_validator(self): """Test allowed values - ranges and values combination""" allowed_value1 = AllowedValue() allowed_value1.allowed_type = ALLOWEDVALUETYPE.RANGE allowed_value1.minval = 1 allowed_value1.maxval = 11 allowed_value1.spacing = 2 allowed_value1.range_closure = RANGECLOSURETYPE.CLOSED allowed_value2 = AllowedValue() allowed_value2.allowed_type = ALLOWEDVALUETYPE.VALUE allowed_value2.value = 15 inpt = get_input(allowed_values=[allowed_value1, allowed_value2]) inpt.data = 1 self.assertTrue(validate_allowed_values(inpt, MODE.SIMPLE), 'Range CLOSED closure') inpt.data = 15 self.assertTrue(validate_allowed_values(inpt, MODE.SIMPLE), 'AllowedValue') inpt.data = 13 self.assertFalse(validate_allowed_values(inpt, MODE.SIMPLE), 'Out of range')
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.identifiers = value['identifiers'] self.store_execute = value['store_execute'] self.status = value['store_execute'] 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'), 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'), 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'], 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 _allowed_layer(lyr: QgsMapLayer) -> bool: return AllowedValue(value=lyr.name(), allowed_type=ALLOWEDVALUETYPE.LAYER)