Skip to content

Commit

Permalink
Merge branch 'global_submit'
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciusban committed Nov 5, 2013
2 parents c667a5d + a803998 commit 5fc9f76
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
22 changes: 22 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,27 @@ def run(controller, function, env):
return r


def submit(controller, action, env, data=None, formname=None):
"""Submits a form, setting _formkey and _formname accordingly.
env must be the web2py environment fixture.
"""

formname = formname or "default"

hidden = dict(
_formkey=action,
_formname=formname
)

if data:
env.request.post_vars.update(data)
env.request.post_vars.update(hidden)
env.session["_formkey[%s]" % formname] = [action]

return env.run(controller, action, env)


from gluon.shell import env
from gluon.storage import Storage

Expand All @@ -127,6 +148,7 @@ def run(controller, function, env):

del web2py_env['__file__'] # avoid py.test import error
web2py_env['run'] = run
web2py_env['submit'] = submit
globals().update(web2py_env)

return Storage(web2py_env)
26 changes: 2 additions & 24 deletions tests/controllers/test_people_controller_web2pyenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_validate_new_person(web2py):
phone='',
)

result = _submit_form('people', 'new_person', web2py, data,
result = web2py.submit('people', 'new_person', web2py, data,
formname='new_person_form')

assert result['form'].errors
Expand All @@ -76,7 +76,7 @@ def test_save_new_person(web2py):
phone='9988-7766',
)

result = _submit_form('people', 'new_person', web2py, data,
result = web2py.submit('people', 'new_person', web2py, data,
formname='new_person_form')

html = web2py.response.render('people/new_person.html', result)
Expand Down Expand Up @@ -117,25 +117,3 @@ def test_get_person_by_creation_date(web2py):
person = json.loads(html)
assert person['name'] == data['name']
assert person['created_at'] == data['created_at']



def _submit_form(controller, action, env, data=None, formname=None):
"""Submits a form, setting _formkey and _formname accordingly.
env must be the web2py environment fixture.
"""

formname = formname or "default"

hidden = dict(
_formkey=action,
_formname=formname
)

if data:
env.request.post_vars.update(data)
env.request.post_vars.update(hidden)
env.session["_formkey[%s]" % formname] = [action]

return env.run(controller, action, env)

0 comments on commit 5fc9f76

Please sign in to comment.