Package spammcan :: Package tests :: Module test_controllers
[hide private]

Source Code for Module spammcan.tests.test_controllers

 1  import unittest 
 2  from turbogears import testutil 
 3  from spammcan.controllers import Root 
 4  from spammcan.model import User 
 5   
 6   
7 -class TestPages(testutil.TGTest):
8 9 root = Root 10
11 - def test_method(self):
12 """The index method should return a string called 'now'""" 13 response = self.app.get('/') 14 assert isinstance(response.raw['now'], str)
15
16 - def test_index_title(self):
17 """"The index page should have the right title.""" 18 response = self.app.get('/') 19 assert "<title>Welcome to TurboGears</title>" in response.body
20
21 - def test_login_title(self):
22 """The login page should have the right title.""" 23 response = self.app.get('/login') 24 assert "<title>Login</title>" in response 25 assert "Please log in." in response 26 assert "session cookies" not in response 27 assert "credentials" not in response 28 assert "not correct" not in response
29
30 - def test_login_errors(self):
31 """The login page should display the right errors.""" 32 login = '/login?user_name=nobody&password=wrong&login=Login' 33 response = self.app.get(login) 34 assert "<title>Login</title>" in response 35 assert "session cookies" in response 36 cookie = ', '.join(map(str, response.cookies_set.values())) 37 response = self.app.get(login, headers=dict(Cookie=cookie)) 38 assert "<title>Login</title>" in response 39 assert "credentials" in response 40 assert "not correct" in response
41
42 - def test_login_and_logout(self):
43 """Login with correct credentials and then logout.""" 44 User(user_name = u"scott", password = u"tiger", 45 display_name = u"Bruce Scott", 46 email_address = u"scott@enterprise.com") 47 response = self.app.get('/') 48 assert "<title>Welcome to TurboGears</title>" in response 49 assert 'href="/login"' in response 50 assert 'href="/logout"' not in response 51 response = self.app.get('/login') 52 assert "<title>Login</title>" in response 53 assert 'Please log in.' in response 54 cookie = ', '.join(map(str, response.cookies_set.values())) 55 login = '/login?user_name=scott&password=tiger&login=Login' 56 headers = dict(Cookie=cookie) 57 response = self.app.get(login, headers=headers, status=302) 58 location = response.headers['Location'] 59 response = self.app.get(location, headers=headers) 60 assert "<title>Welcome to TurboGears</title>" in response 61 assert "Welcome Bruce Scott" in response 62 assert 'href="/login"' not in response 63 assert 'href="/logout"' in response 64 response = self.app.get('/', headers=headers) 65 assert "<title>Welcome to TurboGears</title>" in response 66 assert "Welcome Bruce Scott" in response 67 assert 'href="/login"' not in response 68 assert 'href="/logout"' in response 69 response = self.app.get('/logout', headers=headers, status=302) 70 location = response.headers['Location'] 71 response = self.app.get(location, headers=headers) 72 assert "<title>Welcome to TurboGears</title>" in response 73 assert 'href="/login"' in response 74 assert 'href="/logout"' not in response
75