Exemple #1
0
'''
import sys
import os
from apkcrawl.tests import get_projectpath

cur_file = os.path.realpath(__file__)
cur_dir = os.path.dirname(os.path.dirname(cur_file))
#crawl_path = os.path.dirname(os.path.dirname( cur_dir ))
#sys.path.append( crawl_path )
import unittest2 as unittest
from apkcrawl import settings
from apkcrawl.utils import random_proxy , proxy_lists

from apkcrawl.utils import ApkFileParser, ApkDumpFailError

projectpath = get_projectpath()
class TestSetting(unittest.TestCase): # pargma: no cover
    """ 项目配置测试 TestSettingBuild"""

    settings = settings

    def test_proxy_lists(self):
        """test_proxy_lists 测试代理列表"""
        proxies = proxy_lists( settings.PROXY_LIST_FILE )
        self.assertTrue( len(proxies) != 0)
        #print( random_proxy( proxies ) )

class TestApkParse(unittest.TestCase):
    """ TestApkParse 测试解析apk包信息"""

    def setUp(self):
Exemple #2
0
 def setUp(self):
     orig_spiders_dir = os.path.join(get_projectpath(), 'tests', 'feature',
                                     'searchspiders')
     sys.path.append(orig_spiders_dir)
     self.spiderman = SpiderManager(['feature.searchspiders'])
Exemple #3
0
        pipeline = self._apkparsepipecls()

        recrespipeline = self._recrespipcls()

        # 以不存在的文件做测试
        qitem['fileinfo']['file_name'] = 'dropitem_test.apk'
        try:
            pipeline.process_item(qitem)
        except DropItem, e:
            _qitem = recrespipeline.process_item(qitem)
            self.assertEquals(3001, _qitem['res_state'])
        else:
            self.assertTrue(False, "解析不存在的文件包下载资源队列后状态更新失败,目标状态为3001")

        # 以错误格式的包做解析测试
        qitem['fileinfo']['file_path'] = os.path.join(get_projectpath(),
                                                      "tests/tmp")
        qitem['fileinfo'][
            'file_name'] = "fbaafb5dbf0aa3f6d0ebb40709a52cd8a5104241.apk.bk"
        try:
            pipeline.process_item(qitem)
        except DropItem, e:
            _qitem = recrespipeline.process_item(qitem)
            self.assertEquals(3001, _qitem['res_state'])
        else:
            self.assertTrue(False, "解析格式错误的包后下载资源队列状态更新失败,目标状态为3001")

        qitem['res_state'] = state
        qitem['fileinfo']['file_name'], qitem['fileinfo'][
            'file_path'] = fname, fpath
        # 恢复初始状态
Exemple #4
0
 def setUp(self):
     orig_spiders_dir = os.path.join(get_projectpath() , 'tests', 'feature', 'searchspiders')
     sys.path.append(orig_spiders_dir)
     self.spiderman = SpiderManager(['feature.searchspiders'])
Exemple #5
0
        pipeline = self._apkparsepipecls()

        recrespipeline = self._recrespipcls()

        # 以不存在的文件做测试
        qitem['fileinfo']['file_name'] = 'dropitem_test.apk'
        try:
            pipeline.process_item( qitem )
        except  DropItem, e:
            _qitem = recrespipeline.process_item( qitem )
            self.assertEquals( 3001, _qitem['res_state'] ) 
        else:
            self.assertTrue(False , "解析不存在的文件包下载资源队列后状态更新失败,目标状态为3001")
        
        # 以错误格式的包做解析测试
        qitem['fileinfo']['file_path'] = os.path.join( get_projectpath(), "tests/tmp")
        qitem['fileinfo']['file_name'] = "fbaafb5dbf0aa3f6d0ebb40709a52cd8a5104241.apk.bk"
        try:
            pipeline.process_item( qitem )
        except DropItem, e:
            _qitem = recrespipeline.process_item( qitem )
            self.assertEquals( 3001, _qitem['res_state'] ) 
        else:
            self.assertTrue(False , "解析格式错误的包后下载资源队列状态更新失败,目标状态为3001")


        qitem['res_state'] = state
        qitem['fileinfo']['file_name'] , qitem['fileinfo']['file_path'] = fname,fpath
        # 恢复初始状态
        cur = pipeline.con.cursor()
        pipeline._update_state( qitem , state )