def test_redis_set_and_get_with_prefix_encoder(self): storage = RedisStorage(RedisMock(), prefix='pre::', encoder=json) storage.set("theKey", "theValue") storage.set("theKey2", "theValue2") assert storage.get("theKey2") == "theValue2" assert storage.get("theKey") == "theValue" assert storage.get("noKey") == None
def test_redis_set_and_get_with_prefix_encoder(self): storage = RedisStorage(RedisMock(), prefix='pre::', encoder=json) storage.set("theKey", "theValue") storage.set("theKey2", "theValue2") assert storage.get("theKey2") == "theValue2" assert storage.get("theKey") == "theValue" assert storage.get("noKey") == None
class TestObelixLogging(unittest.TestCase): def setUp(self): """ setup any state tied to the execution of the given method in a class. setup_method is invoked for every test method of a class. """ self.cache = RedisStorage(RedisMock(), prefix='pre::', encoder=json) self.recommendations = RedisStorage(RedisMock(), 'recommendations::') self.queues = RedisQueue(RedisMock(), encoder=json) self.obelix = Obelix(self.cache, self.recommendations, self.queues) def test_log_search_result(self): obelix = self.obelix # def test_log_search(self): user_info = {'uid': 1, 'remote_ip': "127.0.0.1", "uri": "testuri"} record_ids = [[1, 88], [1, 2]] results_final_colls_scores = [[0.3, 0.5], [0.5, 0.2]] cols_in_result_ordered = ["Thesis", "Another"] seconds_to_rank_and_print = 2 jrec, rg, rm, cc = 0, 10, "recommendations", "obelix" obelix.log("search_result", user_info, record_ids, record_ids, results_final_colls_scores, cols_in_result_ordered, seconds_to_rank_and_print, jrec, rg, rm, cc) storage_key = "{0}::{1}".format("last-search-result", user_info['uid']) log_storage = self.cache.get(storage_key) log_queue = self.queues.rpop("statistics-search-result") assert record_ids == log_storage['record_ids'] assert results_final_colls_scores == \ log_queue['results_final_colls_scores'] def test_log_search_analytics(self): obelix = self.obelix user_info = {'uid': 1, 'remote_ip': "127.0.0.1", "uri": "testuri"} record_ids = [[1, 88], [1, 2]] results_final_colls_scores = [[0.3, 0.5], [0.5, 0.2]] cols_in_result_ordered = ["Thesis", "Another"] seconds_to_rank_and_print = 2 jrec, rg, rm, cc = 0, 10, "recommendations", "obelix" obelix.log('search_result', user_info, record_ids, record_ids, results_final_colls_scores, cols_in_result_ordered, seconds_to_rank_and_print, jrec, rg, rm, cc) # TODO: Check if own queue are needed # log_queue = queues.lpop("statistics-search-result::1") log_queue = self.queues.lpop("statistics-search-result") assert str(user_info['uid']) == str(log_queue['uid']) assert user_info['remote_ip'] == log_queue['remote_ip'] def test_log_page_view(self): obelix = self.obelix user_info = {'uid': 1, 'remote_ip': "127.0.0.1", "uri": "testuri"} record_ids = [[1, 88], [1, 2]] results_final_colls_scores = [[0.3, 0.5], [0.5, 0.2]] cols_in_result_ordered = ["Thesis", "Another"] seconds_to_rank_and_print = 2 jrec, rg, rm, cc = 0, 10, "recommendations", "obelix" obelix.log('search_result', user_info, record_ids, record_ids, results_final_colls_scores, cols_in_result_ordered, seconds_to_rank_and_print, jrec, rg, rm, cc) obelix.log('page_view', user_info, 1) logged = self.queues.lpop("statistics-page-view") assert str(logged['uid']) == '1' # TODO: check cache "last-search-result" logged = self.queues.lpop("logentries") assert logged['type'] == "events.pageviews" assert str(logged['user']) == '1' def test_log_page_view_after_search_error(self): """ There should be no statistics because there was no search before """ # TODO: Improve test obelix = self.obelix user_info = {'uid': 1, 'remote_ip': "127.0.0.1", "uri": "testuri"} record_ids = [[1, 88], [1, 2]] obelix.log('page_view_after_search', user_info, record_ids) logged = self.queues.lpop("statistics-page-view") assert logged is None # TODO: check cache "last-search-result" logged = self.queues.lpop("logentries") assert logged['type'] == "events.pageviews" assert str(logged['user']) == '1' def test_log_download_after_search(self): obelix = self.obelix user_info = {'uid': 5, 'remote_ip': "127.0.0.1", "uri": "testuri.pdf"} record_ids = [[1, 88], [1, 2]] results_final_colls_scores = [[0.3, 0.5], [0.5, 0.2]] cols_in_result_ordered = ["Thesis", "Another"] seconds_to_rank_and_print = 2 downloaded_record = 88 jrec, rg, rm, cc = 0, 10, "recommendations", "obelix" # log search obelix.log('search_result', user_info, record_ids, record_ids, results_final_colls_scores, cols_in_result_ordered, seconds_to_rank_and_print, jrec, rg, rm, cc) obelix.log('download_after_search', user_info, downloaded_record) # 'last-search-result::5' logged = self.queues.lpop("statistics-search-result") assert str(logged['uid']) == '5' # TODO: check cache "last-search-result" logged = self.queues.lpop("logentries") assert logged['type'] == "events.downloads" assert str(logged['user']) == '5'