More tests for browser.network.pastebin
This commit is contained in:
parent
6826a97910
commit
90c8078225
@ -1,6 +1,6 @@
|
||||
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||
|
||||
# Copyright 2016 Anna Kobak (avk) <arsana7@gmail.com>:
|
||||
# Copyright 2016 Anna Kobak (avk) <awerk@onet.eu>:
|
||||
#
|
||||
# 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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user