tests for browser.network.pastebin - code refactor
This commit is contained in:
parent
90c8078225
commit
c9bb6d0111
@ -65,6 +65,8 @@ PERFECT_FILES = [
|
|||||||
'qutebrowser/browser/network/filescheme.py'),
|
'qutebrowser/browser/network/filescheme.py'),
|
||||||
('tests/unit/browser/network/test_networkreply.py',
|
('tests/unit/browser/network/test_networkreply.py',
|
||||||
'qutebrowser/browser/network/networkreply.py'),
|
'qutebrowser/browser/network/networkreply.py'),
|
||||||
|
('tests/unit/browser/network/test_pastebin.py',
|
||||||
|
'qutebrowser/browser/network/pastebin.py'),
|
||||||
('tests/unit/browser/test_signalfilter.py',
|
('tests/unit/browser/test_signalfilter.py',
|
||||||
'qutebrowser/browser/signalfilter.py'),
|
'qutebrowser/browser/signalfilter.py'),
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
"""Tests for qutebrowser.browser.network"""
|
"""Tests for qutebrowser.browser.network."""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from PyQt5.QtCore import QUrl
|
from PyQt5.QtCore import QUrl
|
||||||
@ -25,15 +25,6 @@ from PyQt5.QtCore import QUrl
|
|||||||
from qutebrowser.browser.network import pastebin
|
from qutebrowser.browser.network import pastebin
|
||||||
from qutebrowser.misc import httpclient
|
from qutebrowser.misc import httpclient
|
||||||
|
|
||||||
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):
|
class HTTPPostStub(httpclient.HTTPClient):
|
||||||
|
|
||||||
@ -46,50 +37,83 @@ class HTTPPostStub(httpclient.HTTPClient):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
self.url = None
|
||||||
|
self.data = None
|
||||||
|
|
||||||
def post(self, url, data):
|
def post(self, url, data=None):
|
||||||
self.url = url
|
self.url = url
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def pbclient():
|
||||||
|
client = pastebin.PastebinClient()
|
||||||
|
http_stub = HTTPPostStub()
|
||||||
|
client._client = http_stub
|
||||||
|
return client
|
||||||
|
|
||||||
|
|
||||||
def test_constructor(qapp):
|
def test_constructor(qapp):
|
||||||
client = pastebin.PastebinClient()
|
pbclient = pastebin.PastebinClient()
|
||||||
assert isinstance(client._client, httpclient.HTTPClient)
|
assert isinstance(pbclient._client, httpclient.HTTPClient)
|
||||||
|
|
||||||
@pytest.mark.parametrize('data', DATA)
|
|
||||||
def test_paste_with_parent(data):
|
@pytest.mark.parametrize('data', [
|
||||||
client = pastebin.PastebinClient()
|
{
|
||||||
http_stub = HTTPPostStub()
|
"name": "XYZ",
|
||||||
client._client = http_stub
|
"title": "hello world",
|
||||||
client.paste(data["name"], data["title"], data["text"], data["reply"])
|
"text": "xyz. 123 \n 172ANB",
|
||||||
|
"reply": "abc"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "the name",
|
||||||
|
"title": "the title",
|
||||||
|
"text": "some Text",
|
||||||
|
"reply": "some parent"
|
||||||
|
}
|
||||||
|
])
|
||||||
|
def test_paste_with_parent(data, pbclient):
|
||||||
|
http_stub = pbclient._client
|
||||||
|
pbclient.paste(data["name"], data["title"], data["text"], data["reply"])
|
||||||
assert http_stub.data == data
|
assert http_stub.data == data
|
||||||
assert http_stub.url == QUrl('http://paste.the-compiler.org/api/create')
|
assert http_stub.url == QUrl('http://paste.the-compiler.org/api/create')
|
||||||
|
|
||||||
@pytest.mark.parametrize('data', DATA_NOPARENT)
|
|
||||||
def test_paste_without_parent(data):
|
@pytest.mark.parametrize('data', [
|
||||||
client = pastebin.PastebinClient()
|
{
|
||||||
http_stub = HTTPPostStub()
|
"name": "XYZ",
|
||||||
client._client = http_stub
|
"title": "hello world",
|
||||||
client.paste(data["name"], data["title"], data["text"])
|
"text": "xyz. 123 \n 172ANB"
|
||||||
assert http_stub.data == data
|
},
|
||||||
|
{
|
||||||
|
"name": "the name",
|
||||||
|
"title": "the title",
|
||||||
|
"text": "some Text"
|
||||||
|
}
|
||||||
|
])
|
||||||
|
def test_paste_without_parent(data, pbclient):
|
||||||
|
http_stub = pbclient._client
|
||||||
|
pbclient.paste(data["name"], data["title"], data["text"])
|
||||||
|
assert pbclient._client.data == data
|
||||||
assert http_stub.url == QUrl('http://paste.the-compiler.org/api/create')
|
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)
|
@pytest.mark.parametrize('http', [
|
||||||
def test_on_client_success_invalid_http(http, qtbot):
|
"http://paste.the-compiler.org/view/ges83nt3",
|
||||||
client = pastebin.PastebinClient()
|
"http://paste.the-compiler.org/view/3gjnwg4"
|
||||||
http_stub = HTTPPostStub()
|
])
|
||||||
client._client = http_stub
|
def test_on_client_success(http, pbclient, qtbot):
|
||||||
with qtbot.assertNotEmitted(client.success):
|
with qtbot.assertNotEmitted(pbclient.error):
|
||||||
with qtbot.waitSignal(client.error):
|
with qtbot.waitSignal(pbclient.success):
|
||||||
client.on_client_success(http)
|
pbclient.on_client_success(http)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('http', [
|
||||||
|
"http invalid",
|
||||||
|
"http:/invalid.org"
|
||||||
|
"http//invalid.com"
|
||||||
|
])
|
||||||
|
def test_on_client_success_invalid_http(http, pbclient, qtbot):
|
||||||
|
with qtbot.assertNotEmitted(pbclient.success):
|
||||||
|
with qtbot.waitSignal(pbclient.error):
|
||||||
|
pbclient.on_client_success(http)
|
||||||
|
Loading…
Reference in New Issue
Block a user