Переглянути джерело

[update] :heavy_check_mark: test

jhao 6 роки тому
батько
коміт
1a36662838

+ 3 - 3
setting.py

@@ -37,7 +37,7 @@ PORT = 5000
 # example:
 #      Redis: redis://:password@ip:port/db
 #      Ssdb:  ssdb://:password@ip:port
-DB_CONN = 'redis://:_@Fintell@10.10.61.65:6379'
+DB_CONN = 'redis://:pwd@127.0.0.1:6379/0'
 
 # proxy table name
 TABLE_NAME = 'use_proxy'
@@ -47,13 +47,13 @@ TABLE_NAME = 'use_proxy'
 PROXY_FETCHER = [
     "freeProxy01",
     # "freeProxy02",
-    "freeProxy03",
+    # "freeProxy03",
     "freeProxy04",
     "freeProxy05",
     # "freeProxy06",
     "freeProxy07",
     # "freeProxy08",
-    "freeProxy09",
+    # "freeProxy09",
     "freeProxy13",
     "freeProxy14",
     "freeProxy15",

+ 9 - 0
test.py

@@ -13,6 +13,15 @@
 __author__ = 'JHao'
 
 from test import testConfigHandler
+from test import testLogHandler
+from test import testDbClient
 
 if __name__ == '__main__':
+    print("ConfigHandler:")
     testConfigHandler.testConfig()
+
+    print("LogHandler:")
+    testLogHandler.testLogHandler()
+
+    print("DbClient:")
+    testDbClient.testDbClient()

+ 1 - 1
test/__init__.py

@@ -10,4 +10,4 @@
                    2019/2/15:
 -------------------------------------------------
 """
-__author__ = 'JHao'
+__author__ = 'JHao'

+ 1 - 2
test/testConfigHandler.py

@@ -24,8 +24,7 @@ def testConfig():
     print(conf.dbConn)
     print(conf.serverPort)
     print(conf.serverHost)
-    print(conf.useProxy)
-    print(conf.rawProxy)
+    print(conf.tableName)
     assert isinstance(conf.fetchers, list)
     print(conf.fetchers)
 

+ 6 - 2
test/testDbClient.py

@@ -14,7 +14,8 @@ __author__ = 'JHao'
 
 from db.dbClient import DbClient
 
-if __name__ == '__main__':
+
+def testDbClient():
     #  ############### ssdb ###############
     ssdb_uri = "ssdb://:password@127.0.0.1:8888"
     s = DbClient.parseDbConn(ssdb_uri)
@@ -31,5 +32,8 @@ if __name__ == '__main__':
     assert r.db_host == "127.0.0.1"
     assert r.db_port == 6379
     assert r.db_name == "1"
-
     print("DbClient ok!")
+
+
+if __name__ == '__main__':
+    testDbClient()

+ 0 - 37
test/testGetFreeProxy.py

@@ -1,37 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
--------------------------------------------------
-   File Name:     testGetFreeProxy
-   Description :   test model ProxyGetter/getFreeProxy
-   Author :        J_hao
-   date:          2017/7/31
--------------------------------------------------
-   Change Activity:
-                   2017/7/31:function testGetFreeProxy
--------------------------------------------------
-"""
-__author__ = 'J_hao'
-
-
-from fetcher.getFreeProxy import GetFreeProxy
-from config.ConfigGetter import config
-
-
-def testGetFreeProxy():
-    """
-    test class GetFreeProxy in ProxyGetter/GetFreeProxy
-    :return:
-    """
-    proxy_getter_functions = config.proxy_getter_functions
-    for proxyGetter in proxy_getter_functions:
-        proxy_count = 0
-        for proxy in getattr(GetFreeProxy, proxyGetter.strip())():
-            if proxy:
-                print('{func}: fetch proxy {proxy},proxy_count:{proxy_count}'.format(func=proxyGetter, proxy=proxy,
-                                                                                     proxy_count=proxy_count))
-                proxy_count += 1
-        # assert proxy_count >= 20, '{} fetch proxy fail'.format(proxyGetter)
-
-
-if __name__ == '__main__':
-    testGetFreeProxy()

+ 3 - 13
test/testLogHandler.py

@@ -12,23 +12,13 @@
 """
 __author__ = 'J_hao'
 
-from util.LogHandler import LogHandler
+from handler.logHandler import LogHandler
 
 
-# noinspection PyPep8Naming
 def testLogHandler():
-    """
-    test function LogHandler  in Util/LogHandler
-    :return:
-    """
     log = LogHandler('test')
-    log.info('this is a log from test')
-
-    log.resetName(name='test1')
-    log.info('this is a log from test1')
-
-    log.resetName(name='test2')
-    log.info('this is a log from test2')
+    log.info('this is info')
+    log.error('this is error')
 
 
 if __name__ == '__main__':

+ 6 - 5
test/testProxyClass.py

@@ -13,21 +13,22 @@
 __author__ = 'JHao'
 
 import json
-from helper import Proxy
+from helper.proxy import Proxy
 
 
 def testProxyClass():
     proxy = Proxy("127.0.0.1:8080")
 
-    print(proxy.info_dict)
+    print(proxy.to_json)
 
     proxy.source = "test"
 
-    proxy_str = json.dumps(proxy.info_dict, ensure_ascii=False)
+    proxy_str = json.dumps(proxy.to_dict, ensure_ascii=False)
 
     print(proxy_str)
 
-    print(Proxy.newProxyFromJson(proxy_str).info_dict)
+    print(Proxy.createFromJson(proxy_str).to_dict)
 
 
-testProxyClass()
+if __name__ == '__main__':
+    testProxyClass()

+ 12 - 37
test/testProxyFetcher.py

@@ -13,45 +13,20 @@
 __author__ = 'JHao'
 
 from fetcher.proxyFetcher import ProxyFetcher
+from handler.configHandler import ConfigHandler
 
 
-def test():
-    # for _ in ProxyFetcher.freeProxy01():
-    #     print(_)
-    #
-    # for _ in ProxyFetcher.freeProxy02():
-    #     print(_)
-    #
-    # for _ in ProxyFetcher.freeProxy03():
-    #     print(_)
-    #
-    # for _ in ProxyFetcher.freeProxy04():
-    #     print(_)
-    #
-    # for _ in ProxyFetcher.freeProxy05():
-    #     print(_)
-    #
-    # for _ in ProxyFetcher.freeProxy06():
-    #     print(_)
-    #
-    # for _ in ProxyFetcher.freeProxy07():
-    #     print(_)
-    #
-    # for _ in ProxyFetcher.freeProxy08():
-    #     print(_)
-    #
-    # for _ in ProxyFetcher.freeProxy09():
-    #     print(_)
-
-    # for _ in ProxyFetcher.freeProxy13():
-    #     print(_)
-
-    # for _ in ProxyFetcher.freeProxy14():
-    #     print(_)
-
-    for _ in ProxyFetcher.freeProxy15():
-        print(_)
+def testProxyFetcher():
+    conf = ConfigHandler()
+    proxy_getter_functions = conf.fetchers
+    for proxyGetter in proxy_getter_functions:
+        proxy_count = 0
+        for proxy in getattr(ProxyFetcher, proxyGetter.strip())():
+            if proxy:
+                print('{func}: fetch proxy {proxy},proxy_count:{proxy_count}'.format(func=proxyGetter, proxy=proxy,
+                                                                                     proxy_count=proxy_count))
+                proxy_count += 1
 
 
 if __name__ == '__main__':
-    test()
+    testProxyFetcher()

+ 1 - 1
test/testRedisClient.py

@@ -17,7 +17,7 @@ def testRedisClient():
     from db.dbClient import DbClient
     from helper.proxy import Proxy
 
-    uri = "redis://:_@Fintell@10.10.61.65:6379"
+    uri = "redis://:pwd@127.0.0.1:6379"
     db = DbClient(uri)
     db.changeTable("use_proxy")
     proxy = Proxy.createFromJson(

+ 4 - 2
test/testSsdbClient.py

@@ -17,7 +17,7 @@ def testSsdbClient():
     from db.dbClient import DbClient
     from helper.proxy import Proxy
 
-    uri = "ssdb://@120.79.78.193:8888"
+    uri = "ssdb://@127.0.0.1:8888"
     db = DbClient(uri)
     db.changeTable("use_proxy")
     proxy = Proxy.createFromJson(
@@ -34,7 +34,9 @@ def testSsdbClient():
 
     print("getAll: ", db.getAll())
 
-    print("pop: ", db.pop())
+    # print("pop: ", db.pop())
+
+    print("clear: ", db.clear())
 
     print("getCount", db.getCount())
 

+ 0 - 30
test/testWebRequest.py

@@ -1,30 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
--------------------------------------------------
-   File Name:     testWebRequest
-   Description :   test class WebRequest
-   Author :        J_hao
-   date:          2017/7/31
--------------------------------------------------
-   Change Activity:
-                   2017/7/31: function testWebRequest
--------------------------------------------------
-"""
-__author__ = 'J_hao'
-
-from util.WebRequest import WebRequest
-
-
-# noinspection PyPep8Naming
-def testWebRequest():
-    """
-    test class WebRequest in Util/WebRequest.py
-    :return:
-    """
-    wr = WebRequest()
-    request_object = wr.get('https://www.baidu.com/')
-    assert request_object.status_code == 200
-
-
-if __name__ == '__main__':
-    testWebRequest()