def test_should_log_one_row_and_load_using_all_contexts(self): # Given logger = CassandraLogger(self.dao) source_context = 'CassandraLoggerTest1' log_source = 'unittest1' timestamp = datetime.strptime('1979-06-20T06:06:06.20', '%Y-%m-%dT%H:%M:%S.%f') level = 'warn' message = u'This is a log message from the erste unit test.' # When logger.log(source_context, log_source, timestamp, level, message) # Then free_text = 'erste' # 1. Find by exact context, note it returns list of LogMessageDTOs from the facade module result = logger.free_text_search(free_text, source_context, log_source, level) self.assertEqual(len(result), 1) self.__assert_log_message(result[0], source_context, log_source, timestamp, level, message) # 2 Find by looser context result = logger.free_text_search(free_text, source_context, None, level) self.assertEqual(len(result), 1) self.__assert_log_message(result[0], source_context, log_source, timestamp, level, message) # 3 Find by even more loose context, global but still within the 'info'-level result = logger.free_text_search(free_text, None, None, level) self.assertEqual(len(result), 1) self.__assert_log_message(result[0], source_context, log_source, timestamp, level, message) # 4 Find in über-global context result = logger.free_text_search(free_text) self.assertEqual(len(result), 1) self.__assert_log_message(result[0], source_context, log_source, timestamp, level, message)
def test_should_log_one_row_for_three_sources_and_three_should_be_found_within_higher_contexts(self): # Given logger = CassandraLogger(self.dao) source_context = 'CassandraLoggerTest2' log_source1 = 'unittest1_1' log_source2 = 'unittest1_2' log_source3 = 'unittest1_3' timestamp1 = datetime.strptime('1979-06-20T06:06:06.20', '%Y-%m-%dT%H:%M:%S.%f') timestamp2 = datetime.strptime('1979-06-20T06:06:06.21', '%Y-%m-%dT%H:%M:%S.%f') timestamp3 = datetime.strptime('1979-06-20T06:06:06.22', '%Y-%m-%dT%H:%M:%S.%f') level = 'warn' message = u'This is a log message from the second unit test.' # When logger.log(source_context, log_source1, timestamp1, level, message) logger.log(source_context, log_source2, timestamp2, level, message) logger.log(source_context, log_source3, timestamp3, level, message) # Then... free_text = 'second' # 1. Find by exact context, should return 1 result = logger.free_text_search(free_text, source_context, log_source1, level) self.assertEqual(len(result), 1) self.__assert_log_message(result[0], source_context, log_source1, timestamp1, level, message) # 2 Find by looser context, should find all three now result = logger.free_text_search(free_text, source_context, None, level) self.assertEqual(len(result), 3) self.__assert_log_message(result[0], source_context, log_source1, timestamp1, level, message) self.__assert_log_message(result[1], source_context, log_source2, timestamp2, level, message) self.__assert_log_message(result[2], source_context, log_source3, timestamp3, level, message) # 3 Find by even more loose context, global but still within the 'info'-level result = logger.free_text_search(free_text, None, None, level) self.assertEqual(len(result), 3) self.__assert_log_message(result[0], source_context, log_source1, timestamp1, level, message) self.__assert_log_message(result[1], source_context, log_source2, timestamp2, level, message) self.__assert_log_message(result[2], source_context, log_source3, timestamp3, level, message) # 4 Find in über-global context result = logger.free_text_search(free_text) self.assertEqual(len(result), 3) self.__assert_log_message(result[0], source_context, log_source1, timestamp1, level, message) self.__assert_log_message(result[1], source_context, log_source2, timestamp2, level, message) self.__assert_log_message(result[2], source_context, log_source3, timestamp3, level, message)
def test_should_log_three_rows_for_three_sources_and_load_by_date_range(self): # Given logger = CassandraLogger(self.dao) source_context = 'CassandraLoggerTest3' log_source1 = 'unittest1_1' log_source2 = 'unittest1_2' log_source3 = 'unittest1_3' timestamp1_1 = datetime.strptime('1979-06-20T06:06:06.20', '%Y-%m-%dT%H:%M:%S.%f') timestamp1_2 = datetime.strptime('1979-06-20T06:06:06.21', '%Y-%m-%dT%H:%M:%S.%f') timestamp1_3 = datetime.strptime('1979-06-20T06:06:06.22', '%Y-%m-%dT%H:%M:%S.%f') timestamp2_1 = datetime.strptime('1979-06-20T06:06:06.23', '%Y-%m-%dT%H:%M:%S.%f') timestamp2_2 = datetime.strptime('1979-06-20T06:06:06.24', '%Y-%m-%dT%H:%M:%S.%f') timestamp2_3 = datetime.strptime('1979-06-20T06:06:06.25', '%Y-%m-%dT%H:%M:%S.%f') timestamp3_1 = datetime.strptime('1979-06-20T06:06:06.26', '%Y-%m-%dT%H:%M:%S.%f') timestamp3_2 = datetime.strptime('1979-06-20T06:06:06.27', '%Y-%m-%dT%H:%M:%S.%f') timestamp3_3 = datetime.strptime('1979-06-20T06:06:06.28', '%Y-%m-%dT%H:%M:%S.%f') level = 'warn' message = u'In Sweden Strindberg is both known as a novelist and a playwright' # When logger.log(source_context, log_source1, timestamp1_1, level, message) logger.log(source_context, log_source1, timestamp1_2, level, message) logger.log(source_context, log_source1, timestamp1_3, level, message) logger.log(source_context, log_source2, timestamp2_1, level, message) logger.log(source_context, log_source2, timestamp2_2, level, message) logger.log(source_context, log_source2, timestamp2_3, level, message) logger.log(source_context, log_source3, timestamp3_1, level, message) logger.log(source_context, log_source3, timestamp3_2, level, message) logger.log(source_context, log_source3, timestamp3_3, level, message) # Then... free_text = 'Strindberg' # 1. Find by exact context, should return 3 in this date span # (ie provide source context, log_source and level fromdate = datetime.strptime('1979-06-20T06:06:06.19', '%Y-%m-%dT%H:%M:%S.%f') todate = datetime.strptime('1979-06-20T06:06:06.23', '%Y-%m-%dT%H:%M:%S.%f') result = logger.load_by_date_range(source_context, log_source1, level, fromdate, todate) self.assertEqual(len(result), 3) self.__assert_log_message(result[0], source_context, log_source1, timestamp1_1, level, message) self.__assert_log_message(result[1], source_context, log_source1, timestamp1_2, level, message) self.__assert_log_message(result[2], source_context, log_source1, timestamp1_3, level, message) # 2. now be less specific, should find all 9 # (ie provide source context, no log_source but keep level fromdate = datetime.strptime('1979-06-20T06:06:06.19', '%Y-%m-%dT%H:%M:%S.%f') todate = datetime.strptime('1979-06-20T06:06:06.29', '%Y-%m-%dT%H:%M:%S.%f') result = logger.load_by_date_range(source_context, None, level, fromdate, todate) self.assertEqual(len(result), 9) # 3. Same as last, but choose a date outside the inserted range, should find 0 fromdate = datetime.strptime('1939-06-20T06:06:06.19', '%Y-%m-%dT%H:%M:%S.%f') todate = datetime.strptime('1939-06-20T06:06:06.29', '%Y-%m-%dT%H:%M:%S.%f') result = logger.load_by_date_range(source_context, None, level, fromdate, todate) self.assertEqual(len(result), 0)
def test_should_log_three_rows_for_three_sources_and_load_by_date_range( self): # Given logger = CassandraLogger(self.dao) source_context = 'CassandraLoggerTest3' log_source1 = 'unittest1_1' log_source2 = 'unittest1_2' log_source3 = 'unittest1_3' timestamp1_1 = datetime.strptime('1979-06-20T06:06:06.20', '%Y-%m-%dT%H:%M:%S.%f') timestamp1_2 = datetime.strptime('1979-06-20T06:06:06.21', '%Y-%m-%dT%H:%M:%S.%f') timestamp1_3 = datetime.strptime('1979-06-20T06:06:06.22', '%Y-%m-%dT%H:%M:%S.%f') timestamp2_1 = datetime.strptime('1979-06-20T06:06:06.23', '%Y-%m-%dT%H:%M:%S.%f') timestamp2_2 = datetime.strptime('1979-06-20T06:06:06.24', '%Y-%m-%dT%H:%M:%S.%f') timestamp2_3 = datetime.strptime('1979-06-20T06:06:06.25', '%Y-%m-%dT%H:%M:%S.%f') timestamp3_1 = datetime.strptime('1979-06-20T06:06:06.26', '%Y-%m-%dT%H:%M:%S.%f') timestamp3_2 = datetime.strptime('1979-06-20T06:06:06.27', '%Y-%m-%dT%H:%M:%S.%f') timestamp3_3 = datetime.strptime('1979-06-20T06:06:06.28', '%Y-%m-%dT%H:%M:%S.%f') level = 'warn' message = u'In Sweden Strindberg is both known as a novelist and a playwright' # When logger.log(source_context, log_source1, timestamp1_1, level, message) logger.log(source_context, log_source1, timestamp1_2, level, message) logger.log(source_context, log_source1, timestamp1_3, level, message) logger.log(source_context, log_source2, timestamp2_1, level, message) logger.log(source_context, log_source2, timestamp2_2, level, message) logger.log(source_context, log_source2, timestamp2_3, level, message) logger.log(source_context, log_source3, timestamp3_1, level, message) logger.log(source_context, log_source3, timestamp3_2, level, message) logger.log(source_context, log_source3, timestamp3_3, level, message) # Then... free_text = 'Strindberg' # 1. Find by exact context, should return 3 in this date span # (ie provide source context, log_source and level fromdate = datetime.strptime('1979-06-20T06:06:06.19', '%Y-%m-%dT%H:%M:%S.%f') todate = datetime.strptime('1979-06-20T06:06:06.23', '%Y-%m-%dT%H:%M:%S.%f') result = logger.load_by_date_range(source_context, log_source1, level, fromdate, todate) self.assertEqual(len(result), 3) self.__assert_log_message(result[0], source_context, log_source1, timestamp1_1, level, message) self.__assert_log_message(result[1], source_context, log_source1, timestamp1_2, level, message) self.__assert_log_message(result[2], source_context, log_source1, timestamp1_3, level, message) # 2. now be less specific, should find all 9 # (ie provide source context, no log_source but keep level fromdate = datetime.strptime('1979-06-20T06:06:06.19', '%Y-%m-%dT%H:%M:%S.%f') todate = datetime.strptime('1979-06-20T06:06:06.29', '%Y-%m-%dT%H:%M:%S.%f') result = logger.load_by_date_range(source_context, None, level, fromdate, todate) self.assertEqual(len(result), 9) # 3. Same as last, but choose a date outside the inserted range, should find 0 fromdate = datetime.strptime('1939-06-20T06:06:06.19', '%Y-%m-%dT%H:%M:%S.%f') todate = datetime.strptime('1939-06-20T06:06:06.29', '%Y-%m-%dT%H:%M:%S.%f') result = logger.load_by_date_range(source_context, None, level, fromdate, todate) self.assertEqual(len(result), 0)
def test_should_log_one_row_for_three_sources_and_three_should_be_found_within_higher_contexts( self): # Given logger = CassandraLogger(self.dao) source_context = 'CassandraLoggerTest2' log_source1 = 'unittest1_1' log_source2 = 'unittest1_2' log_source3 = 'unittest1_3' timestamp1 = datetime.strptime('1979-06-20T06:06:06.20', '%Y-%m-%dT%H:%M:%S.%f') timestamp2 = datetime.strptime('1979-06-20T06:06:06.21', '%Y-%m-%dT%H:%M:%S.%f') timestamp3 = datetime.strptime('1979-06-20T06:06:06.22', '%Y-%m-%dT%H:%M:%S.%f') level = 'warn' message = u'This is a log message from the second unit test.' # When logger.log(source_context, log_source1, timestamp1, level, message) logger.log(source_context, log_source2, timestamp2, level, message) logger.log(source_context, log_source3, timestamp3, level, message) # Then... free_text = 'second' # 1. Find by exact context, should return 1 result = logger.free_text_search(free_text, source_context, log_source1, level) self.assertEqual(len(result), 1) self.__assert_log_message(result[0], source_context, log_source1, timestamp1, level, message) # 2 Find by looser context, should find all three now result = logger.free_text_search(free_text, source_context, None, level) self.assertEqual(len(result), 3) self.__assert_log_message(result[0], source_context, log_source1, timestamp1, level, message) self.__assert_log_message(result[1], source_context, log_source2, timestamp2, level, message) self.__assert_log_message(result[2], source_context, log_source3, timestamp3, level, message) # 3 Find by even more loose context, global but still within the 'info'-level result = logger.free_text_search(free_text, None, None, level) self.assertEqual(len(result), 3) self.__assert_log_message(result[0], source_context, log_source1, timestamp1, level, message) self.__assert_log_message(result[1], source_context, log_source2, timestamp2, level, message) self.__assert_log_message(result[2], source_context, log_source3, timestamp3, level, message) # 4 Find in über-global context result = logger.free_text_search(free_text) self.assertEqual(len(result), 3) self.__assert_log_message(result[0], source_context, log_source1, timestamp1, level, message) self.__assert_log_message(result[1], source_context, log_source2, timestamp2, level, message) self.__assert_log_message(result[2], source_context, log_source3, timestamp3, level, message)