Testing redirection with py.test

727 views
Skip to first unread message

Vinicius Assef

unread,
Oct 28, 2013, 7:13:22 PM10/28/13
to web2py
I created this gist to help people testing controllers that makes redirection:
https://gist.github.com/viniciusban/7206413

Hope it helps someone.

Massimo Di Pierro

unread,
Oct 30, 2013, 10:11:50 PM10/30/13
to web...@googlegroups.com
Can you please make a web2py slice about this?

Vinicius Assef

unread,
Oct 31, 2013, 6:29:02 AM10/31/13
to web2py
Good idea.

I'll make it, but it is based on a previous work [1]. I need improve
docs for it.

[1] http://github.com/viniciusban/web2py.test
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Richard Vézina

unread,
Oct 31, 2013, 9:59:25 AM10/31/13
to web2py-users
I would like to help you Vinicius, what could I do?

Richard

Vinicius Assef

unread,
Oct 31, 2013, 11:39:05 AM10/31/13
to web2py
Thank you, Richard.

Basically, I need to isolate web2py.test from my example app and
prepare better examples.

Richard Vézina

unread,
Oct 31, 2013, 12:08:35 PM10/31/13
to web2py-users
Ok, I get web2py.test and web2py 2.7.4 (I will test at the same time that web2py.test works well with it).

Now, https://gist.github.com/viniciusban/7206413 seems just a example... Should I just add it to web2py.test app?

Richard

Richard Vézina

unread,
Oct 31, 2013, 12:28:46 PM10/31/13
to web2py-users
Wait, I didn't read carefully web2py.test more complex than I thought, I thought it was just an app.

I will set up a virtualenv.

Richard

Vinicius Assef

unread,
Oct 31, 2013, 4:08:49 PM10/31/13
to web2py
Yes, that's the way to go. :-)

On Thu, Oct 31, 2013 at 2:28 PM, Richard Vézina

Richard Vézina

unread,
Nov 4, 2013, 8:48:47 PM11/4/13
to web2py-users
Hello Vinicius,

I have been able to run tests, one failed though :

=================================================================================== test session starts ===================================================================================
platform linux2 -- Python 2.7.4 -- pytest-2.4.2 -- /home/noitulove/projets/web2py.test/bin/python
collected 11 items 

applications/people/tests/controllers/test_people_controller_web2pyenv.py:15: test_index_exists PASSED
applications/people/tests/controllers/test_people_controller_web2pyenv.py:29: test_new_person_with_form PASSED
applications/people/tests/controllers/test_people_controller_web2pyenv.py:50: test_validate_new_person FAILED

======================================================================================== FAILURES =========================================================================================
________________________________________________________________________________ test_validate_new_person _________________________________________________________________________________

web2py = <Storage {'Service': <class 'gluon.tools.Service'>, 'OBJECT': <class 'gluon.ht...ytest/web2pytest.pyc'>, 'T': <gluon.languages.translator object at 0x333c450>}>

    def test_validate_new_person(web2py):
        '''Is the form validating?
        '''
    
        from gluon.compileapp import run_controller_in
    
        data = dict(
            name='',
            phone='',
            _formname='new_person_form',
        )
    
        web2py.request.post_vars.update(data)
        result = run_controller_in('people', 'new_person', web2py)
    
>       assert result['form'].errors
E       assert <Storage {}>
E        +  where <Storage {}> = <gluon.sqlhtml.SQLFORM object at 0x335c650>.errors

applications/people/tests/controllers/test_people_controller_web2pyenv.py:65: AssertionError
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=========================================================================== 1 failed, 2 passed in 0.25 seconds ==========================================================================

I use web2py 2.7.4

I will start to study it.

:)

Richard

Richard Vézina

unread,
Nov 4, 2013, 9:19:28 PM11/4/13
to web2py-users
Wrote this to get started :

# -*- coding: utf8 -*-

# Create a python virtual environnement
cd
mkdir projects
virtualenv ~/projets/web2py.test
# Access the environnement
source ~/projects/web2py.test/bin/activate
# Now your prompt should look like this :
# (web2py.test)username@yourmachine:~$
# Go in ~/projets/web2py.test
cd ~/projects/web2py.test
# Get last web2py stable
wget http://www.web2py.com/examples/static/web2py_src.zip
# Unpack it
unzip web2py_src.zip
# Go in web2py/applications/
cd web2py/applications/
# Get the last web2py.test app
wget https://github.com/viniciusban/web2py.test/archive/master.zip
# Unpack it
unzip master.zip
# Rename
mv web2py.test-master/ people
# You are read for the rest

Attach it...

:)

Richard
create_a_virtualenv_en.sh

Vinicius Assef

unread,
Nov 5, 2013, 2:34:52 AM11/5/13
to web2py
Richard, in some way, form submission has changed. I don't know
exactly in which version, but now you must set _formkey before form
submission.

I commited some changes.

Now you don't need to import run_controller_in, anymore. Just call
web2py.run() function.
To submit a form, just call web2py.submit()


On Mon, Nov 4, 2013 at 11:48 PM, Richard Vézina

Vinicius Assef

unread,
Nov 5, 2013, 3:34:41 AM11/5/13
to web2py
Thank you so much.

I've made some changes in README, too. Take a look.

On Tue, Nov 5, 2013 at 12:19 AM, Richard Vézina
Reply all
Reply to author
Forward
0 new messages