Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d6e511fc authored by Cqoicebordel's avatar Cqoicebordel
Browse files

Twitter's unit test

There is a commented line of a test that I didn't succed to make it work. It's an issue of unicode, utf-8, ascii, latin1... I think I tried everything, but if you have an idea... I'm still a newbie in python...
parent a96208be
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -13,8 +13,8 @@
from urlparse import urljoin
from urllib import urlencode
from lxml import html
from cgi import escape
from datetime import datetime
from searx.engines.xpath import extract_text

# engine dependent config
categories = ['social media']
@@ -27,7 +27,7 @@ search_url = base_url+'search?'
# specific xpath variables
results_xpath = '//li[@data-item-type="tweet"]'
link_xpath = './/small[@class="time"]//a'
title_xpath = './/span[@class="username js-action-profile-name"]//text()'
title_xpath = './/span[@class="username js-action-profile-name"]'
content_xpath = './/p[@class="js-tweet-text tweet-text"]'
timestamp_xpath = './/span[contains(@class,"_timestamp")]'

@@ -39,6 +39,8 @@ def request(query, params):
    # set language if specified
    if params['language'] != 'all':
        params['cookies']['lang'] = params['language'].split('_')[0]
    else:
        params['cookies']['lang'] = 'en'

    return params

@@ -53,8 +55,9 @@ def response(resp):
    for tweet in dom.xpath(results_xpath):
        link = tweet.xpath(link_xpath)[0]
        url = urljoin(base_url, link.attrib.get('href'))
        title = ''.join(tweet.xpath(title_xpath))
        content = escape(html.tostring(tweet.xpath(content_xpath)[0], method='text', encoding='UTF-8').decode("utf-8"))
        title = extract_text(tweet.xpath(title_xpath))
        content = extract_text(tweet.xpath(content_xpath)[0])

        pubdate = tweet.xpath(timestamp_xpath)
        if len(pubdate) > 0:
            timestamp = float(pubdate[0].attrib.get('data-time'))
+502 −0

File added.

Preview size limit exceeded, changes collapsed.

+1 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ from searx.tests.engines.test_searchcode_code import * # noqa
from searx.tests.engines.test_searchcode_doc import *  # noqa
from searx.tests.engines.test_soundcloud import *  # noqa
from searx.tests.engines.test_stackoverflow import *  # noqa
from searx.tests.engines.test_twitter import *  # noqa
from searx.tests.engines.test_vimeo import *  # noqa
from searx.tests.engines.test_www500px import *  # noqa
from searx.tests.engines.test_youtube import *  # noqa