def test_invalid_data_bulk_processor(self, process_change): self.config.validations = [ Validation.wrap({ "name": "impossible_condition", "error_message": "This condition is impossible to satisfy", "expression": { "type": "boolean_expression", "expression": { "type": "property_name", "property_name": "doesnt_exist" }, "operator": "in", "property_value": ["nonsense"] } }) ] self.config.save() cases = self._create_and_process_changes() num_rows = self.adapter.get_query_object().count() self.assertEqual(num_rows, 0) invalid_data = InvalidUCRData.objects.all().values_list('doc_id', flat=True) self.assertEqual(set([case.case_id for case in cases]), set(invalid_data)) # processor.process_change should not get called but processor.process_changes_chunk self.assertFalse(process_change.called)
def test_multiple_validations(self): self.config.validations = self.config.validations + [ Validation.wrap({ "name": "a_second_validation", "error_message": "another starred validation", "expression": { "type": "boolean_expression", "expression": { "type": "property_name", "property_name": "is_starred" }, "operator": "in", "property_value": ["yes", "no"] } }) ] sample_doc, expected_indicators = get_sample_doc_and_indicators() self.assertIsNone(self.config.validate_document(sample_doc)) sample_doc['is_starred'] = 'what is a star?' try: self.config.validate_document(sample_doc) except ValidationError as e: self.assertEqual(len(e.errors), 2) else: self.fail("There were no validation errors returned")
def test_invalid_data_serial_processor(self, process_changes_chunk): process_changes_chunk.side_effect = Exception self.config.validations = [ Validation.wrap({ "name": "impossible_condition", "error_message": "This condition is impossible to satisfy", "expression": { "type": "boolean_expression", "expression": { "type": "property_name", "property_name": "doesnt_exist" }, "operator": "in", "property_value": ["nonsense"] } }) ] self.config.save() cases = self._create_and_process_changes() num_rows = self.adapter.get_query_object().count() self.assertEqual(num_rows, 0) invalid_data = InvalidUCRData.objects.all().values_list('doc_id', flat=True) self.assertEqual(set([case.case_id for case in cases]), set(invalid_data))
def test_invalid_data_bulk_processor(self, process_change): # re-fetch from DB to bust object caches self.config = DataSourceConfiguration.get(self.config.data_source_id) self.config.validations = [ Validation.wrap({ "name": "impossible_condition", "error_message": "This condition is impossible to satisfy", "expression": { "type": "boolean_expression", "expression": { "type": "property_name", "property_name": "doesnt_exist" }, "operator": "in", "property_value": ["nonsense"] } }) ] self.config.save() cases = self._create_and_process_changes() num_rows = self.adapter.get_query_object().count() self.assertEqual(num_rows, 0) invalid_data = InvalidUCRData.objects.all().values_list('doc_id', flat=True) self.assertEqual(set([case.case_id for case in cases]), set(invalid_data)) # processor.process_change should not get called but processor.process_changes_chunk self.assertFalse(process_change.called)
def test_multiple_validations(self): self.config.validations = self.config.validations + [ Validation.wrap({ "name": "a_second_validation", "error_message": "another starred validation", "expression": { "type": "boolean_expression", "expression": { "type": "property_name", "property_name": "is_starred" }, "operator": "in", "property_value": ["yes", "no"] } }) ] sample_doc, expected_indicators = get_sample_doc_and_indicators() self.assertIsNone(self.config.validate_document(sample_doc)) sample_doc['is_starred'] = 'what is a star?' try: self.config.validate_document(sample_doc) except ValidationError as e: self.assertEquals(len(e.errors), 2) else: self.fail("There were no validation errors returned")
def test_async_invalid_data(self): # re-fetch from DB to bust object caches self.config = DataSourceConfiguration.get(self.config.data_source_id) self.config.validations = [ Validation.wrap({ "name": "impossible_condition", "error_message": "This condition is impossible to satisfy", "expression": { "type": "boolean_expression", "expression": { "type": "property_name", "property_name": "doesnt_exist" }, "operator": "in", "property_value": ["nonsense"] } }) ] self.config.save() parent_id, child_id = uuid.uuid4().hex, uuid.uuid4().hex since = self.pillow.get_change_feed().get_latest_offsets() for i in range(3): form, cases = post_case_blocks([ CaseBlock.deprecated_init( create=i == 0, case_id=parent_id, case_name='parent-name', case_type='bug', update={ 'update-prop-parent': i }, ).as_xml(), CaseBlock.deprecated_init(create=i == 0, case_id=child_id, case_name='child-name', case_type='bug-child', index={ 'parent': ('bug', parent_id) }, update={ 'update-prop-child': i }).as_xml() ], domain=self.domain) self.pillow.process_changes(since=since, forever=False) # run async queue queue_async_indicators() self.assertEqual(InvalidUCRData.objects.count(), 1)
def setUp(self): self.config = get_sample_data_source() self.config.validations = [ Validation.wrap({ "name": "is_starred_valid", "error_message": "is_starred has unexpected value", "expression": { "type": "boolean_expression", "expression": { "type": "property_name", "property_name": "is_starred" }, "operator": "in", "property_value": ["yes", "no"] } }) ]
def test_async_invalid_data(self): self.config.validations = [ Validation.wrap({ "name": "impossible_condition", "error_message": "This condition is impossible to satisfy", "expression": { "type": "boolean_expression", "expression": { "type": "property_name", "property_name": "doesnt_exist" }, "operator": "in", "property_value": ["nonsense"] } }) ] self.config.save() parent_id, child_id = uuid.uuid4().hex, uuid.uuid4().hex since = self.pillow.get_change_feed().get_latest_offsets() for i in range(3): form, cases = post_case_blocks( [ CaseBlock( create=i == 0, case_id=parent_id, case_name='parent-name', case_type='bug', update={'update-prop-parent': i}, ).as_xml(), CaseBlock( create=i == 0, case_id=child_id, case_name='child-name', case_type='bug-child', index={'parent': ('bug', parent_id)}, update={'update-prop-child': i} ).as_xml() ], domain=self.domain ) self.pillow.process_changes(since=since, forever=False) # run async queue queue_async_indicators() self.assertEqual(InvalidUCRData.objects.count(), 1)