<s> """<STR_LIT>""" <EOL> import os <EOL> import minitwit <EOL> import tempfile <EOL> import pytest <EOL> @ pytest . fixture <EOL> def client ( request ) : <EOL> db_fd , minitwit . app . config [ '<STR_LIT>' ] = tempfile . mkstemp ( ) <EOL> client = minitwit . app . test_client ( ) <EOL> with minitwit . app . app_context ( ) : <EOL> minitwit . init_db ( ) <EOL> def teardown ( ) : <EOL> """<STR_LIT>""" <EOL> os . close ( db_fd ) <EOL> os . unlink ( minitwit . app . config [ '<STR_LIT>' ] ) <EOL> request . addfinalizer ( teardown ) <EOL> return client <EOL> def register ( client , username , password , password2 = None , email = None ) : <EOL> """<STR_LIT>""" <EOL> if password2 is None : <EOL> password2 = password <EOL> if email is None : <EOL> email = username + '<STR_LIT>' <EOL> return client . post ( '<STR_LIT>' , data = { <EOL> '<STR_LIT:username>' : username , <EOL> '<STR_LIT:password>' : password , <EOL> '<STR_LIT>' : password2 , <EOL> '<STR_LIT:email>' : email , <EOL> } , follow_redirects = True ) <EOL> def login ( client , username , password ) : <EOL> """<STR_LIT>""" <EOL> return client . post ( '<STR_LIT>' , data = { <EOL> '<STR_LIT:username>' : username , <EOL> '<STR_LIT:password>' : password <EOL> } , follow_redirects = True ) <EOL> def register_and_login ( client , username , password ) : <EOL> """<STR_LIT>""" <EOL> register ( client , username , password ) <EOL> return login ( client , username , password ) <EOL> def logout ( client ) : <EOL> """<STR_LIT>""" <EOL> return client . get ( '<STR_LIT>' , follow_redirects = True ) <EOL> def add_message ( client , text ) : <EOL> """<STR_LIT>""" <EOL> rv = client . post ( '<STR_LIT>' , data = { '<STR_LIT:text>' : text } , <EOL> follow_redirects = True ) <EOL> if text : <EOL> assert b'<STR_LIT>' in rv . data <EOL> return rv <EOL> def test_register ( client ) : <EOL> """<STR_LIT>""" <EOL> rv = register ( client , '<STR_LIT>' , '<STR_LIT:default>' ) <EOL> assert b'<STR_LIT>' b'<STR_LIT>' in rv . data <EOL> rv = register ( client , '<STR_LIT>' , '<STR_LIT:default>' ) <EOL> assert b'<STR_LIT>' in rv . data <EOL> rv = register ( client , '<STR_LIT>' , '<STR_LIT:default>' ) <EOL> assert b'<STR_LIT>' in rv . data <EOL> rv = register ( client , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert b'<STR_LIT>' in rv . data <EOL> rv = register ( client , '<STR_LIT>' , '<STR_LIT:x>' , '<STR_LIT:y>' ) <EOL> assert b'<STR_LIT>' in rv . data <EOL> rv = register ( client , '<STR_LIT>' , '<STR_LIT:foo>' , email = '<STR_LIT>' ) <EOL> assert b'<STR_LIT>' in rv . data <EOL> def test_login_logout ( client ) : <EOL> """<STR_LIT>""" <EOL> rv = register_and_login ( client , '<STR_LIT>' , '<STR_LIT:default>' ) <EOL> assert b'<STR_LIT>' in rv . data <EOL> rv = logout ( client ) <EOL> assert b'<STR_LIT>' in rv . data <EOL> rv = login ( client , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert b'<STR_LIT>' in rv . data <EOL> rv = login ( client , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert b'<STR_LIT>' in rv . data <EOL> def test_message_recording ( client ) : <EOL> """<STR_LIT>""" <EOL> register_and_login ( client , '<STR_LIT:foo>' , '<STR_LIT:default>' ) <EOL> add_message ( client , '<STR_LIT>' ) <EOL> add_message ( client , '<STR_LIT>' ) <EOL> rv = client . get ( '<STR_LIT:/>' ) <EOL> assert b'<STR_LIT>' in rv . data <EOL> assert b'<STR_LIT>' in rv . data <EOL> def test_timelines ( client ) : <EOL> """<STR_LIT>""" <EOL> register_and_login ( client , '<STR_LIT:foo>' , '<STR_LIT:default>' ) <EOL> add_message ( client , '<STR_LIT>' ) <EOL> logout ( client ) <EOL> register_and_login ( client , '<STR_LIT:bar>' , '<STR_LIT:default>' ) <EOL> add_message ( client , '<STR_LIT>' ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> assert b'<STR_LIT>' in rv . data <EOL> assert b'<STR_LIT>' in rv . data <EOL> rv = client . get ( '<STR_LIT:/>' ) <EOL> assert b'<STR_LIT>' not in rv . data <EOL> assert b'<STR_LIT>' in rv . data <EOL> rv = client . get ( '<STR_LIT>' , follow_redirects = True ) <EOL> assert b'<STR_LIT>' in rv . data <EOL> rv = client . get ( '<STR_LIT:/>' ) <EOL> assert b'<STR_LIT>' in rv . data <EOL> assert b'<STR_LIT>' in rv . data <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> assert b'<STR_LIT>' not in rv . data <EOL> assert b'<STR_LIT>' in rv . data <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> assert b'<STR_LIT>' in rv . data <EOL> assert b'<STR_LIT>' not in rv . data <EOL> rv = client . get ( '<STR_LIT>' , follow_redirects = True ) <EOL> assert b'<STR_LIT>' in rv . data <EOL> rv = client . get ( '<STR_LIT:/>' ) <EOL> assert b'<STR_LIT>' not in rv . data <EOL> assert b'<STR_LIT>' in rv . data </s>
