From 90c80782258c89a4c2612f73985fba15078803ad Mon Sep 17 00:00:00 2001 From: avk Date: Mon, 22 Feb 2016 16:09:57 +0100 Subject: [PATCH] More tests for browser.network.pastebin --- tests/unit/browser/network/test_pastebin.py | 41 +++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/tests/unit/browser/network/test_pastebin.py b/tests/unit/browser/network/test_pastebin.py index e0999bc60..1e237d58c 100644 --- a/tests/unit/browser/network/test_pastebin.py +++ b/tests/unit/browser/network/test_pastebin.py @@ -1,6 +1,6 @@ # vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: -# Copyright 2016 Anna Kobak (avk) : +# Copyright 2016 Anna Kobak (avk) : # # This file is part of qutebrowser. # @@ -25,7 +25,15 @@ from PyQt5.QtCore import QUrl from qutebrowser.browser.network import pastebin from qutebrowser.misc import httpclient -DATA = [{"name" : "XYZ", "title" : "hello world", "text" : "xyz. 123 \n 172ANB", "reply" : "abc" }] +DATA = [{"name" : "XYZ", "title" : "hello world", "text" : "xyz. 123 \n 172ANB", "reply" : "abc" }, + {"name" : "the name", "title" : "the title", "text" : "some Text", "reply" : "some parent"}] + +DATA_NOPARENT = [{"name" : "XYZ", "title" : "hello world", "text" : "xyz. 123 \n 172ANB"}, + {"name" : "the name", "title" : "the title", "text" : "some Text"}] + +HTTP_VALID = ["http://paste.the-compiler.org/view/ges83nt3", "http://paste.the-compiler.org/view/3gjnwg4"] + +HTTP_INVALID = ["http invalid", "http:/invalid.org"] class HTTPPostStub(httpclient.HTTPClient): @@ -50,7 +58,7 @@ def test_constructor(qapp): assert isinstance(client._client, httpclient.HTTPClient) @pytest.mark.parametrize('data', DATA) -def test_paste(data): +def test_paste_with_parent(data): client = pastebin.PastebinClient() http_stub = HTTPPostStub() client._client = http_stub @@ -58,3 +66,30 @@ def test_paste(data): assert http_stub.data == data assert http_stub.url == QUrl('http://paste.the-compiler.org/api/create') +@pytest.mark.parametrize('data', DATA_NOPARENT) +def test_paste_without_parent(data): + client = pastebin.PastebinClient() + http_stub = HTTPPostStub() + client._client = http_stub + client.paste(data["name"], data["title"], data["text"]) + assert http_stub.data == data + assert http_stub.url == QUrl('http://paste.the-compiler.org/api/create') + +@pytest.mark.parametrize('http', HTTP_VALID) +def test_on_client_success(http, qtbot): + client = pastebin.PastebinClient() + http_stub = HTTPPostStub() + client._client = http_stub + with qtbot.assertNotEmitted(client.error): + with qtbot.waitSignal(client.success): + client.on_client_success(http) + +@pytest.mark.parametrize('http', HTTP_INVALID) +def test_on_client_success_invalid_http(http, qtbot): + client = pastebin.PastebinClient() + http_stub = HTTPPostStub() + client._client = http_stub + with qtbot.assertNotEmitted(client.success): + with qtbot.waitSignal(client.error): + client.on_client_success(http) +