<s> import unittest <EOL> from pyramid import testing <EOL> class Test_get_pastes ( unittest . TestCase ) : <EOL> def _callFUT ( self , context , request , max ) : <EOL> from cluegun . views import get_pastes <EOL> return get_pastes ( context , request , max ) <EOL> def test_it ( self ) : <EOL> import datetime <EOL> from cluegun . models import IPasteBin <EOL> pb = testing . DummyResource ( __provides__ = IPasteBin ) <EOL> now = datetime . datetime . now ( ) <EOL> for x in range ( <NUM_LIT:0> , <NUM_LIT:20> ) : <EOL> entry = testing . DummyResource ( ) <EOL> last_date = entry . date = now + datetime . timedelta ( x ) <EOL> entry . author_name = '<STR_LIT>' <EOL> pb [ str ( x ) ] = entry <EOL> context = testing . DummyResource ( __parent__ = pb ) <EOL> request = testing . DummyRequest ( ) <EOL> result = self . _callFUT ( context , request , <NUM_LIT:10> ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:10> ) <EOL> entry = result [ <NUM_LIT:0> ] <EOL> self . assertEqual ( entry [ '<STR_LIT:date>' ] , last_date . strftime ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( entry [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( entry [ '<STR_LIT:url>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( entry [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> class Test_preferred_author ( unittest . TestCase ) : <EOL> def _callFUT ( self , request ) : <EOL> from cluegun . views import preferred_author <EOL> return preferred_author ( request ) <EOL> def test_with_str_author_name_in_params ( self ) : <EOL> request = testing . DummyRequest ( ) <EOL> request . params [ '<STR_LIT>' ] = '<STR_LIT:abc>' <EOL> result = self . _callFUT ( request ) <EOL> self . failUnless ( isinstance ( result , unicode ) ) <EOL> self . assertEqual ( result , u'<STR_LIT:abc>' ) <EOL> def test_with_unicode_author_name_in_params ( self ) : <EOL> request = testing . DummyRequest ( ) <EOL> request . params [ '<STR_LIT>' ] = u'<STR_LIT:abc>' <EOL> result = self . _callFUT ( request ) <EOL> self . failUnless ( isinstance ( result , unicode ) ) <EOL> self . assertEqual ( result , u'<STR_LIT:abc>' ) <EOL> def test_with_str_author_name_in_cookie ( self ) : <EOL> request = testing . DummyRequest ( ) <EOL> request . cookies [ '<STR_LIT>' ] = '<STR_LIT:abc>' <EOL> result = self . _callFUT ( request ) <EOL> self . failUnless ( isinstance ( result , unicode ) ) <EOL> self . assertEqual ( result , u'<STR_LIT:abc>' ) <EOL> def test_with_unicode_author_name_in_cookie ( self ) : <EOL> request = testing . DummyRequest ( ) <EOL> request . cookies [ '<STR_LIT>' ] = u'<STR_LIT:abc>' <EOL> result = self . _callFUT ( request ) <EOL> self . failUnless ( isinstance ( result , unicode ) ) <EOL> self . assertEqual ( result , u'<STR_LIT:abc>' ) <EOL> class Test_check_passwd ( unittest . TestCase ) : <EOL> def _callFUT ( self , passwd_file , login , password ) : <EOL> from cluegun . views import check_passwd <EOL> return check_passwd ( passwd_file , login , password ) <EOL> def test_password_equals_hashed ( self ) : <EOL> from StringIO import StringIO <EOL> passwd_file = StringIO ( '<STR_LIT>' ) <EOL> result = self . _callFUT ( passwd_file , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( result , '<STR_LIT>' ) <EOL> def test_password_doesnt_equal_hashed ( self ) : <EOL> from StringIO import StringIO <EOL> passwd_file = StringIO ( '<STR_LIT>' ) <EOL> result = self . _callFUT ( passwd_file , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( result , None ) <EOL> def test_bad_data_in_file ( self ) : <EOL> from StringIO import StringIO <EOL> passwd_file = StringIO ( '<STR_LIT>' ) <EOL> result = self . _callFUT ( passwd_file , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( result , '<STR_LIT>' ) <EOL> class Test_entry_view ( unittest . TestCase ) : <EOL> def _callFUT ( self , context , request ) : <EOL> from cluegun . views import entry_view <EOL> return entry_view ( context , request ) <EOL> def test_it ( self ) : <EOL> import datetime <EOL> from cluegun . models import IPasteBin <EOL> from cluegun . views import app_version <EOL> now = datetime . datetime . now ( ) <EOL> pb = testing . DummyResource ( __provides__ = IPasteBin ) <EOL> entry = testing . DummyResource ( language = '<STR_LIT>' , <EOL> author_name = '<STR_LIT>' , <EOL> paste = '<STR_LIT:abc>' , <EOL> date = now , <EOL> __parent__ = pb ) <EOL> pb [ '<STR_LIT>' ] = entry <EOL> request = testing . DummyRequest ( ) <EOL> result = self . _callFUT ( entry , request ) <EOL> self . assertEqual ( result [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( result [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . failUnless ( result [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( result [ '<STR_LIT:version>' ] , app_version ) <EOL> self . assertEqual ( result [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . failUnless ( '<STR_LIT:abc>' in result [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( result [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) </s>
