def log_transaction(self, message, typing='TRANSACTION', commit=True): if not isinstance(message, str): raise TypeError('ERROR: Message must be of type string') if typing not in OracleDB.types: raise ValueError('ERROR: typing must be a defined log type') self._db.insert_into_Logs(TIME.get_timestamp(), typing, message, commit)
def insert_into_Logs(self, time, typ, msg, commit = True): if not TIME.is_time_formatted(time): raise TypeError('ERROR time variable must be formatted in the proper format %Y-%m-%d %H:%M:%S') if typ not in types: raise ValueError('ERROR typ must be one of the approved types of Logs') if not isinstance(msg, str): raise ValueError('ERROR msg must be of type str') self._cursor.execute('INSERT INTO db.Logs(time, type, message) VALUES (%s, %s, %s);',(time,typ,msg)) if commit: self.commit()
def test_LD_insert_log(): logDB = LD.LogDatabase() logDB.insert_into_Logs(TIME.get_timestamp(), 'TRANSACTION', 'This is a TEST Transaction Message')
def test_LD_insert_message_failure(): logDB = LD.LogDatabase() with pytest.raises(TypeError): logDB.insert_into_Logs(TIME.get_timestamp(), 'TRANSACTION', 18)
def test_LD_insert_type_failure(): logDB = LD.LogDatabase() with pytest.raises(ValueError): logDB.insert_into_Logs(TIME.get_timestamp(), 'INVALID TYPE', 'This is a TEST Transaction Message')