librelist archives

« back to archive

Do you use flask with Lettuce?

Do you use flask with Lettuce?

From:
Italo Maia
Date:
2011-09-19 @ 04:51
Anyone using flask with lettuce? What did you think of the experience?

-- 
"A arrogância é a arma dos fracos."

===========================
Italo Moreira Campelo Maia
Bacharel em Ciência da Computação - UECE
Desenvolvedor WEB e Desktop (Java, Python, Lua)
Coordenador do Pug-CE
-----------------------------------------------------
http://www.italomaia.com/
http://twitter.com/italomaia/
http://eusouolobomau.blogspot.com/
-----------------------------------------------------
Turtle Linux  9.10 - http://tiny.cc/blogturtle910
Turtle Linux 10.10 - http://bit.ly/cEw4ET
===========================

Re: [flask] Do you use flask with Lettuce?

From:
Joseph Heck
Date:
2011-09-19 @ 16:00
I've been using Lettuce with Flask for the past several weeks to
reasonably good success. Any failings, I should say, are my own - as
I've taken several runs and haven't been consistent on my DSL wording
while putting it together.

I've fiddled with iterations that use Twill, Httplib2 directly, the
Werkzeug testing client, and selenium - all with success. I have some
detail on the steps and terrain.py file that I used at the bottom of a
more general post on functional testing with fabric & lettuce:

http://www.rhonabwy.com/wp/2011/08/10/functional-testing-with-lettuce-and-fabric/

2011/9/18 Italo Maia <italo.maia@gmail.com>:
> Anyone using flask with lettuce? What did you think of the experience?
>
> --
> "A arrogância é a arma dos fracos."
>
> ===========================
> Italo Moreira Campelo Maia
> Bacharel em Ciência da Computação - UECE
> Desenvolvedor WEB e Desktop (Java, Python, Lua)
> Coordenador do Pug-CE
> -----------------------------------------------------
> http://www.italomaia.com/
> http://twitter.com/italomaia/
> http://eusouolobomau.blogspot.com/
> -----------------------------------------------------
> Turtle Linux  9.10 - http://tiny.cc/blogturtle910
> Turtle Linux 10.10 - http://bit.ly/cEw4ET
> ===========================
>

Re: [flask] Do you use flask with Lettuce?

From:
Italo Maia
Date:
2011-09-22 @ 18:01
Ron, thanks for the tips. = ]

Thanks for the example Nikolaus.

Joseph Heck, do you have any opensource flask+lettuce project that i can
take a look?

2011/9/19 Joseph Heck <joseph.heck@gmail.com>

> I've been using Lettuce with Flask for the past several weeks to
> reasonably good success. Any failings, I should say, are my own - as
> I've taken several runs and haven't been consistent on my DSL wording
> while putting it together.
>
> I've fiddled with iterations that use Twill, Httplib2 directly, the
> Werkzeug testing client, and selenium - all with success. I have some
> detail on the steps and terrain.py file that I used at the bottom of a
> more general post on functional testing with fabric & lettuce:
>
>
> 
http://www.rhonabwy.com/wp/2011/08/10/functional-testing-with-lettuce-and-fabric/
>
> 2011/9/18 Italo Maia <italo.maia@gmail.com>:
> > Anyone using flask with lettuce? What did you think of the experience?
> >
> > --
> > "A arrogância é a arma dos fracos."
> >
> > ===========================
> > Italo Moreira Campelo Maia
> > Bacharel em Ciência da Computação - UECE
> > Desenvolvedor WEB e Desktop (Java, Python, Lua)
> > Coordenador do Pug-CE
> > -----------------------------------------------------
> > http://www.italomaia.com/
> > http://twitter.com/italomaia/
> > http://eusouolobomau.blogspot.com/
> > -----------------------------------------------------
> > Turtle Linux  9.10 - http://tiny.cc/blogturtle910
> > Turtle Linux 10.10 - http://bit.ly/cEw4ET
> > ===========================
> >
>



-- 
"A arrogância é a arma dos fracos."

===========================
Italo Moreira Campelo Maia
Bacharel em Ciência da Computação - UECE
Desenvolvedor WEB e Desktop (Java, Python, Lua)
Coordenador do Pug-CE
-----------------------------------------------------
http://www.italomaia.com/
http://twitter.com/italomaia/
http://eusouolobomau.blogspot.com/
-----------------------------------------------------
Turtle Linux  9.10 - http://tiny.cc/blogturtle910
Turtle Linux 10.10 - http://bit.ly/cEw4ET
===========================

Re: [flask] Do you use flask with Lettuce?

From:
Italo Maia
Date:
2011-09-22 @ 18:06
By the way Ron, you suggest that werkzeud testing be used with lettuce or
besides lettuce? Got a little confused.

2011/9/22 Italo Maia <italo.maia@gmail.com>

> Ron, thanks for the tips. = ]
>
> Thanks for the example Nikolaus.
>
> Joseph Heck, do you have any opensource flask+lettuce project that i can
> take a look?
>
>
> 2011/9/19 Joseph Heck <joseph.heck@gmail.com>
>
>> I've been using Lettuce with Flask for the past several weeks to
>> reasonably good success. Any failings, I should say, are my own - as
>> I've taken several runs and haven't been consistent on my DSL wording
>> while putting it together.
>>
>> I've fiddled with iterations that use Twill, Httplib2 directly, the
>> Werkzeug testing client, and selenium - all with success. I have some
>> detail on the steps and terrain.py file that I used at the bottom of a
>> more general post on functional testing with fabric & lettuce:
>>
>>
>> 
http://www.rhonabwy.com/wp/2011/08/10/functional-testing-with-lettuce-and-fabric/
>>
>> 2011/9/18 Italo Maia <italo.maia@gmail.com>:
>> > Anyone using flask with lettuce? What did you think of the experience?
>> >
>> > --
>> > "A arrogância é a arma dos fracos."
>> >
>> > ===========================
>> > Italo Moreira Campelo Maia
>> > Bacharel em Ciência da Computação - UECE
>> > Desenvolvedor WEB e Desktop (Java, Python, Lua)
>> > Coordenador do Pug-CE
>> > -----------------------------------------------------
>> > http://www.italomaia.com/
>> > http://twitter.com/italomaia/
>> > http://eusouolobomau.blogspot.com/
>> > -----------------------------------------------------
>> > Turtle Linux  9.10 - http://tiny.cc/blogturtle910
>> > Turtle Linux 10.10 - http://bit.ly/cEw4ET
>> > ===========================
>> >
>>
>
>
>
> --
> "A arrogância é a arma dos fracos."
>
> ===========================
> Italo Moreira Campelo Maia
> Bacharel em Ciência da Computação - UECE
> Desenvolvedor WEB e Desktop (Java, Python, Lua)
> Coordenador do Pug-CE
> -----------------------------------------------------
> http://www.italomaia.com/
> http://twitter.com/italomaia/
> http://eusouolobomau.blogspot.com/
> -----------------------------------------------------
> Turtle Linux  9.10 - http://tiny.cc/blogturtle910
> Turtle Linux 10.10 - http://bit.ly/cEw4ET
> ===========================
>



-- 
"A arrogância é a arma dos fracos."

===========================
Italo Moreira Campelo Maia
Bacharel em Ciência da Computação - UECE
Desenvolvedor WEB e Desktop (Java, Python, Lua)
Coordenador do Pug-CE
-----------------------------------------------------
http://www.italomaia.com/
http://twitter.com/italomaia/
http://eusouolobomau.blogspot.com/
-----------------------------------------------------
Turtle Linux  9.10 - http://tiny.cc/blogturtle910
Turtle Linux 10.10 - http://bit.ly/cEw4ET
===========================

Re: [flask] Do you use flask with Lettuce?

From:
Ron DuPlain
Date:
2011-09-22 @ 18:14
On Thu, Sep 22, 2011 at 2:06 PM, Italo Maia <italo.maia@gmail.com> wrote:
> By the way Ron, you suggest that werkzeud testing be used with lettuce or
> besides lettuce? Got a little confused.

You can use FlaskClient (from app.test_client()) for most tests.  You
might face a limitation with the builtin test client if you are
testing redirects with a HTTP service outside of your project, for
example with a redirect for external authentication or payment
processing.  In this case, the test client does not follow the
redirect like a browser would because it is working at the WSGI layer.

I test redirects with some utility methods on top of Python's urllib2.
 For everything else, I use Flask's test client which is created with
app.test_client().  In the thread of lettuce experience, I'd like to
share this experience, because otherwise you'll be left wondering why
FlaskClient isn't following redirects (and likely conclude it's a
bug).

-Ron

Re: [flask] Do you use flask with Lettuce?

From:
Ron DuPlain
Date:
2011-09-22 @ 19:01
On Thu, Sep 22, 2011 at 2:14 PM, Ron DuPlain <ron.duplain@gmail.com> wrote:
> On Thu, Sep 22, 2011 at 2:06 PM, Italo Maia <italo.maia@gmail.com> wrote:
>> By the way Ron, you suggest that werkzeud testing be used with lettuce or
>> besides lettuce? Got a little confused.
>
> You can use FlaskClient (from app.test_client()) for most tests.  You
> might face a limitation with the builtin test client if you are
> testing redirects with a HTTP service outside of your project, for
> example with a redirect for external authentication or payment
> processing.  In this case, the test client does not follow the
> redirect like a browser would because it is working at the WSGI layer.
>
> I test redirects with some utility methods on top of Python's urllib2.
>  For everything else, I use Flask's test client which is created with
> app.test_client().  In the thread of lettuce experience, I'd like to
> share this experience, because otherwise you'll be left wondering why
> FlaskClient isn't following redirects (and likely conclude it's a
> bug).

For the runtime, test client can be used directly in your lettuce
code, because the test client takes care of all of the application
routing.  This is the simple case.  If FlaskClient works for you, you
can stop reading here.

If you are using something other than FlaskClient, like Selenium or
utilities built on urllib2, you have to provide a development server
to run your tests.  Here are a couple options:

1) Build a hook to run a test server for you when you run lettuce.  I
don't know of any Flask-specific hooks, but here's one for Pylons to
give you the idea:

https://gist.github.com/517237

2) Run your application in one process and the lettuce test runner in
another, and configure your lettuce tests to point at the URL your
application provides.

-Ron

Re: [flask] Do you use flask with Lettuce?

From:
Italo Maia
Date:
2011-09-24 @ 04:43
Hummm, I think i get it now. I thought i should mix unittest and lettuce,
but I can use lettuce with FlaskClient straight forward. Thank you very
much. = ]

Walking around github, I found this:
https://github.com/dqminh/Flask-Lettuce Seems
promosing. The flask-script integration seems very helpful!

2011/9/22 Ron DuPlain <ron.duplain@gmail.com>

> On Thu, Sep 22, 2011 at 2:14 PM, Ron DuPlain <ron.duplain@gmail.com>
> wrote:
> > On Thu, Sep 22, 2011 at 2:06 PM, Italo Maia <italo.maia@gmail.com>
> wrote:
> >> By the way Ron, you suggest that werkzeud testing be used with lettuce
> or
> >> besides lettuce? Got a little confused.
> >
> > You can use FlaskClient (from app.test_client()) for most tests.  You
> > might face a limitation with the builtin test client if you are
> > testing redirects with a HTTP service outside of your project, for
> > example with a redirect for external authentication or payment
> > processing.  In this case, the test client does not follow the
> > redirect like a browser would because it is working at the WSGI layer.
> >
> > I test redirects with some utility methods on top of Python's urllib2.
> >  For everything else, I use Flask's test client which is created with
> > app.test_client().  In the thread of lettuce experience, I'd like to
> > share this experience, because otherwise you'll be left wondering why
> > FlaskClient isn't following redirects (and likely conclude it's a
> > bug).
>
> For the runtime, test client can be used directly in your lettuce
> code, because the test client takes care of all of the application
> routing.  This is the simple case.  If FlaskClient works for you, you
> can stop reading here.
>
> If you are using something other than FlaskClient, like Selenium or
> utilities built on urllib2, you have to provide a development server
> to run your tests.  Here are a couple options:
>
> 1) Build a hook to run a test server for you when you run lettuce.  I
> don't know of any Flask-specific hooks, but here's one for Pylons to
> give you the idea:
>
> https://gist.github.com/517237
>
> 2) Run your application in one process and the lettuce test runner in
> another, and configure your lettuce tests to point at the URL your
> application provides.
>
> -Ron
>



-- 
"A arrogância é a arma dos fracos."

===========================
Italo Moreira Campelo Maia
Bacharel em Ciência da Computação - UECE
Desenvolvedor WEB e Desktop (Java, Python, Lua)
Coordenador do Pug-CE
-----------------------------------------------------
http://www.italomaia.com/
http://twitter.com/italomaia/
http://eusouolobomau.blogspot.com/
-----------------------------------------------------
Turtle Linux  9.10 - http://tiny.cc/blogturtle910
Turtle Linux 10.10 - http://bit.ly/cEw4ET
===========================

Re: [flask] Do you use flask with Lettuce?

From:
Nikolaus Graf
Date:
2011-09-19 @ 16:28
I have created a repository with a plug&play example how to combine 
Lettuce, Lettuce Webdriver and Selenium.

https://github.com/blossom/lettuce-webdriver-setup

greetings Nik

On Sep 19, 2011, at 5:00 PM, Joseph Heck wrote:

> I've been using Lettuce with Flask for the past several weeks to
> reasonably good success. Any failings, I should say, are my own - as
> I've taken several runs and haven't been consistent on my DSL wording
> while putting it together.
> 
> I've fiddled with iterations that use Twill, Httplib2 directly, the
> Werkzeug testing client, and selenium - all with success. I have some
> detail on the steps and terrain.py file that I used at the bottom of a
> more general post on functional testing with fabric & lettuce:
> 
> 
http://www.rhonabwy.com/wp/2011/08/10/functional-testing-with-lettuce-and-fabric/
> 
> 2011/9/18 Italo Maia <italo.maia@gmail.com>:
>> Anyone using flask with lettuce? What did you think of the experience?
>> 
>> --
>> "A arrogância é a arma dos fracos."
>> 
>> ===========================
>> Italo Moreira Campelo Maia
>> Bacharel em Ciência da Computação - UECE
>> Desenvolvedor WEB e Desktop (Java, Python, Lua)
>> Coordenador do Pug-CE
>> -----------------------------------------------------
>> http://www.italomaia.com/
>> http://twitter.com/italomaia/
>> http://eusouolobomau.blogspot.com/
>> -----------------------------------------------------
>> Turtle Linux  9.10 - http://tiny.cc/blogturtle910
>> Turtle Linux 10.10 - http://bit.ly/cEw4ET
>> ===========================
>> 

Re: [flask] Do you use flask with Lettuce?

From:
Ron DuPlain
Date:
2011-09-19 @ 06:37
Hi Italo,

2011/9/19 Italo Maia <italo.maia@gmail.com>:
> Anyone using flask with lettuce? What did you think of the experience?

Lettuce is great for Flask.  You'll want to spend some time setting up
your terrain.py to initialize a test client for your desired test
environment.  Once you have your first few tests up and running, you
should find that writing features and steps is quite productive.

The Flask / Werkzeug test client
(http://flask.pocoo.org/docs/testing/) works well for most purposes,
but note that you cannot use it to test redirects to external servers
(e.g. redirects for external auth or payments), since the test client
is working at the WSGI layer.  For that, I used a simple HTTP client
using Python standard lib to follow redirects.  Selenium integrates
nicely for full-browser testing (or if you have something the test
client APIs do not do, including the redirect limitation I just
noted).  If you are using anything beyond Flask's builtin test client,
you'll have to run a development server to conduct your tests.

For the docs, I recommend Cucumber, http://cukes.info/.  The main
difference here is that you write your steps in Python instead of
Ruby, which is particularly useful in testing Flask applications.  The
Cucumber documentation does well to expose patterns, good ideas, and
bad ideas in behavioral testing.

Over time, you should find that you have a collection of steps which
you can use many times over when writing new feature files.  As with
Flask contexts, be careful what you load onto Lettuce's world
(thread-local object).  It's quite useful for maintaining state across
steps, particularly since you are emulating a user's browser, but you
can easily introduce bugs into your tests if you rely too heavily on
thread-locals.

Happy testing,

Ron