def send_logfile(self): self.logger.info('Sending log file') try: sender = Sender() logger.info('Bye bye.') time.sleep(10) logutil = LogUtil() logutil.read_log(boxsettings.LOG_FILE) sender.send_log(logutil.log_text) self.logger.debug('done') except Exception, e: msg = "problem occured when attempting to send the log." self.logger.fatal(msg, exc_info=True)
def send_log(self): self.logger.info('Sending log file') try: sender = Sender() self.logger.info('Bye bye.') time.sleep(1) logutil = LogUtil() logutil.read_log(boxsettings.LOG_FILE) if sender.is_online(): self.logger.debug('sender.is_online') sender.send_log(logutil.log_text) else: self.logger.info('We do not send log as we are not online') except: msg = "problem occured when attempting to send the log." self.logger.fatal(msg)
def btest_sender_send_log_with_LogUtil(self): sender = Sender() logutil = LogUtil() logutil.read_log(boxsettings.LOG_FILE) try: response = sender.send_log(logutil.log_text) print(response.json()) self.assertEqual(201, response.status_code) except: msg = "problem occured when attempting to send the log" self.assertFalse(True, msg)
def btest_sender_send_log(self): sender = Sender() log_text = """INFO : 2018-07-13 16:28:04,039 : Saving settings to local JSON file settings.json INFO : 2018-07-13 16:28:04,046 : Settings written to file. INFO : 2018-07-13 16:28:04,143 : Saving settings to local JSON file settings.json INFO : 2018-07-13 16:28:04,143 : Settings written to file. INFO : 2018-07-13 16:28:04,144 : REST url: http://aquawatch.ch/battery/ INFO : 2018-07-13 16:28:04,144 : JSON: {'battery_charge': '10'} INFO : 2018-07-13 16:28:04,144 : User: raspi INFO : 2018-07-13 16:28:04,248 : Data sent to /battery/ of REST service. """ try: response = sender.send_log(log_text) print(response.json()) self.assertEqual(201, response.status_code) except: msg = "problem occured when attempting to send the log" self.assertFalse(True, msg)