예제 #1
0
def test_parse(context, mocker):
    url = "http://example.org/"
    result = context.http.get(url)
    data = result.serialize()

    mocker.patch.object(context, "emit")

    rules = {'pattern': 'https://httpbin.org/*'}
    context.params["store"] = rules
    context.params["meta"] = {
        "title": ".//h1",
        "description": ".//p"
    }
    parse(context, data)
    assert context.emit.call_count == 1
    context.emit.assert_called_once_with(rule="fetch", data=ANY)

    # cleanup tags
    conn = connect_redis()
    conn.flushall()

    context.http.result = None
    context.params["store"] = None
    parse(context, data)
    assert data['url'] == 'https://www.iana.org/domains/example'
    assert data['title'] == 'Example Domain'
    assert data['description'].startswith('This domain is for')
    assert context.emit.call_count == 3, data
예제 #2
0
def test_parse(context, mocker):
    url = "http://example.org/"
    result = context.http.get(url)
    data = result.serialize()

    with mocker.patch.object(context, "emit"):
        rules = {'pattern': 'https://httpbin.org/*'}
        context.params["store"] = rules
        parse(context, data)
        assert context.emit.call_count == 1
        context.emit.assert_called_once_with(
            rule="fetch", data={"url": "https://www.iana.org/domains/example"})

    # cleanup tags
    conn = connect_redis()
    conn.flushall()

    with mocker.patch.object(context, "emit"):
        context.http.result = None
        context.params["store"] = None
        parse(context, data)
        assert context.emit.call_count == 2, data
예제 #3
0
def killthekitten():
    """Completely kill redis contents."""
    from memorious.core import connect_redis
    conn = connect_redis()
    conn.flushall()
예제 #4
0
class Base(object):
    conn = connect_redis()