Skip to content

Instantly share code, notes, and snippets.

@lrowe
Created February 23, 2016 19:29
Show Gist options
  • Save lrowe/b8a0baea089be076fd8f to your computer and use it in GitHub Desktop.
Save lrowe/b8a0baea089be076fd8f to your computer and use it in GitHub Desktop.
Pytest adaption of Pyramid tutorial tests
# Adapted from https://github.com/Pylons/pyramid/blob/1.6.1/docs/quick_tutorial/json/tutorial/tests.py
import pytest
# View tests
@pytest.yield_fixture
def config():
from pyramid import testing
yield testing.setUp()
testing.tearDown()
@pytest.fixture
def dummy_request():
from pyramid import testing
return testing.DummyRequest()
def test_view_home(config, dummy_request):
from .views import TutorialViews
inst = TutorialViews(dummy_request)
response = inst.home()
assert 'Home View' == response['name']
def test_view_hello(config, dummy_request):
from .views import TutorialViews
inst = TutorialViews(dummy_request)
response = inst.hello()
assert 'Hello View' == response['name']
# Functional tests
@pytest.fixture
def app():
from tutorial import main
return main({})
@pytest.fixture
def testapp(app):
from webtest import TestApp
return TestApp(app)
def test_functional_home(testapp):
res = testapp.get('/', status=200)
assert b'<h1>Hi Home View' in res.body
def test_functional_hello(testapp):
res = testapp.get('/howdy', status=200)
assert b'<h1>Hi Hello View' in res.body
def test_functional_hello_json(testapp):
res = testapp.get('/howdy.json', status=200)
assert b'{"name": "Hello View"}' in res.body
assert res.content_type == 'application/json'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment