Example #1
0
    def test_queries(self):
        self.assertEqual(self.db.queries_sent(), 0)
        self.assertEqual(self.db.queries_completed(), 0)

        self.db.store_msg(
            MonitorMsg(MonitorMsg.QUERY_SENT, -1, MonitorMsg.OK, 1, None))
        self.db.store_msg(
            MonitorMsg(MonitorMsg.QUERY_COMPLETED, -1, MonitorMsg.OK, 1, None))

        self.assertEqual(self.db.queries_sent(), 1)
        self.assertEqual(self.db.queries_completed(), 1)
Example #2
0
	def test_day_requests(self):
		self.assertEqual(self.db.yandex_search_requests(True), 0)

		msg = MonitorMsg(MonitorMsg.HTTP_SEARCH, Consts.Providers.YANDEX, MonitorMsg.OK, 1, None)
		self.db.store_msg(msg)

		one_day = datetime.datetime.utcnow() - datetime.timedelta(hours = 23, minutes = 59, seconds = 59)
		two_days = datetime.datetime.utcnow() - datetime.timedelta(days = 2)

		msg.timestamp = one_day
		self.db.store_msg(msg)

		msg.timestamp = two_days
		self.db.store_msg(msg)

		self.assertEqual(self.db.yandex_search_requests(True ,MonDB.SCOPE_DAY), 2)
Example #3
0
    def test_day_requests(self):
        self.assertEqual(self.db.yandex_search_requests(True), 0)

        msg = MonitorMsg(MonitorMsg.HTTP_SEARCH, Consts.Providers.YANDEX,
                         MonitorMsg.OK, 1, None)
        self.db.store_msg(msg)

        one_day = datetime.datetime.utcnow() - datetime.timedelta(
            hours=23, minutes=59, seconds=59)
        two_days = datetime.datetime.utcnow() - datetime.timedelta(days=2)

        msg.timestamp = one_day
        self.db.store_msg(msg)

        msg.timestamp = two_days
        self.db.store_msg(msg)

        self.assertEqual(self.db.yandex_search_requests(True, MonDB.SCOPE_DAY),
                         2)
Example #4
0
    def test_posts(self):
        self.assertEqual(self.db.posts_collected(), 0)
        self.assertEqual(self.db.posts_dublicate_detected(), 0)
        self.assertEqual(self.db.posts_update_detected(), 0)
        self.assertEqual(self.db.posts_new_link_detected(), 0)
        self.assertEqual(self.db.posts_persisted(), 0)

        self.db.store_msg(
            MonitorMsg(MonitorMsg.POST_COLLECTED, -1, MonitorMsg.OK, 1, None))
        self.db.store_msg(
            MonitorMsg(MonitorMsg.POST_DUBLICATE_DETECTED, -1, MonitorMsg.OK,
                       1, None))
        self.db.store_msg(
            MonitorMsg(MonitorMsg.POST_UPDATE_DETECTED, -1, MonitorMsg.OK, 1,
                       None))
        self.db.store_msg(
            MonitorMsg(MonitorMsg.POST_NEW_LINK_DETECTED, -1, MonitorMsg.OK, 1,
                       None))
        self.db.store_msg(
            MonitorMsg(MonitorMsg.POST_SPAM_DETECTED, -1, MonitorMsg.OK, 1,
                       None))
        self.db.store_msg(
            MonitorMsg(MonitorMsg.POST_PERSISTED, -1, MonitorMsg.OK, 1, None))

        self.assertEqual(self.db.posts_collected(), 1)
        self.assertEqual(self.db.posts_dublicate_detected(), 1)
        self.assertEqual(self.db.posts_update_detected(), 1)
        self.assertEqual(self.db.posts_new_link_detected(), 1)
        self.assertEqual(self.db.posts_persisted(), 1)
Example #5
0
    def test_http_requests(self):
        self.assertEqual(self.db.yandex_search_requests(True), 0)
        self.assertEqual(self.db.yandex_content_requests(True), 0)
        self.assertEqual(self.db.lj_content_requests(True), 0)
        self.assertEqual(self.db.vk_content_requests(True), 0)

        self.db.store_msg(
            MonitorMsg(MonitorMsg.HTTP_SEARCH, Consts.Providers.YANDEX,
                       MonitorMsg.OK, 1, None))
        self.db.store_msg(
            MonitorMsg(MonitorMsg.HTTP_CONTENT, Consts.Providers.YANDEX,
                       MonitorMsg.OK, None, 'http://test'))
        self.db.store_msg(
            MonitorMsg(MonitorMsg.HTTP_CONTENT, Consts.Providers.VK,
                       MonitorMsg.OK, None, 'http://test'))
        self.db.store_msg(
            MonitorMsg(MonitorMsg.HTTP_CONTENT, Consts.Providers.LJ,
                       MonitorMsg.OK, None, 'http://test'))

        self.assertEqual(self.db.yandex_search_requests(True), 1)
        self.assertEqual(self.db.yandex_content_requests(True), 1)
        self.assertEqual(self.db.lj_content_requests(True), 1)
        self.assertEqual(self.db.vk_content_requests(True), 1)
Example #6
0
    def test_http_requests_err(self):
        self.assertEqual(self.db.yandex_search_requests(False), 0)
        self.assertEqual(self.db.yandex_content_requests(False), 0)
        self.assertEqual(self.db.lj_content_requests(False), 0)
        self.assertEqual(self.db.vk_content_requests(False), 0)

        self.db.store_msg(
            MonitorMsg(MonitorMsg.HTTP_SEARCH, Consts.Providers.YANDEX,
                       MonitorMsg.ERROR, 1, 'error'))
        self.db.store_msg(
            MonitorMsg(MonitorMsg.HTTP_CONTENT, Consts.Providers.YANDEX,
                       MonitorMsg.ERROR, None, 'error'))
        self.db.store_msg(
            MonitorMsg(MonitorMsg.HTTP_CONTENT, Consts.Providers.VK,
                       MonitorMsg.ERROR, None, 'error'))
        self.db.store_msg(
            MonitorMsg(MonitorMsg.HTTP_CONTENT, Consts.Providers.LJ,
                       MonitorMsg.ERROR, None, 'error'))

        self.assertEqual(self.db.yandex_search_requests(False), 1)
        self.assertEqual(self.db.yandex_content_requests(False), 1)
        self.assertEqual(self.db.lj_content_requests(False), 1)
        self.assertEqual(self.db.vk_content_requests(False), 1)
Example #7
0
 def post_persisted(self, post_id, link):
     self.queue.put(
         MonitorMsg(MonitorMsg.POST_PERSISTED, -1, MonitorMsg.OK, post_id,
                    link))
Example #8
0
 def query_error(self, query_id):
     self.queue.put(
         MonitorMsg(MonitorMsg.QUERY_COMPLETED, -1, MonitorMsg.ERROR,
                    query_id, None))
Example #9
0
 def post_new_link_detected(self, link):
     self.queue.put(
         MonitorMsg(MonitorMsg.POST_NEW_LINK_DETECTED, -1, MonitorMsg.OK,
                    None, link))
Example #10
0
 def post_spam_detected(self, link):
     self.queue.put(
         MonitorMsg(MonitorMsg.POST_SPAM_DETECTED, -1, MonitorMsg.OK, None,
                    link))
Example #11
0
 def post_dublicate_detected(self, link):
     self.queue.put(
         MonitorMsg(MonitorMsg.POST_DUBLICATE_DETECTED, -1, MonitorMsg.OK,
                    None, link))
Example #12
0
 def search_http_error(self, provider, query_id, code, url):
     self.queue.put(
         MonitorMsg(MonitorMsg.HTTP_SEARCH, provider, MonitorMsg.ERROR,
                    query_id, "%s, %s" %
                    (code, url)))  # now only Yandex search is supported
Example #13
0
 def content_exception(self, provider, link, e):
     self.queue.put(
         MonitorMsg(MonitorMsg.HTTP_CONTENT, provider, MonitorMsg.ERROR,
                    None, str(e)))
Example #14
0
 def query_sent(self, query_id):
     self.queue.put(
         MonitorMsg(MonitorMsg.QUERY_SENT, -1, MonitorMsg.OK, query_id,
                    None))
Example #15
0
 def content_http_error(self, provider, code, url):
     self.queue.put(
         MonitorMsg(MonitorMsg.HTTP_CONTENT, provider, MonitorMsg.ERROR,
                    None, "%s, %s" % (code, url)))
Example #16
0
 def content_http_request(self, provider, link):
     self.queue.put(
         MonitorMsg(MonitorMsg.HTTP_CONTENT, provider, MonitorMsg.OK, None,
                    link))
Example #17
0
 def search_exception(self, provider, query_id, e):
     self.queue.put(
         MonitorMsg(MonitorMsg.HTTP_SEARCH, provider, MonitorMsg.ERROR,
                    query_id, str(e)))
Example #18
0
 def query_completed(self, query_id):
     self.queue.put(
         MonitorMsg(MonitorMsg.QUERY_COMPLETED, -1, MonitorMsg.OK, query_id,
                    None))
Example #19
0
 def post_update_detected(self, link):
     self.queue.put(
         MonitorMsg(MonitorMsg.POST_UPDATE_DETECTED, -1, MonitorMsg.OK,
                    None, link))
Example #20
0
 def post_collected(self, link):
     self.queue.put(
         MonitorMsg(MonitorMsg.POST_COLLECTED, -1, MonitorMsg.OK, None,
                    link))
Example #21
0
 def search_http_request(self, provider, query_id):
     self.queue.put(
         MonitorMsg(MonitorMsg.HTTP_SEARCH, provider, MonitorMsg.OK,
                    query_id, None))  # now only Yandex search is supported