11import os
22import tempfile
33import unittest
4- import microblog
54
5+ import microblog
66
77class MicroblogTestCase (unittest .TestCase ):
88
@@ -19,10 +19,10 @@ def tearDown(self):
1919 os .unlink (microblog .app .config ['DATABASE' ])
2020
2121 def test_database_setup (self ):
22- con = microblog .connect_db ()
23- cur = con .execute ('PRAGMA table_info(entries);' )
24- rows = cur .fetchall ()
25- self .assertEquals (len (rows ), 3 )
22+ con = microblog .connect_db ()
23+ cur = con .execute ('PRAGMA table_info(entries);' )
24+ rows = cur .fetchall ()
25+ self .assertEquals (len (rows ), 3 )
2626
2727 def test_write_entry (self ):
2828 expected = ("My Title" , "My Text" )
@@ -64,6 +64,8 @@ def test_listing(self):
6464 self .assertTrue (value in actual )
6565
6666 def test_add_entries (self ):
67+ with self .client .session_transaction () as session :
68+ session ['logged_in' ] = True
6769 actual = self .client .post ('/add' , data = dict (
6870 title = 'Hello' ,
6971 text = 'This is a post'
@@ -72,6 +74,17 @@ def test_add_entries(self):
7274 self .assertTrue ('Hello' in actual )
7375 self .assertTrue ('This is a post' in actual )
7476
77+ def test_login (self ):
78+ actual = self .client .post ('/login' , data = dict (username = 'user0' , password = 'notapassword' ), follow_redirects = True )
79+ self .assertTrue ('You are logged in' in actual .data )
80+
81+ def test_logout (self ):
82+ actual = self .client .get ('/logout' , follow_redirects = True )
83+ self .assertTrue ('You have logged out' in actual .data )
84+
85+ def test_login_incorrect (self ):
86+ actual = self .client .post ('/login' , data = dict (username = 'Voldemort' , password = 'HarryMustDie' ), follow_redirects = True )
87+ self .assertTrue ('Invalid username' in actual .data )
7588
7689if __name__ == '__main__' :
7790 unittest .main ()
0 commit comments