1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
import unittest
import transaction
from pyramid import testing
def _initTestingDB():
from sqlalchemy import create_engine
from .models import (
DBSession,
Page,
Base
)
engine = create_engine('sqlite://')
Base.metadata.create_all(engine)
DBSession.configure(bind=engine)
with transaction.manager:
model = Page(title='FrontPage', body='This is the front page')
DBSession.add(model)
return DBSession
class WikiViewTests(unittest.TestCase):
def setUp(self):
self.session = _initTestingDB()
self.config = testing.setUp()
def tearDown(self):
self.session.remove()
testing.tearDown()
def test_wiki_view(self):
from tutorial.views import WikiViews
request = testing.DummyRequest()
inst = WikiViews(request)
response = inst.wiki_view()
self.assertEqual(response['title'], 'Wiki View')
class WikiFunctionalTests(unittest.TestCase):
def setUp(self):
from pyramid.paster import get_app
app = get_app('development.ini')
from webtest import TestApp
self.testapp = TestApp(app)
def tearDown(self):
from .models import DBSession
DBSession.remove()
def test_it(self):
res = self.testapp.get('/', status=200)
self.assertIn(b'Wiki: View', res.body)
res = self.testapp.get('/add', status=200)
self.assertIn(b'Add/Edit', res.body)
|