Skip to content

Instantly share code, notes, and snippets.

@mcdonc
Created October 1, 2014 19:30
Show Gist options
  • Save mcdonc/a317b66dd77df9d53ec4 to your computer and use it in GitHub Desktop.
Save mcdonc/a317b66dd77df9d53ec4 to your computer and use it in GitHub Desktop.
# views.py
from pyramid.view import view_config
@view_config(route_name='home', renderer='templates/mytemplate.pt')
def my_view(request):
url = request.route_url('foo')
return {'project': 'myproj', 'url':url}
# tests.py
import unittest
from pyramid import testing
class ViewTests(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
self.config.add_route('foo', '/bar')
def tearDown(self):
testing.tearDown()
def test_my_view(self):
from .views import my_view
request = testing.DummyRequest()
info = my_view(request)
self.assertEqual(info['project'], 'myproj')
self.assertEqual(info['url'], 'http://example.com/bar')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment