def test_MyWidget()
paramsForMyWidget = dict(...)
mw = MyWidget()
widgetOutput = mw.render(**paramsForMyWidget)
assert 'some string' in widgetOutput
-Ian
Based on the docstring I think you can assume for the most part that
it acts just like the display method. You only need to pass the
params you would have needed at display time. Ie. whatever you define
in params in your Widget's definition. And you should expect back the
populated html.
Here is the docstring looked up on one of my instantiated widgets in
tg-admin shell:
render(self, value=None, format='html', **params)
Exactly the same as display() but return serialized output instead.
Useful for debugging or to display the widget in a non-Kid template like
Cheetah, STAN, ...
Another note if you need to make sure that the css/js are working you
can do something like this:
mw = MyWidget()
for cssWidget in mw.retrieve_css():
cssString = cssString + cssWidget.render()
assert 'some css string' in cssString
assert 'some css link' in cssString
for jsWidget in mw.retrieve_javascript():
jsString = jsString + jsWidget.render()
assert 'some js string' in jsString
assert 'some js link' in jsString
retrieve_css and retrieve_javascript are used by the master.kid (KID)
or master.html(GENSHI) to get the css and js that should be included
when a widget is returned from a controller.
Testing this out in tg-admin shell first will help you see what I mean
and you can work out the details you will need when setting up your
tests.
Tell me if this all doesn't make sense.
Some of my (related) questions are:
Can one test method have multiple assert statements?
What other assert statements can be created? (e.g. not just string
match)
>
> Thanks a lot.
>
> Some of my (related) questions are:
>
> Can one test method have multiple assert statements?
Yes, as many as you'd like. However, it's good practice to group
related asserts under the same function with a self describing name.
Keep in mind that when one assert fails, the ones that follow it
under the same function wont be executed.
>
> What other assert statements can be created? (e.g. not just string
> match)
You can assert any boolean condition:
assert 1 + 1 == 2
assert is_active()
assert True
etc...
Alberto
> Thanks a lot.
>
> Some of my (related) questions are:
>
> Can one test method have multiple assert statements?
Yes, but then it's not a "unit" anymore. Why not having multiple tests
testing each behavior?
> What other assert statements can be created? (e.g. not just string
> match)
Take a look at the docs for the test module you're using. There are several
of them...
For the standard case: http://docs.python.org/lib/module-unittest.html
--
Jorge Godoy <jgo...@gmail.com>
In addition to what they said you probably want to focus on 4
potential problems(4 tests).
1. Make sure the widget's template compiles and you can import it..
by trying to import it.
from project.widgets import MyWidget
2. Make sure the widget instantiates.
myWidget = MyWidget(**defaultParams)
3. Make sure the wiget's template is correctly interpolating by calling render.
myWidgetOutput = myWidget.render(**params)
4. Check that the output of the widget's render method is correct by
checking string inclusion.
assert someString in myWidgetOutput
-Ian
> Ha you guys are fast.
>
> In addition to what they said you probably want to focus on 4
> potential problems(4 tests).
>
> 1. Make sure the widget's template compiles and you can import it..
> by trying to import it.
> from project.widgets import MyWidget
>
> 2. Make sure the widget instantiates.
> myWidget = MyWidget(**defaultParams)
>
> 3. Make sure the wiget's template is correctly interpolating by calling render.
> myWidgetOutput = myWidget.render(**params)
>
> 4. Check that the output of the widget's render method is correct by
> checking string inclusion.
> assert someString in myWidgetOutput
>
> -Ian
I like testing with the toolbox as well. This makes me write a description to
it, document every variable I use and I have a test case that can be used by
other people without they having to look at my source code.
--
Jorge Godoy <jgo...@gmail.com>