def test_error_stub(self): # Test that when a converter fails an appropriate error record is # written test_proto.set_test_options(next_convert_fails=True) def check_target_last(lasts): expected = set(('rd.core.error', 'rd.msg.test.raw')) types = set([row['doc']['rd_schema_id'] for row in lasts]) self.failUnlessEqual(types, expected) # open the test document to get its ID and _rev. return self.process_doc( ).addCallback(lambda whateva: self.get_last_by_seq(2) ).addCallback(check_target_last )
def test_error_stub(self): # Test that when a converter fails an appropriate error record is # written test_proto.set_test_options(next_convert_fails=True) def check_target_last(lasts): expected = set(('rd.core.error', 'rd.msg.test.raw')) types = set([row['doc']['rd_schema_id'] for row in lasts]) self.failUnlessEqual(types, expected) # open the test document to get its ID and _rev, and indicate how many # errors we expect. test_doc = self.process_doc(1) seq = self.get_last_by_seq(2) return check_target_last(seq)
def test_all_steps(self): # We test the right thing happens running a 'full' pipeline # when our test converter throws an error. def check_last_doc(lasts): # The tail of the DB should be as below: expected = set(['rd.core.error', 'rd.msg.test.raw']) # Note the 'rd.core.error' is the failing conversion (ie, the # error stub), and no 'later' records exist as they all depend # on the failing conversion. got = set(l['doc'].get('rd_schema_id') for l in lasts) self.failUnlessEqual(got, expected) test_proto.set_test_options(next_convert_fails=True) doc = self.process_doc(1) seq = self.get_last_by_seq(2) return check_last_doc(seq)
def test_one_step(self): # Test taking a raw message one step along its pipeline. test_proto.set_test_options(next_convert_fails=False, emit_identities=False) def check_targets_last(lasts_by_seq, target_types): assert len(target_types)==len(lasts_by_seq) db_types = set(row['doc']['rd_schema_id'] for row in lasts_by_seq) self.failUnlessEqual(db_types, target_types) return target_types def check_targets(result, target_types): # Our targets should be the last written result = self.get_last_by_seq(len(target_types),) return check_targets_last(result, target_types) targets = set(('rd.msg.body', 'rd.msg.email', 'rd.msg.flags', 'rd.tags', 'rd.msg.rfc822', 'rd.msg.test.raw')) result = self.process_doc() return check_targets(result, targets)
def start_retry(result): test_proto.set_test_options(next_convert_fails=False, emit_identities=False) logger.info('starting retry for %r', result) return self.pipeline.start_retry_errors()
def process_doc(self, emit_common_ids=True): test_proto.set_test_options(emit_identities=True, emit_common_identities=emit_common_ids) self.deferMakeAnotherTestMessage(None) self.ensure_pipeline_complete()