def test_case_preserved(self): validator = cell_validators.FixedStringValidator( ['MyCamelCaseIsImportant'], 'RecordType', self.logger) self.assertRaisesRegexp( error.CellValidationFailure, r'Value was expected to be one of the following: ' r'\[\'MyCamelCaseIsImportant\'\].', validator.validate_value, 'WrongValue', 9, 'some_file.csv', '1')
def test_parse_xsd_file_valid_row_types_in_a_specific_row(self): """Tests the expected cells in a specific row.""" rows_validators = self.dsrf_schema_parser.parse_xsd_file(self.logger) expected_su02_validators = [ cell_validators.FixedStringValidator({}, 'RecordType', self.logger, True, False), cell_validators.StringValidator('BlockId', self.logger, True, False), cell_validators.StringValidator('SalesTransactionId', self.logger, True, False), cell_validators.StringValidator('TransactedReleaseOrResource', self.logger, True, False), cell_validators.StringValidator('CommercialModelType', self.logger, True, False), cell_validators.FixedStringValidator({}, 'UseType', self.logger, True, False), cell_validators.StringValidator('Territory', self.logger, True, False), cell_validators.StringValidator('ServiceDescription', self.logger, False, False), cell_validators.BooleanValidator('IsRoyaltyBearing', self.logger, True, False), cell_validators.IntegerValidator('NumberOfStreams', self.logger, True, False), cell_validators.StringValidator('Currency', self.logger, False, False), cell_validators.DecimalValidator('PriceConsumerPaidExcSalesTax', self.logger, False, False), cell_validators.StringValidator('PromotionalActivity', self.logger, False, False), cell_validators.BooleanValidator('PreviewAvailable', self.logger, False, False), ] for actual_cell, expected_cell in zip(rows_validators['SU02'], expected_su02_validators): self.assertIsInstance(actual_cell, expected_cell.__class__) self.assertEquals(actual_cell.cell_name, expected_cell.cell_name, self.logger) self.assertEquals(actual_cell.required, expected_cell.required) self.assertEquals(actual_cell.repeated, expected_cell.repeated)
def get_cell_validator(self, cell_name, cell_type, required, repeated, logger): """Creates a cell validator object by the given cell name. Args: cell_name: The cell name (from the schema file). cell_type: The cell type (from the schema file). required: True if the cell is mandatory. repeated: True if the cell is repeated. logger: The library logger. Returns: cell_validator object. """ # Primitive types. if cell_type in VALIDATOR_TYPES_MAP: return VALIDATOR_TYPES_MAP[cell_type](cell_name, logger, required, repeated) # Simple types. if cell_type.startswith(constants.DSRF_TYPE_PREFIX): cell_type = cell_type.split(':')[-1] if cell_type in self.simple_types_map: if (self.simple_types_map[cell_type][1][0].tag == constants.XSD_TAG_PREFIX + 'pattern'): return cell_validators.PatternValidator( self.simple_types_map[cell_type][1][0].attrib['value'], cell_name, logger, required, repeated) # AVS types. cell_type = cell_type.replace(constants.FIXED_STRING_PREFIX, '') if cell_type in self._fixed_string_values: return cell_validators.FixedStringValidator( self._fixed_string_values[cell_type], cell_name, logger, required, repeated) raise error.XsdParsingFailure( path.basename(self.dsrf_xsd_file_name), 'The cell type %s does not ' 'exist in the provided configuration files. Please make sure you use ' 'the right files and version.' % cell_type)
def get_validator(self): return cell_validators.FixedStringValidator( ['HEAD', 'FOOT', 'FHEA', 'FFOO', 'SY01', 'RE01'], 'RecordType', self.logger)