def test_scrapeAppsWithExoticPermissions(): """ Scrape apps with no permissions, only other permissions, etc. Make sure scraper can correctly handle them. :return: """ testCases = { 'kr.co.kcp.wechatpaycheckout', 'com.om.calc', 'com.appdevgenie.electronicscalculator', 'com.androidapps.unitconverter', 'com.videos.freemusic.song.mp3.musicplayer.mv' } dbFilePath = os.path.join(testUtils.getTestFolder(), '../../data/db.sqlite3') if os.path.exists(dbFilePath): os.remove(dbFilePath) testUtils.runScraper(['--pytest', '-p', ','.join(testCases)]) assert os.path.exists(dbFilePath), "Database file is not created." connection = sqlite3.connect(dbFilePath) cursor = connection.cursor() cursor.execute('select id from App') s = set([r[0] for r in cursor.fetchall()]) failedCases = testCases - s if len(failedCases) > 0: pytest.fail('Failed to scrape ' + ', '.join(failedCases))
def test_searchCategoryFilter(websiteUrl, dbFilePath): # com.facebook.katana uses category 'Social' # we exclude this category in the search, and make sure the result doesn't have com.facebook.katana. testUtils.runScraper(['--pytest', '-p', 'com.facebook.katana']) connection = sqlite3.connect(dbFilePath) cursor = connection.cursor() categories = GooglePlayAdvancedSearch.DBUtils.getAllCategories(cursor) cid = next((k for k, v in categories.items() if 'Social' in v), None) response = requests.get(websiteUrl + '/Api/Search?q=facebook&cids=' + str(cid), verify=True) text = response.text assert 'com.facebook.katana' not in text, "Search for facebook without Social category. The search result should not have it." response = requests.get(websiteUrl + '/Api/Search?q=facebook', verify=True) text = response.text assert 'com.facebook.katana' in text, "Search for facebook allowing Social category. The search result should have it."
def callback_searchPermissionFilter(websiteUrl): # com.tencent.mm uses permission 'read the contents of your USB storage' # We exclude this permission in the search, and make sure the result doesn't have com.tencent.mm. testUtils.runScraper(['--pytest', '-p', 'com.tencent.mm']) dbFilePath = os.path.join(testUtils.getTestFolder(), '../../data/db.sqlite3') connection = sqlite3.connect(dbFilePath) cursor = connection.cursor() permissions = GooglePlayAdvancedSearch.DBUtils.getAllPermissions(cursor) pid = next((k for k, v in permissions.items() if 'read the contents of your USB storage' in v), None) response = requests.get(websiteUrl + '/Api/Search?q=wechat&pids=' + str(pid), verify=True) text = response.text assert 'com.tencent.mm' not in text, "Search for wechat without storage permission. The search result should not have wechat." response = requests.get(websiteUrl + '/Api/Search?q=wechat', verify=True) text = response.text assert 'com.tencent.mm' in text, "Search for wechat allowing storage permission. The search result not have wechat."
def test_sslVerify(): completed = testUtils.runScraper( ['--pytest', '--bad-ssl-url', 'https://expired.badssl.com/']) assert completed.returncode == GooglePlayAdvancedSearch.Errors.sslErrorCode, 'Expect to detect invalid SSL certificate'