<s> from flask import url_for <EOL> from flask_views . db . mongoengine . edit import CreateView , UpdateView , DeleteView <EOL> from flask_views . tests . functional . db . mongoengine . base import BaseMongoTestCase <EOL> class CreateViewTestCase ( BaseMongoTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( CreateViewTestCase , self ) . setUp ( ) <EOL> class TestView ( CreateView ) : <EOL> document_class = self . TestDocument <EOL> form_class = self . TestForm <EOL> template_name = '<STR_LIT>' <EOL> success_url = '<STR_LIT>' <EOL> self . app . add_url_rule ( '<STR_LIT>' , view_func = TestView . as_view ( '<STR_LIT:test>' ) ) <EOL> def test_get ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <NUM_LIT:0> , self . TestDocument . objects . count ( ) ) <EOL> with self . app . test_request_context ( ) : <EOL> response = self . client . get ( url_for ( '<STR_LIT:test>' ) ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status_code ) <EOL> self . assertIn ( '<STR_LIT>' , response . data ) <EOL> self . assertIn ( '<STR_LIT>' , response . data ) <EOL> self . assertEqual ( <NUM_LIT:0> , self . TestDocument . objects . count ( ) ) <EOL> def test_empty_post ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <NUM_LIT:0> , self . TestDocument . objects . count ( ) ) <EOL> with self . app . test_request_context ( ) : <EOL> response = self . client . post ( url_for ( '<STR_LIT:test>' ) ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status_code ) <EOL> self . assertIn ( '<STR_LIT>' , response . data ) <EOL> self . assertIn ( '<STR_LIT>' , response . data ) <EOL> self . assertEqual ( <NUM_LIT:0> , self . TestDocument . objects . count ( ) ) <EOL> def test_post ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <NUM_LIT:0> , self . TestDocument . objects . count ( ) ) <EOL> with self . app . test_request_context ( ) : <EOL> response = self . client . post ( url_for ( '<STR_LIT:test>' ) , data = { <EOL> '<STR_LIT:username>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT:name>' : '<STR_LIT:bar>' , <EOL> } ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> self . assertEqual ( '<STR_LIT>' , response . headers [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , self . TestDocument . objects . count ( ) ) <EOL> self . TestDocument . objects . get ( username = '<STR_LIT:foo>' , name = '<STR_LIT:bar>' ) <EOL> class UpdateViewTestCase ( BaseMongoTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( UpdateViewTestCase , self ) . setUp ( ) <EOL> class TestView ( UpdateView ) : <EOL> document_class = self . TestDocument <EOL> form_class = self . TestForm <EOL> template_name = '<STR_LIT>' <EOL> success_url = '<STR_LIT>' <EOL> get_fields = { <EOL> '<STR_LIT:username>' : '<STR_LIT:user>' , <EOL> } <EOL> self . app . add_url_rule ( '<STR_LIT>' , view_func = TestView . as_view ( '<STR_LIT:test>' ) ) <EOL> test_obj = self . TestDocument ( username = '<STR_LIT:foo>' , name = '<STR_LIT:bar>' ) <EOL> test_obj . save ( ) <EOL> def test_get ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . app . test_request_context ( ) : <EOL> response = self . client . get ( url_for ( '<STR_LIT:test>' , user = '<STR_LIT:foo>' ) ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status_code ) <EOL> self . assertIn ( '<STR_LIT>' , response . data ) <EOL> self . assertIn ( '<STR_LIT>' , response . data ) <EOL> def test_post ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . app . test_request_context ( ) : <EOL> response = self . client . post ( url_for ( '<STR_LIT:test>' , user = '<STR_LIT:foo>' ) , data = { <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> } ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> self . assertEqual ( '<STR_LIT>' , response . headers [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , self . TestDocument . objects . count ( ) ) <EOL> self . TestDocument . objects . get ( username = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> class DeleteViewTestCase ( BaseMongoTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( DeleteViewTestCase , self ) . setUp ( ) <EOL> class TestView ( DeleteView ) : <EOL> document_class = self . TestDocument <EOL> template_name = '<STR_LIT>' <EOL> success_url = '<STR_LIT>' <EOL> get_fields = { <EOL> '<STR_LIT:username>' : '<STR_LIT:user>' , <EOL> } <EOL> self . app . add_url_rule ( '<STR_LIT>' , view_func = TestView . as_view ( '<STR_LIT:test>' ) ) <EOL> self . TestDocument ( username = '<STR_LIT:foo>' , name = '<STR_LIT:bar>' ) . save ( ) <EOL> self . TestDocument ( username = '<STR_LIT:bar>' , name = '<STR_LIT:foo>' ) . save ( ) <EOL> def test_get ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . app . test_request_context ( ) : <EOL> response = self . client . get ( url_for ( '<STR_LIT:test>' , user = '<STR_LIT:foo>' ) ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status_code ) <EOL> self . assertEqual ( '<STR_LIT:bar>' , response . data ) <EOL> def test_delete ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <NUM_LIT:2> , self . TestDocument . objects . count ( ) ) <EOL> with self . app . test_request_context ( ) : <EOL> response = self . client . delete ( url_for ( '<STR_LIT:test>' , user = '<STR_LIT:foo>' ) ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> self . assertEqual ( '<STR_LIT>' , response . headers [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , self . TestDocument . objects . count ( ) ) <EOL> self . TestDocument . objects . get ( username = '<STR_LIT:bar>' ) <EOL> self . assertRaises ( <EOL> self . TestDocument . DoesNotExist , <EOL> self . TestDocument . objects . get , username = '<STR_LIT:foo>' <EOL> ) </s>
