def test_change_dimension_and_check_consistency(self): # make sure _checkConsistency does not complain about a cell # having an id outside the len of the dimension after a dimension # change if id is within acceptable values matrix = self.matrix cell_range = [['1', '2',], ['a', 'b',]] kwd = {'base_id' : 'quantity'} matrix.setCellRange(*cell_range, **kwd) for place in cartesianProduct(cell_range): matrix.newCell(*place, **kwd) cell = matrix.getCell('2', 'b', **kwd) self.assertEqual('quantity_1_1', cell.getId()) cell.setTitle('This one') self.tic() cell_range = [['2', ], ['b',]] matrix.setCellRange(*cell_range, **kwd) self.commit() self.assertEquals(set(["quantity_1_1"]), set([ x.getId() for x in matrix.objectValues()])) cell = matrix.getCell('2', 'b', **kwd) self.assertEqual('quantity_1_1', cell.getId()) self.assertEqual('This one', cell.getTitle()) self.assertEqual(XMLMatrix._checkConsistency(matrix), []) cell.setId('quantity_2_1') error_list = XMLMatrix._checkConsistency(matrix) self.assertEqual(1, len(error_list)) self.assertTrue(error_list[0][3].find("is out of bound") > 0)
def _checkConsistency(self, fixit=0): """ Check the constitency of transformation elements """ transformation = self.getParentValue() transformation_category_list = transformation.getVariationCategoryList( ) error_list = XMLMatrix._checkConsistency(self, fixit=fixit) # Quantity should be empty if no variation q_range = self.getCellRange(base_id='quantity') if q_range is not None: range_is_empty = 1 for q_list in q_range: if q_list is not None: range_is_empty = 0 break if range_is_empty: matrix_is_not_empty = 0 for k in self.getCellIds(base_id='quantity'): if hasattr(self, k): matrix_is_not_empty = 1 if matrix_is_not_empty: if fixit: self.delCells(base_id='quantity') error_message = "Variation cells for quantity should be empty (fixed)" else: error_message = "Variation cells for quantity should be empty" error_list += [(self.getRelativeUrl(), 'TransformedResource inconsistency', 100, error_message)] # First quantity # We build an attribute equality and look at all cells q_constraint = Constraint.AttributeEquality( domain_base_category_list=self.getQVariationBaseCategoryList(), predicate_operator='SUPERSET_OF', mapped_value_property_list=['quantity']) for kw in self.getCellKeys(base_id='quantity'): kwd = {'base_id': 'quantity'} c = self.getCell(*kw, **kwd) if c is not None: predicate_value_list = [] categories_list = [] for p in kw: if p is not None: if p in transformation_category_list: if p not in predicate_value_list: predicate_value_list.append(p) else: if p not in categories_list: categories_list.append(p) q_constraint.edit(predicate_value_list=predicate_value_list, categories_list=categories_list) if fixit: error_list += q_constraint.fixConsistency(c) else: error_list += q_constraint.checkConsistency(c) return error_list
def _checkConsistency(self, fixit=0): """ Check the constitency of transformation elements """ transformation = self.getParentValue() transformation_category_list = transformation.getVariationCategoryList() error_list = XMLMatrix._checkConsistency(self, fixit=fixit) # Quantity should be empty if no variation q_range = self.getCellRange(base_id = 'quantity') if q_range is not None: range_is_empty = 1 for q_list in q_range: if q_list is not None: range_is_empty = 0 break if range_is_empty: matrix_is_not_empty = 0 for k in self.getCellIds(base_id = 'quantity'): if hasattr(self, k):matrix_is_not_empty = 1 if matrix_is_not_empty: if fixit: self.delCells(base_id = 'quantity') error_message = "Variation cells for quantity should be empty (fixed)" else: error_message = "Variation cells for quantity should be empty" error_list += [(self.getRelativeUrl(), 'TransformedResource inconsistency', 100, error_message)] # First quantity # We build an attribute equality and look at all cells q_constraint = Constraint.AttributeEquality( domain_base_category_list = self.getQVariationBaseCategoryList(), predicate_operator = 'SUPERSET_OF', mapped_value_property_list = ['quantity'] ) for kw in self.getCellKeys(base_id = 'quantity'): kwd={'base_id': 'quantity'} c = self.getCell(*kw, **kwd) if c is not None: predicate_value_list = [] categories_list = [] for p in kw: if p is not None: if p in transformation_category_list: if p not in predicate_value_list: predicate_value_list.append(p) else: if p not in categories_list: categories_list.append(p) q_constraint.edit(predicate_value_list = predicate_value_list, categories_list = categories_list) if fixit: error_list += q_constraint.fixConsistency(c) else: error_list += q_constraint.checkConsistency(c) return error_list
def test_change_dimension_and_check_consistency(self): # make sure _checkConsistency does not complain about a cell # having an id outside the len of the dimension after a dimension # change if id is within acceptable values matrix = self.matrix cell_range = [[ '1', '2', ], [ 'a', 'b', ]] kwd = {'base_id': 'quantity'} matrix.setCellRange(*cell_range, **kwd) for place in cartesianProduct(cell_range): matrix.newCell(*place, **kwd) cell = matrix.getCell('2', 'b', **kwd) self.assertEqual('quantity_1_1', cell.getId()) cell.setTitle('This one') self.tic() cell_range = [[ '2', ], [ 'b', ]] matrix.setCellRange(*cell_range, **kwd) self.commit() self.assertEquals(set(["quantity_1_1"]), set([x.getId() for x in matrix.objectValues()])) cell = matrix.getCell('2', 'b', **kwd) self.assertEqual('quantity_1_1', cell.getId()) self.assertEqual('This one', cell.getTitle()) self.assertEqual(XMLMatrix._checkConsistency(matrix), []) cell.setId('quantity_2_1') error_list = XMLMatrix._checkConsistency(matrix) self.assertEqual(1, len(error_list)) self.assertTrue(error_list[0][3].find("is out of bound") > 0)