Example #1
0
def test_login():
    client = HttpClient()

    raw_args = {
        'method': 'auth.login',
        'params': ['deluge'],
        'id': 0,
    }

    d = client.post('http://localhost:8112/json', DelugeWebUIBodyProducer('auth.login', ['deluge']))

    def parse_response(response):
        pprint.pprint(response)

    def on_post_success(result):
        assert result.code == 200

        finished = Deferred()
        finished.addCallback(parse_response)

        pprint.pprint(list(result.headers.getAllRawHeaders()))

        reader = SimpleContentProtocol(finished, json.loads)
        result.deliverBody(reader)

        return finished

    d.addCallback(on_post_success)

    return d
Example #2
0
def test_feed_request():
    client = HttpClient()

    d = client.get("http://hasthelhcdestroyedtheearth.com/rss.xml")

    def parse_feed(feed):
        assert "bozo_exception" not in feed
        assert feed["feed"]["title"] == "Has the Large Hadron Collider destroyed the earth yet?"
        assert feed["feed"]["language"] == "en-us"
        assert feed["entries"][0]["title"] == "NO."
        assert feed["entries"][0]["description"] == "NO."

    def on_get_success(result):
        assert result.code == 200

        finished = Deferred()
        finished.addCallback(parse_feed)

        reader = SimpleContentProtocol(finished, feedparser.parse)
        result.deliverBody(reader)

        return finished

    d.addCallback(on_get_success)

    return d