コード例 #1
0
    def test_redis_queue_rpush_lpop_with_encoder_prefix(self):
        queue = RedisQueue(RedisMock(), prefix='pre::', encoder=json)

        data1 = {"test": [1, 2, 3]}
        data2 = [1, 2, 3]
        queue.rpush("q1", 111111)
        queue.rpush("q2", 222222)
        queue.rpush("q1", data1)
        queue.rpush("q2", data2)
        queue.rpush("q1", 555555)
        queue.rpush("q2", 666666)

        assert queue.lpop("q1") == 111111
        assert queue.lpop("q1") == data1
        assert queue.lpop("q1") == 555555

        assert queue.lpop("q2") == 222222
        assert queue.lpop("q2") == data2
        assert queue.lpop("q2") == 666666
コード例 #2
0
ファイル: test_queue.py プロジェクト: ddaze/obelix-client
    def test_redis_queue_rpush_lpop_with_encoder_prefix(self):
        queue = RedisQueue(RedisMock(), prefix='pre::', encoder=json)

        data1 = {"test": [1, 2, 3]}
        data2 = [1, 2, 3]
        queue.rpush("q1", 111111)
        queue.rpush("q2", 222222)
        queue.rpush("q1", data1)
        queue.rpush("q2", data2)
        queue.rpush("q1", 555555)
        queue.rpush("q2", 666666)

        assert queue.lpop("q1") == 111111
        assert queue.lpop("q1") == data1
        assert queue.lpop("q1") == 555555

        assert queue.lpop("q2") == 222222
        assert queue.lpop("q2") == data2
        assert queue.lpop("q2") == 666666
コード例 #3
0
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'