2014-10-23 07:52:40 +08:00
|
|
|
import sys
|
|
|
|
import pytest
|
2009-09-06 22:59:39 +08:00
|
|
|
|
|
|
|
class TestPasting:
|
2014-10-23 07:52:40 +08:00
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def pastebinlist(self, monkeypatch, request):
|
2009-09-06 22:59:39 +08:00
|
|
|
pastebinlist = []
|
2009-10-17 18:56:59 +08:00
|
|
|
plugin = request.config.pluginmanager.getplugin('pastebin')
|
2014-10-23 07:52:40 +08:00
|
|
|
monkeypatch.setattr(plugin, 'create_new_paste', pastebinlist.append)
|
2010-07-27 03:15:15 +08:00
|
|
|
return pastebinlist
|
2009-09-06 22:59:39 +08:00
|
|
|
|
|
|
|
def test_failed(self, testdir, pastebinlist):
|
|
|
|
testpath = testdir.makepyfile("""
|
2010-11-18 05:12:16 +08:00
|
|
|
import pytest
|
2009-09-06 22:59:39 +08:00
|
|
|
def test_pass():
|
|
|
|
pass
|
|
|
|
def test_fail():
|
|
|
|
assert 0
|
|
|
|
def test_skip():
|
2010-11-18 05:12:16 +08:00
|
|
|
pytest.skip("")
|
2009-09-06 22:59:39 +08:00
|
|
|
""")
|
|
|
|
reprec = testdir.inline_run(testpath, "--paste=failed")
|
|
|
|
assert len(pastebinlist) == 1
|
2014-10-23 07:52:40 +08:00
|
|
|
s = pastebinlist[0]
|
2009-09-06 22:59:39 +08:00
|
|
|
assert s.find("def test_fail") != -1
|
|
|
|
assert reprec.countoutcomes() == [1,1,1]
|
|
|
|
|
|
|
|
def test_all(self, testdir, pastebinlist):
|
|
|
|
testpath = testdir.makepyfile("""
|
2010-11-18 05:12:16 +08:00
|
|
|
import pytest
|
2009-09-06 22:59:39 +08:00
|
|
|
def test_pass():
|
|
|
|
pass
|
|
|
|
def test_fail():
|
|
|
|
assert 0
|
|
|
|
def test_skip():
|
2010-11-18 05:12:16 +08:00
|
|
|
pytest.skip("")
|
2009-09-06 22:59:39 +08:00
|
|
|
""")
|
2014-10-23 07:52:40 +08:00
|
|
|
reprec = testdir.inline_run(testpath, "--pastebin=all", '-v')
|
2009-09-06 22:59:39 +08:00
|
|
|
assert reprec.countoutcomes() == [1,1,1]
|
|
|
|
assert len(pastebinlist) == 1
|
2014-10-23 07:52:40 +08:00
|
|
|
s = pastebinlist[0]
|
|
|
|
for x in 'test_fail test_skip test_pass'.split():
|
|
|
|
assert x in s
|
|
|
|
|
2010-07-27 03:15:15 +08:00
|
|
|
|
2014-10-23 07:52:40 +08:00
|
|
|
class TestPaste:
|
2011-11-15 00:51:12 +08:00
|
|
|
|
2014-10-23 07:52:40 +08:00
|
|
|
@pytest.fixture
|
|
|
|
def pastebin(self, request):
|
2011-11-15 00:51:12 +08:00
|
|
|
return request.config.pluginmanager.getplugin('pastebin')
|
|
|
|
|
2014-10-23 07:52:40 +08:00
|
|
|
@pytest.fixture
|
|
|
|
def mocked_urlopen(self, monkeypatch):
|
|
|
|
"""
|
|
|
|
monkeypatch the actual urlopen calls done by the internal plugin
|
|
|
|
function that connects to bpaste service.
|
|
|
|
"""
|
|
|
|
calls = []
|
|
|
|
def mocked(url, data):
|
|
|
|
calls.append((url, data))
|
|
|
|
class DummyFile:
|
|
|
|
def read(self):
|
|
|
|
# part of html of a normal response
|
|
|
|
return 'View <a href="/raw/3c0c6750bd">raw</a>.'
|
|
|
|
return DummyFile()
|
|
|
|
|
|
|
|
if sys.version_info < (3, 0):
|
|
|
|
import urllib
|
|
|
|
monkeypatch.setattr(urllib, 'urlopen', mocked)
|
|
|
|
else:
|
|
|
|
import urllib.request
|
|
|
|
monkeypatch.setattr(urllib.request, 'urlopen', mocked)
|
|
|
|
return calls
|
|
|
|
|
|
|
|
def test_create_new_paste(self, pastebin, mocked_urlopen):
|
|
|
|
result = pastebin.create_new_paste('full-paste-contents')
|
|
|
|
assert result == 'https://bpaste.net/show/3c0c6750bd'
|
|
|
|
assert len(mocked_urlopen) == 1
|
|
|
|
url, data = mocked_urlopen[0]
|
|
|
|
lexer = 'python3' if sys.version_info[0] == 3 else 'python'
|
|
|
|
assert url == 'https://bpaste.net'
|
|
|
|
assert 'lexer=%s' % lexer in data
|
|
|
|
assert 'code=full-paste-contents' in data
|
|
|
|
assert 'expiry=1week' in data
|
2011-11-15 00:51:12 +08:00
|
|
|
|
2013-10-12 21:39:22 +08:00
|
|
|
|