def check_input_file(batch_warning_days, db_path, email_settings, raw_xml_file): batch = None if not os.path.exists(db_path): create_empty_md5_database(db_path) new_md5ive = get_md5_input_file(raw_xml_file) new_msg = 'Using SQLite file: %s to store input file: %s md5 sum: %s' % ( db_path, raw_xml_file, new_md5ive) logger.info(new_msg) old_batch = get_last_batch(db_path) old_md5ive = None if old_batch: old_md5ive = old_batch['rbMd5Sum'] logger.info('Old md5 sum for the input file is: ' + old_md5ive) else: # this is the first time the checksum feature is used logger.info( "There is no old md5 recorded yet for the input file. Continue data import..." ) batch = add_batch_entry(db_path, new_md5ive) record_msg = 'Added batch (rbID= %s, rbStartTime= %s, rbMd5Sum= %s' % ( batch['rbID'], batch['rbStartTime'], batch['rbMd5Sum']) logger.info(record_msg) return batch if old_md5ive != new_md5ive: # the data has changed... insert a new batch entry batch = add_batch_entry(db_path, new_md5ive) record_msg = 'Added batch (rbID= %s, rbStartTime= %s, rbMd5Sum= %s' % ( batch['rbID'], batch['rbStartTime'], batch['rbMd5Sum']) logger.info(record_msg) return batch else: days_since_today = get_days_since_today(old_batch['rbStartTime']) # TODO: refactor code to use ConfigParser.RawConfigParser in order to # preserve data types if (days_since_today > int(batch_warning_days)): logger.info( 'Last import was started on: %s which is more than the limit of %s' % (old_batch['rbStartTime'], batch_warning_days)) if (-1 == int(batch_warning_days)): msg_continue = """ The configuration `batch_warning_days = -1` indicates that we want to continue execution even if the input file did not change """ logger.info(msg_continue) else: msg_quit = "The input file did not change in the past: %s days. Stop data import." % batch_warning_days logger.critical(msg_quit) redi_email.send_email_input_data_unchanged(email_settings) sys.exit() else: logger.info('Reusing md5 entry: ' + str(old_batch['rbID'])) # return the old batch so we can update the status return old_batch
def check_input_file(batch_warning_days, db_path, email_settings, raw_xml_file, project, start_time): batch = None if not os.path.exists(db_path) : create_empty_md5_database(db_path) new_md5ive = get_md5_input_file(raw_xml_file) new_msg = 'Using SQLite file: %s to store input file: %s md5 sum: %s' % ( db_path, raw_xml_file, new_md5ive) logger.info(new_msg) old_batch = get_last_batch(db_path) old_md5ive = None if old_batch: old_md5ive = old_batch['rbMd5Sum'] logger.info('Old md5 sum for the input file is: ' + old_md5ive) else: # this is the first time the checksum feature is used logger.info( "There is no old md5 recorded yet for the input file. Continue data import...") batch = add_batch_entry(db_path, new_md5ive) record_msg = 'Added batch (rbID= %s, rbCreateTime= %s, rbMd5Sum= %s' % ( batch['rbID'], batch['rbCreateTime'], batch['rbMd5Sum']) logger.info(record_msg) return batch if old_md5ive != new_md5ive: # the data has changed... insert a new batch entry batch = add_batch_entry(db_path, new_md5ive) record_msg = 'Added batch (rbID= %s, rbCreateTime= %s, rbMd5Sum= %s' % ( batch['rbID'], batch['rbCreateTime'], batch['rbMd5Sum']) logger.info(record_msg) return batch else: days_since_today = get_days_since_today(old_batch['rbCreateTime']) # TODO: refactor code to use ConfigParser.RawConfigParser in order to # preserve data types if (days_since_today > int(batch_warning_days)): raw_xml = RawXml(project, raw_xml_file) msg_file_details = "\nXML file details: " + raw_xml.get_info() logger.info('Last import was started on: %s which is more than '\ ' the limit of %s' % (old_batch['rbStartTime'], batch_warning_days)) if (-1 == int(batch_warning_days)): msg_continue = """ The configuration `batch_warning_days = -1` indicates that we want to continue execution even if the input file did not change """ + msg_file_details logger.info(msg_continue) else: msg_quit = "The input file did not change in the past: %s days." % days_since_today logger.critical(msg_quit + msg_file_details) redi_email.send_email_input_data_unchanged(email_settings, raw_xml) sys.exit() else: logger.info('Reusing md5 entry: ' + str(old_batch['rbID'])) # return the old batch so we can update the status return old_batch
def test_failed(self): """ Verify return false when email is not sent""" ese = self.email_settings self.assertFalse(redi_email.send_email_redcap_connection_error(ese)) self.assertFalse(redi_email.send_email_input_data_unchanged(ese))
def test_success(self): """ Verify return true when email is sent""" ese = self.email_settings self.assertTrue(redi_email.send_email_redcap_connection_error(ese)) self.assertTrue(redi_email.send_email_input_data_unchanged(ese))