示例#1
0
 def test_data_from_DB_1(self):
     data = get_cache("dbdirty1")
     assert data["id"] == "dbclean1"
     assert data["screamer_chance"] == 1.0
     # Retry the same
     data = get_cache("dbdirty1")
     assert data["id"] == "dbclean1"
     assert data["screamer_chance"] == "1.0"  # Should fix later
示例#2
0
    def test_data_from_DB_none(self):
        data = get_cache("dbdirtynone")
        assert data["id"] == "dbcleannone"
        assert data["screamer_chance"] is None

        dup_data = get_cache("dbdirtynone_dup")
        assert dup_data["id"] == "dbcleannone"
        assert dup_data["screamer_chance"] is None
示例#3
0
    def test_md5_same_clear(self):
        # Different md5, and shouldn't be incremented
        assert isinstance(check_ip_viewed("dbdirtynone_dup", self.ip), int)
        assert incr_views(self.ip, "dbdirtynone_dup") is True
        assert get_cache("dbdirtynone")["views"] == "3"

        # diff IP
        assert incr_views("12.21.52.1", "dbdirtynone_dup") is True
        assert get_cache("dbdirtynone")["views"] == "4"
示例#4
0
    def test_md5_in_cache(self):
        assert check_ip_viewed("dbdirtynone", self.ip) is False
        assert incr_views(self.ip, "dbdirtynone") is True
        assert get_cache("dbdirtynone")["views"] == "1"

        assert isinstance(check_ip_viewed("dbdirtynone", self.ip), int)

        assert incr_views(self.ip, "dbdirtynone") is True
        assert get_cache("dbdirtynone")["views"] == "2"
示例#5
0
文件: views.py 项目: bushig/webmtube
    def on_post(self, request, response):
        webm_list = request.context['doc']
        resp_data = []
        try:
            for webm in webm_list:
                md5 = webm["md5"]
                url = webm["url"]
                webm_response = None

                webm_redis_info = get_cache(md5)  # clean_md5, delayed or None
                if isinstance(webm_redis_info, dict):
                    webm_redis_info['md5'] = md5
                    webm_response = webm_redis_info
                elif webm_redis_info == "delayed":
                    webm_response = {"md5": md5, "message": "Уже анализируется"}
                elif webm_redis_info is None:
                    if is_valid_2ch_url(url):
                        analyse_video.delay(md5, url)
                        set_cache_delayed(md5)
                        webm_response = {"md5": md5, "message": "Добавлено в очередь на анализ"}
                    else:
                        webm_response = {"md5": md5, "message": "Неправильный url"}
                else:
                    webm_response = {"md5": md5, "message": "Some error"}

                resp_data.append(webm_response)
            request.context['result'] = resp_data


        except Exception as e:
            response.status = status_codes.HTTP_400
            request.context['result'] = {"message": "Неправильный запрос"}
            print("error in post request:", e)
示例#6
0
文件: views.py 项目: bushig/webmtube
 def on_get(self, request, response):
     md5 = request.get_param('md5')
     url = request.get_param('url')
     response.set_header("Access-Control-Allow-Origin", "*")
     webm_redis_info = get_cache(md5)  # data, delayed or None
     # print("redis:", webm_redis_info)
     # If data in cache
     if isinstance(webm_redis_info, dict):
         webm_redis_info['md5'] = md5
         response.status = status_codes.HTTP_200
         request.context['result'] = webm_redis_info
     # If webm is analysed
     elif webm_redis_info == "delayed":
         response.status = status_codes.HTTP_202
         request.context['result'] = {"md5": md5, "message": "Уже анализируется"}
     # If no cache data
     elif webm_redis_info is None:
         if is_valid_2ch_url(url):
             analyse_video.delay(md5, url)
             set_cache_delayed(md5)
             response.status = status_codes.HTTP_202
             request.context['result'] = {"md5": md5, "message": "Добавлено в очередь на анализ"}
         else:
             # not valid url
             response.status = status_codes.HTTP_400
             request.context['result'] = {"md5": md5,
                                          "message": "Неправильная ссылка в запросе"}
     else:
         response.status = status_codes.HTTP_502
         request.context['result'] = {"md5": md5,
                                      "message": "Some error"}
示例#7
0
 def test_existing_cache_with_0_screamer_chance(self):
     result = get_cache("md5scream0")
     assert result["screamer_chance"] == "0"
示例#8
0
 def test_existing_cache_with_none_screamer_chance(self):
     result = get_cache("md5screamnone")
     assert result["screamer_chance"] is None
示例#9
0
 def test_delayed_cache(self):
     assert get_cache("md5delay") == "delayed"
示例#10
0
 def test_not_existing_cache(self):
     assert get_cache("notexists") is None