Skip to content

Instantly share code, notes, and snippets.

@fweep
Created August 13, 2013 20:15
Show Gist options
  • Save fweep/6225226 to your computer and use it in GitHub Desktop.
Save fweep/6225226 to your computer and use it in GitHub Desktop.
from pyramid.authentication import AuthTktAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
from myapp.tests.base import ViewTestBase
from myapp.views.authentication.login import login_view
from myapp.tests.helper import create_user
class LoginViewTests(ViewTestBase):
def setUp(self):
super(LoginViewTests, self).setUp()
self.config.add_route('home', '/')
authz_policy = ACLAuthorizationPolicy()
authn_policy = AuthTktAuthenticationPolicy('secret', hashalg='sha512')
self.config.set_authorization_policy(authz_policy)
self.config.set_authentication_policy(authn_policy)
def test_sets_cookie_on_success(self):
user = create_user()
from pyramid.request import Request
request = Request.blank('/authentication/login', base_url='http://example.com/')
request.method = "POST"
request.POST['login'] = user.login
request.POST['password'] = user.password
result = login_view(request)
self.assertTrue("Set-Cookie" in result.headers.keys())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment