Modernize test suite
This modernizes the lodgeit testsuite to use stestr instead of nose. The primary reason for this is nose is not python3.10 compatible and we would like to use newer python with lodgeit. Change-Id: I8ae480d22bbef0258afc9d6ffd6cd820993430a1
This commit is contained in:
parent
bc2678dc73
commit
9e2d54bb5a
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
bootstrap.py
|
bootstrap.py
|
||||||
.tox
|
.tox
|
||||||
|
.stestr/
|
||||||
.project
|
.project
|
||||||
.pydevproject
|
.pydevproject
|
||||||
.settings
|
.settings
|
||||||
|
3
.stestr.conf
Normal file
3
.stestr.conf
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[DEFAULT]
|
||||||
|
test_path=./tests/unittest
|
||||||
|
top_dir=./
|
@ -61,7 +61,8 @@
|
|||||||
- tox-pep8
|
- tox-pep8
|
||||||
- tox-py36:
|
- tox-py36:
|
||||||
nodeset: ubuntu-bionic
|
nodeset: ubuntu-bionic
|
||||||
- tox-py38
|
- tox-py38:
|
||||||
|
nodeset: ubuntu-focal
|
||||||
- opendev-buildset-registry
|
- opendev-buildset-registry
|
||||||
- lodgeit-build-opendev-image
|
- lodgeit-build-opendev-image
|
||||||
gate:
|
gate:
|
||||||
@ -69,7 +70,8 @@
|
|||||||
- tox-pep8
|
- tox-pep8
|
||||||
- tox-py36:
|
- tox-py36:
|
||||||
nodeset: ubuntu-bionic
|
nodeset: ubuntu-bionic
|
||||||
- tox-py38
|
- tox-py38:
|
||||||
|
nodeset: ubuntu-focal
|
||||||
- opendev-buildset-registry
|
- opendev-buildset-registry
|
||||||
- lodgeit-upload-opendev-image
|
- lodgeit-upload-opendev-image
|
||||||
promote:
|
promote:
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
flake8
|
flake8
|
||||||
nose
|
python-subunit
|
||||||
|
stestr>=1.0.0 # Apache-2.0
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
|
import unittest
|
||||||
|
|
||||||
from werkzeug.test import Client
|
from werkzeug.test import Client
|
||||||
from werkzeug.wrappers import BaseResponse
|
from werkzeug.wrappers import BaseResponse
|
||||||
from lodgeit.application import make_app
|
|
||||||
from json import loads
|
|
||||||
|
|
||||||
client = Client(make_app('sqlite://', 'NONE', False, True), BaseResponse)
|
from lodgeit.application import db, make_app
|
||||||
|
from lodgeit.models import Paste
|
||||||
|
from json import loads
|
||||||
|
|
||||||
|
|
||||||
def is_json(response):
|
def is_json(response):
|
||||||
@ -19,3 +21,15 @@ def json(response):
|
|||||||
like JSON before parsing.
|
like JSON before parsing.
|
||||||
"""
|
"""
|
||||||
return loads(response.data)
|
return loads(response.data)
|
||||||
|
|
||||||
|
|
||||||
|
class BaseTestCase(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.client = Client(
|
||||||
|
make_app('sqlite://', 'NONE', False, True), BaseResponse)
|
||||||
|
|
||||||
|
def teardown(self):
|
||||||
|
Paste.query.delete()
|
||||||
|
db.session.commit()
|
||||||
|
db.session.remove()
|
||||||
|
super().teardown()
|
||||||
|
@ -1,78 +1,69 @@
|
|||||||
from tests import client, is_json, json
|
from tests import BaseTestCase, is_json, json
|
||||||
from tests.utilities.runner import testcase
|
|
||||||
from lodgeit.lib.highlighting import STYLES
|
from lodgeit.lib.highlighting import STYLES
|
||||||
|
|
||||||
|
|
||||||
def post_json(method, data=None):
|
class APITestCase(BaseTestCase):
|
||||||
return client.post('/json/', query_string={'method': method},
|
def post_json(self, method, data=None):
|
||||||
data=data, content_type='application/json')
|
return self.client.post('/json/', query_string={'method': method},
|
||||||
|
data=data, content_type='application/json')
|
||||||
|
|
||||||
|
def test_json_post_and_get(self):
|
||||||
|
data = '{"language": "text", "code": "hello world"}'
|
||||||
|
resp = self.post_json('pastes.newPaste', data)
|
||||||
|
|
||||||
@testcase()
|
|
||||||
def test_json_post_and_get():
|
|
||||||
data = '{"language": "text", "code": "hello world"}'
|
|
||||||
resp = post_json('pastes.newPaste', data)
|
|
||||||
|
|
||||||
assert is_json(resp)
|
|
||||||
resp = post_json('pastes.getPaste',
|
|
||||||
'{"paste_id": "%d"}' % int(json(resp)['data']))
|
|
||||||
assert is_json(resp)
|
|
||||||
assert json(resp)['data']['code'] == "hello world"
|
|
||||||
assert json(resp)['data']['language'] == "text"
|
|
||||||
|
|
||||||
|
|
||||||
@testcase()
|
|
||||||
def test_json_post_private_and_get():
|
|
||||||
data = '{"language": "text", "code": "hello world", "private": "true"}'
|
|
||||||
resp = post_json('pastes.newPaste', data)
|
|
||||||
|
|
||||||
assert is_json(resp)
|
|
||||||
resp = post_json('pastes.getPaste',
|
|
||||||
'{"paste_id": "%s"}' % json(resp)['data'])
|
|
||||||
assert is_json(resp)
|
|
||||||
assert json(resp)['data']['code'] == "hello world"
|
|
||||||
assert json(resp)['data']['language'] == "text"
|
|
||||||
|
|
||||||
|
|
||||||
@testcase()
|
|
||||||
def test_json_get_last():
|
|
||||||
data = '{"language": "text", "code": "hello world"}'
|
|
||||||
resp = post_json('pastes.newPaste', data)
|
|
||||||
assert is_json(resp)
|
|
||||||
|
|
||||||
data = '{"language": "text", "code": "hello world again"}'
|
|
||||||
resp = post_json('pastes.newPaste', data)
|
|
||||||
assert is_json(resp)
|
|
||||||
|
|
||||||
resp = post_json('pastes.getLast')
|
|
||||||
assert is_json(resp)
|
|
||||||
assert json(resp)['data']['code'] == "hello world again"
|
|
||||||
assert json(resp)['data']['language'] == "text"
|
|
||||||
|
|
||||||
|
|
||||||
@testcase()
|
|
||||||
def test_json_get_recent():
|
|
||||||
def run(inc):
|
|
||||||
data = '{"language": "text", "code": "hello world %s"}' % inc
|
|
||||||
resp = post_json('pastes.newPaste', data)
|
|
||||||
assert is_json(resp)
|
assert is_json(resp)
|
||||||
return resp
|
resp = self.post_json('pastes.getPaste',
|
||||||
|
'{"paste_id": "%d"}' % int(json(resp)['data']))
|
||||||
|
assert is_json(resp)
|
||||||
|
assert json(resp)['data']['code'] == "hello world"
|
||||||
|
assert json(resp)['data']['language'] == "text"
|
||||||
|
|
||||||
paste_ids = []
|
def test_json_post_private_and_get(self):
|
||||||
for x in range(10):
|
data = '{"language": "text", "code": "hello world", "private": "true"}'
|
||||||
resp = run(x)
|
resp = self.post_json('pastes.newPaste', data)
|
||||||
paste_ids.append(int(json(resp)['data']))
|
|
||||||
|
|
||||||
resp = post_json('pastes.getRecent', '{"amount": 7}')
|
assert is_json(resp)
|
||||||
assert is_json(resp)
|
resp = self.post_json('pastes.getPaste',
|
||||||
assert len(json(resp)['data']) == 7
|
'{"paste_id": "%s"}' % json(resp)['data'])
|
||||||
ids = [x['paste_id'] for x in json(resp)['data']]
|
assert is_json(resp)
|
||||||
assert ids[::-1] == paste_ids[3:]
|
assert json(resp)['data']['code'] == "hello world"
|
||||||
|
assert json(resp)['data']['language'] == "text"
|
||||||
|
|
||||||
|
def test_json_get_last(self):
|
||||||
|
data = '{"language": "text", "code": "hello world"}'
|
||||||
|
resp = self.post_json('pastes.newPaste', data)
|
||||||
|
assert is_json(resp)
|
||||||
|
|
||||||
@testcase()
|
data = '{"language": "text", "code": "hello world again"}'
|
||||||
def test_json_get_styles():
|
resp = self.post_json('pastes.newPaste', data)
|
||||||
resp = post_json('styles.getStyles')
|
assert is_json(resp)
|
||||||
assert is_json(resp)
|
|
||||||
expected = [[u'%s' % x, u'%s' % STYLES[x]] for x in STYLES]
|
resp = self.post_json('pastes.getLast')
|
||||||
assert json(resp)['data'] == expected
|
assert is_json(resp)
|
||||||
|
assert json(resp)['data']['code'] == "hello world again"
|
||||||
|
assert json(resp)['data']['language'] == "text"
|
||||||
|
|
||||||
|
def test_json_get_recent(self):
|
||||||
|
def run(inc):
|
||||||
|
data = '{"language": "text", "code": "hello world %s"}' % inc
|
||||||
|
resp = self.post_json('pastes.newPaste', data)
|
||||||
|
assert is_json(resp)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
paste_ids = []
|
||||||
|
for x in range(10):
|
||||||
|
resp = run(x)
|
||||||
|
paste_ids.append(int(json(resp)['data']))
|
||||||
|
|
||||||
|
resp = self.post_json('pastes.getRecent', '{"amount": 7}')
|
||||||
|
assert is_json(resp)
|
||||||
|
assert len(json(resp)['data']) == 7
|
||||||
|
ids = [x['paste_id'] for x in json(resp)['data']]
|
||||||
|
assert ids[::-1] == paste_ids[3:]
|
||||||
|
|
||||||
|
def test_json_get_styles(self):
|
||||||
|
resp = self.post_json('styles.getStyles')
|
||||||
|
assert is_json(resp)
|
||||||
|
expected = [[u'%s' % x, u'%s' % STYLES[x]] for x in STYLES]
|
||||||
|
assert json(resp)['data'] == expected
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
from tests import client
|
from tests import BaseTestCase
|
||||||
|
|
||||||
|
|
||||||
def test_get_urls():
|
class URLTestCase(BaseTestCase):
|
||||||
rules = [
|
def test_get_urls(self):
|
||||||
('/', 200),
|
rules = [
|
||||||
('/all/', 200),
|
('/', 200),
|
||||||
('/all/1/', 200),
|
('/all/', 200),
|
||||||
('/xmlrpc/', 200),
|
('/all/1/', 200),
|
||||||
('/json/', 200),
|
('/xmlrpc/', 200),
|
||||||
('/about/', 200),
|
('/json/', 200),
|
||||||
('/help/', 200),
|
('/about/', 200),
|
||||||
('/help/advanced/', 200),
|
('/help/', 200),
|
||||||
('/help/api/', 200),
|
('/help/advanced/', 200),
|
||||||
('/help/integration/', 200),
|
('/help/api/', 200),
|
||||||
('/help/pasting/', 200),
|
('/help/integration/', 200),
|
||||||
('/language/de/', 302),
|
('/help/pasting/', 200),
|
||||||
('/language/en/', 302),
|
('/language/de/', 302),
|
||||||
]
|
('/language/en/', 302),
|
||||||
for rule, code in rules:
|
]
|
||||||
resp = client.get(rule)
|
for rule, code in rules:
|
||||||
assert code == resp.status_code
|
resp = self.client.get(rule)
|
||||||
|
assert code == resp.status_code
|
||||||
|
|
||||||
|
def test_post_url(self):
|
||||||
def test_post_url():
|
resp = self.client.post('/')
|
||||||
resp = client.post('/')
|
assert 200 == resp.status_code
|
||||||
assert 200 == resp.status_code
|
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
from nose import with_setup
|
|
||||||
|
|
||||||
from lodgeit.application import db, make_app
|
|
||||||
from lodgeit.models import Paste
|
|
||||||
|
|
||||||
foo = make_app('sqlite://', 'NONE', False, True)
|
|
||||||
|
|
||||||
|
|
||||||
def setup():
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def teardown():
|
|
||||||
Paste.query.delete()
|
|
||||||
db.session.commit()
|
|
||||||
db.session.remove()
|
|
||||||
|
|
||||||
|
|
||||||
def testcase():
|
|
||||||
def dec(f):
|
|
||||||
return with_setup(setup, teardown)(f)
|
|
||||||
return dec
|
|
||||||
|
|
||||||
|
|
||||||
testcase.__test__ = False
|
|
3
tox.ini
3
tox.ini
@ -7,7 +7,8 @@ skipsdist = True
|
|||||||
setenv = VIRTUAL_ENV={envdir}
|
setenv = VIRTUAL_ENV={envdir}
|
||||||
deps = -r{toxinidir}/requirements.txt
|
deps = -r{toxinidir}/requirements.txt
|
||||||
-r{toxinidir}/test-requirements.txt
|
-r{toxinidir}/test-requirements.txt
|
||||||
commands = nosetests
|
commands = stestr --test-path ./tests/unittest run --no-subunit-trace {posargs}
|
||||||
|
stestr slowest
|
||||||
|
|
||||||
[testenv:pep8]
|
[testenv:pep8]
|
||||||
commands = flake8
|
commands = flake8
|
||||||
|
Loading…
Reference in New Issue
Block a user