<s> import datetime <EOL> import flask <EOL> from flask . ext . mongoengine import MongoEngine <EOL> from tests import FlaskMongoEngineTestCase <EOL> class BasicAppTestCase ( FlaskMongoEngineTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( BasicAppTestCase , self ) . setUp ( ) <EOL> db = MongoEngine ( ) <EOL> class Todo ( db . Document ) : <EOL> title = db . StringField ( max_length = <NUM_LIT> ) <EOL> text = db . StringField ( ) <EOL> done = db . BooleanField ( default = False ) <EOL> pub_date = db . DateTimeField ( default = datetime . datetime . now ) <EOL> db . init_app ( self . app ) <EOL> Todo . drop_collection ( ) <EOL> self . Todo = Todo <EOL> @ self . app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return '<STR_LIT:\n>' . join ( x . title for x in self . Todo . objects ) <EOL> @ self . app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> def add ( ) : <EOL> form = flask . request . form <EOL> todo = self . Todo ( title = form [ '<STR_LIT:title>' ] , <EOL> text = form [ '<STR_LIT:text>' ] ) <EOL> todo . save ( ) <EOL> return '<STR_LIT>' <EOL> @ self . app . route ( '<STR_LIT>' ) <EOL> def show ( id ) : <EOL> todo = self . Todo . objects . get_or_404 ( id = id ) <EOL> return '<STR_LIT:\n>' . join ( [ todo . title , todo . text ] ) <EOL> self . db = db <EOL> def test_connection_default ( self ) : <EOL> self . app . config [ '<STR_LIT>' ] = { } <EOL> self . app . config [ '<STR_LIT>' ] = True <EOL> db = MongoEngine ( ) <EOL> db . init_app ( self . app ) <EOL> self . app . config [ '<STR_LIT>' ] = True <EOL> db = MongoEngine ( ) <EOL> db . init_app ( self . app ) <EOL> def test_with_id ( self ) : <EOL> c = self . app . test_client ( ) <EOL> resp = c . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> c . post ( '<STR_LIT>' , data = { '<STR_LIT:title>' : '<STR_LIT>' , '<STR_LIT:text>' : '<STR_LIT>' } ) <EOL> resp = c . get ( '<STR_LIT>' % self . Todo . objects . first_or_404 ( ) . id ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEquals ( resp . data . decode ( '<STR_LIT:utf-8>' ) , '<STR_LIT>' ) <EOL> def test_basic_insert ( self ) : <EOL> c = self . app . test_client ( ) <EOL> c . post ( '<STR_LIT>' , data = { '<STR_LIT:title>' : '<STR_LIT>' , '<STR_LIT:text>' : '<STR_LIT>' } ) <EOL> c . post ( '<STR_LIT>' , data = { '<STR_LIT:title>' : '<STR_LIT>' , '<STR_LIT:text>' : '<STR_LIT>' } ) <EOL> rv = c . get ( '<STR_LIT:/>' ) <EOL> self . assertEquals ( rv . data . decode ( '<STR_LIT:utf-8>' ) , '<STR_LIT>' ) <EOL> def test_request_context ( self ) : <EOL> with self . app . test_request_context ( ) : <EOL> todo = self . Todo ( title = '<STR_LIT>' , text = '<STR_LIT:test>' ) <EOL> todo . save ( ) <EOL> self . assertEqual ( self . Todo . objects . count ( ) , <NUM_LIT:1> ) </s>
