def test_edit_get(self): response = self.testapp.get('/admin/test1/1/edit', status=403) headers = self.__remember() response = self.testapp.get('/admin/test1/1/edit', headers=headers, status=200) expected = ''' <!DOCTYPE html> <html> <head><link rel="stylesheet" type="text/css" href="/resources/tw2.forms/static/forms.css" media="all" /> <title>SQLAdmin</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> </head> <body> <form enctype="multipart/form-data" method="post"> <span class="error"></span> <table> <tr class="odd required" id="name:container"> <th><label for="name">Name</label></th> <td> <input name="name" type="text" id="name" value="Bob"/> <span id="name:error"></span> </td> </tr> <tr class="error"><td colspan="2"> <span id=":error"></span> </td></tr> </table> <input type="submit" value="Save"/> </form> </body> </html> ''' tw2test.assert_eq_xml(response.body, expected)
def test_request_get(self): environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING' :'name=foo2'} req=Request(environ) assert(req.GET) r = self.widget().request(req) tw2test.assert_eq_xml(r.body, """<html> <head><title>some title</title></head> <body id="dblistform_d:page"><h1>some title</h1><form method="post" id="dblistform_d:form" enctype="multipart/form-data"> <span class="error"></span> <table id="dblistform_d"> <tr><th>Name</th></tr> <tr id="dblistform_d:0" class="odd"> <td> <input name="dblistform_d:0:name" value="foo1" id="dblistform_d:0:name" type="text"> </td> <td> <input name="dblistform_d:0:id" type="hidden" id="dblistform_d:0:id" value="1"> </td> </tr> <tr id="dblistform_d:1" class="even"> <td> <input name="dblistform_d:1:name" value="foo2" id="dblistform_d:1:name" type="text"> </td> <td> <input name="dblistform_d:1:id" type="hidden" id="dblistform_d:1:id" value="2"> </td> </tr> <tr class="error"><td colspan="2" id="dblistform_d:error"> </td></tr> </table> <input type="submit" id="submit" value="Save"> </form></body> </html>""")
def test_request_get_edit(self): # TODO -- this never actually tests line 68 of tw2.sqla.widgets environ = { 'REQUEST_METHOD': 'GET', 'QUERY_STRING' : 'id=1' } req=Request(environ) self.mw.config.debug = True r = self.widget().request(req) tw2test.assert_eq_xml(r.body, """<html> <head><title>some title</title></head> <body id="dbformpage_d:page"><h1>some title</h1><form method="post" id="dbformpage_d:form" enctype="multipart/form-data"> <span class="error"></span> <table id="dbformpage_d"> <tr class="odd" id="dbformpage_d:name:container"> <th>Name</th> <td> <input name="dbformpage_d:name" value="foo1" id="dbformpage_d:name" type="text"> <span id="dbformpage_d:name:error"></span> </td> </tr> <tr class="error"><td colspan="2"> <input type="hidden" name="dbformpage_d:id" value="1" id="dbformpage_d:id"/> <span id="dbformpage_d:error"></span> </td></tr> </table> <input type="submit" id="submit" value="Save"> </form></body> </html>""")
def test_request_get(self): """ Good lookin' """ environ = { 'REQUEST_METHOD': 'GET', } req=Request(environ) self.mw.config.debug = True r = self.widget().request(req) tw2test.assert_eq_xml(r.body, """ <html> <head><title>Db Test Cls1</title></head> <body id="autolistpage_d:page"> <h1>Db Test Cls1</h1> <table id="autolistpage_d"> <tr><th>Name</th><th>Others</th></tr> <tr id="autolistpage_d:0" class="odd"> <td> <span>foo1<input name="autolistpage_d:0:name" type="hidden" id="autolistpage_d:0:name" value="foo1"></span> </td> <td> <table id="autolistpage_d:0:others"> <tr><th>Nick</th><th>Other</th></tr> <tr id="autolistpage_d:0:others:0" class="odd"> <td> <span>bob3<input name="autolistpage_d:0:others:0:nick" type="hidden" id="autolistpage_d:0:others:0:nick" value="bob3"></span> </td> <td> <span>foo1<input name="autolistpage_d:0:others:0:other" type="hidden" id="autolistpage_d:0:others:0:other" value="foo1"></span> </td> <td> </td> </tr> <tr class="error"><td colspan="1" id="autolistpage_d:0:others:error"> </td></tr> </table> </td> <td> </td> </tr> <tr id="autolistpage_d:1" class="even"> <td> <span>foo2<input name="autolistpage_d:1:name" type="hidden" id="autolistpage_d:1:name" value="foo2"></span> </td> <td> <table id="autolistpage_d:1:others"> <tr><th>Nick</th><th>Other</th></tr> <tr class="error"><td colspan="0" id="autolistpage_d:1:others:error"> </td></tr> </table> </td> <td> </td> </tr> <tr class="error"><td colspan="2" id="autolistpage_d:error"> </td></tr> </table></body></html>""")
def test_orig_children(self): """ Tests overriding properties (`orig_children`) """ class SomeListPage(tws.DbListPage): _no_autoid = True entity = self.DbTestCls1 class child(tws.widgets.AutoViewGrid): name = twf.InputField(type='text') environ = { 'REQUEST_METHOD': 'GET', } req=Request(environ) self.mw.config.debug = True r = SomeListPage.request(req) tw2test.assert_eq_xml(r.body, """ <html><head><title>Db Test Cls1</title></head><body><h1>Db Test Cls1</h1> <table> <tr><th>Name</th><th>Others</th></tr> <tr id="0" class="odd"> <td> <input type="text" name="0:name" value="foo1" id="0:name"/> </td> <td> <table id="0:others"> <tr><th>Nick</th><th>Other</th></tr> <tr id="0:others:0" class="odd"> <td> <span>bob3<input name="0:others:0:nick" type="hidden" id="0:others:0:nick" value="bob3"></span> </td> <td> <span>foo1<input name="0:others:0:other" type="hidden" id="0:others:0:other" value="foo1"></span> </td><td></td></tr> <tr class="error"><td colspan="1" id="0:others:error"> </td></tr> </table> </td><td></td></tr> <tr id="1" class="even"> <td> <input type="text" name="1:name" value="foo2" id="1:name"/> </td><td> <table id="1:others"> <tr><th>Nick</th><th>Other</th></tr> <tr class="error"><td colspan="0" id="1:others:error"> </td></tr></table> </td><td></td> </tr> <tr class="error"><td colspan="2" id=":error"> </td></tr></table></body></html>""")
def _test_request_post_invalid(self): # i have commented this because the post is in fact # valid, there are no arguments sent to the post, but the # widget does not require them environ = {'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('')} req = Request(environ) r = self.widget().request(req) assert_eq_xml(r.body, """<html> <head><title>some title</title></head> <body id="mytestwidget:page"> <h1>some title</h1> <form method="post" id="mytestwidget:form" enctype="multipart/form-data"> <span class="error"></span> <table id="mytestwidget"> <tr class="odd" id="mytestwidget:field1:container"> <th><label for="field1">Field1</label></th> <td> <input name="mytestwidget:field1" id="mytestwidget:field1" type="text"/> <span id="mytestwidget:field1:error"></span> </td> </tr><tr class="even" id="mytestwidget:field2:container"> <th><label for="field2">Field2</label></th> <td> <input name="mytestwidget:field2" id="mytestwidget:field2" type="text"/> <span id="mytestwidget:field2:error"></span> </td> </tr><tr class="odd" id="mytestwidget:field3:container"> <th><label for="field3">Field3</label></th> <td> <input name="mytestwidget:field3" id="mytestwidget:field3" type="text"/> <span id="mytestwidget:field3:error"></span> </td> </tr><tr class="error"><td colspan="2"> <span id="mytestwidget:error"></span> </td></tr> </table> <input type="submit" value="Save"/> </form> </body></html>""")
def test_request_get(self): environ = {'REQUEST_METHOD': 'GET'} req = Request(environ) r = self.widget().request(req) assert_eq_xml(r.body, """<html> <head><title>some title</title></head> <body id="mytestwidget:page"> <h1>some title</h1> <form method="post" id="mytestwidget:form" enctype="multipart/form-data"> <span class="error"></span> <table id="mytestwidget"> <tr class="odd" id="mytestwidget:field1:container"> <th><label for="field1">Field1</label></th> <td> <input name="mytestwidget:field1" id="mytestwidget:field1" type="text"/> <span id="mytestwidget:field1:error"></span> </td> </tr><tr class="even" id="mytestwidget:field2:container"> <th><label for="field2">Field2</label></th> <td> <input name="mytestwidget:field2" id="mytestwidget:field2" type="text"/> <span id="mytestwidget:field2:error"></span> </td> </tr><tr class="odd" id="mytestwidget:field3:container"> <th><label for="field3">Field3</label></th> <td> <input name="mytestwidget:field3" id="mytestwidget:field3" type="text"/> <span id="mytestwidget:field3:error"></span> </td> </tr><tr class="error"><td colspan="2"> <span id="mytestwidget:error"></span> </td></tr> </table> <input type="submit" value="Save"/> </form> </body></html>""")
def test_request_get(self): # This makes much more sense. environ = { 'REQUEST_METHOD': 'GET', } req=Request(environ) self.mw.config.debug = True r = self.widget().request(req) tw2test.assert_eq_xml(r.body, """ <html> <head><title>Db Test Cls1</title></head> <body id="dblistpage_d:page"><h1>Db Test Cls1</h1> <table id="dblistpage_d"> <tr><th>Name</th><th>Edit</th></tr> <tr id="dblistpage_d:0" class="odd"> <td> <span>foo1<input type="hidden" name="dblistpage_d:0:name" value="foo1" id="dblistpage_d:0:name"/></span> </td> <td> <a href="foo?id=1" id="dblistpage_d:0:id">Edit</a> </td> <td> </td> </tr> <tr id="dblistpage_d:1" class="even"> <td> <span>foo2<input type="hidden" name="dblistpage_d:1:name" value="foo2" id="dblistpage_d:1:name"/></span> </td> <td> <a href="foo?id=2" id="dblistpage_d:1:id">Edit</a> </td> <td> </td> </tr> <tr class="error"><td colspan="2" id="dblistpage_d:error"></td></tr> </table> <a href="cls1">New</a> </body> </html>""")