<s> import sys , types <EOL> from pprint import pformat <EOL> from twisted . trial import unittest <EOL> from twisted . news import database <EOL> from twisted . internet import reactor <EOL> MESSAGE_ID = "<STR_LIT>" <EOL> POST_STRING = """<STR_LIT>""" % ( MESSAGE_ID ) <EOL> class NewsTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . backend = database . NewsShelf ( None , '<STR_LIT>' ) <EOL> self . backend . addGroup ( '<STR_LIT>' , '<STR_LIT:y>' ) <EOL> self . backend . postRequest ( POST_STRING . replace ( '<STR_LIT:\n>' , '<STR_LIT:\r\n>' ) ) <EOL> def testArticleExists ( self ) : <EOL> d = self . backend . articleExistsRequest ( MESSAGE_ID ) <EOL> d . addCallback ( self . failUnless ) <EOL> return d <EOL> def testArticleRequest ( self ) : <EOL> d = self . backend . articleRequest ( None , None , MESSAGE_ID ) <EOL> def cbArticle ( result ) : <EOL> self . failUnless ( isinstance ( result , tuple ) , <EOL> '<STR_LIT>' + str ( result ) ) <EOL> self . assertEquals ( len ( result ) , <NUM_LIT:3> , <EOL> '<STR_LIT>' + <EOL> str ( result ) ) <EOL> self . assertEquals ( result [ <NUM_LIT:1> ] , MESSAGE_ID , <EOL> "<STR_LIT>" % <EOL> ( MESSAGE_ID , result [ <NUM_LIT:1> ] ) ) <EOL> body = result [ <NUM_LIT:2> ] . read ( ) <EOL> self . failIfEqual ( body . find ( '<STR_LIT>' ) , - <NUM_LIT:1> , <EOL> "<STR_LIT>" ) <EOL> return result <EOL> d . addCallback ( cbArticle ) <EOL> return d <EOL> def testHeadRequest ( self ) : <EOL> d = self . testArticleRequest ( ) <EOL> def cbArticle ( result ) : <EOL> index = result [ <NUM_LIT:0> ] <EOL> d = self . backend . headRequest ( "<STR_LIT>" , index ) <EOL> d . addCallback ( cbHead ) <EOL> return d <EOL> def cbHead ( result ) : <EOL> self . assertEquals ( result [ <NUM_LIT:1> ] , MESSAGE_ID , <EOL> "<STR_LIT>" % <EOL> ( MESSAGE_ID , result [ <NUM_LIT:1> ] ) ) <EOL> self . assertEquals ( result [ <NUM_LIT:2> ] [ - <NUM_LIT:2> : ] , '<STR_LIT:\r\n>' , <EOL> "<STR_LIT>" ) <EOL> d . addCallback ( cbArticle ) <EOL> return d <EOL> def testBodyRequest ( self ) : <EOL> d = self . testArticleRequest ( ) <EOL> def cbArticle ( result ) : <EOL> index = result [ <NUM_LIT:0> ] <EOL> d = self . backend . bodyRequest ( "<STR_LIT>" , index ) <EOL> d . addCallback ( cbBody ) <EOL> return d <EOL> def cbBody ( result ) : <EOL> body = result [ <NUM_LIT:2> ] . read ( ) <EOL> self . assertEquals ( body [ <NUM_LIT:0> : <NUM_LIT:4> ] , '<STR_LIT>' , <EOL> "<STR_LIT>" + <EOL> pformat ( body [ <NUM_LIT:0> : <NUM_LIT:4> ] ) ) <EOL> d . addCallback ( cbArticle ) <EOL> return d </s>
