Albert Brandl wrote:
>
> On Mon, 19 Mar 2001, Chuck Esterbrook wrote:
>
> > A friend & colleague of mine and I were discussing testing of web sites. I
> > pointed out that I currently scan the HTML output of my web application for
> > important substrings, but that in the future I want to do more detailed
> > analysis on the contents. For example, if the page has a table of numbers,
> > I'd like to be able to work with those numbers to do comparisons, check for
> > "greater than zero", etc.
>
> If you decouple the logic from the presentation (i.e. use
> a model-view-controller architecture), this kind of testing
> is no longer needed. You can test the controller without any
> need to parse HTML; since the view does not contain much
> logic, scanning for substrings might well be enough.
>
> The idea is to associate a controller with every Page
> object, e.g.:
>
> import string
>
> class MyUser:
> def digestName(self, name):
> self.name = string.upper(name)
>
> def digestId(self, id):
> self.id = string.upper(id)
>
> class MyController:
> """controller for the behaviour of MyPage
> Maybe there will be some common logic which
> can be placed in a superclass"""
>
> def __init__(self):
> """initialize the necessary data"""
>
> self.model = MyUser()
>
> def digestId(self, request):
> """do something with the id"""
>
> # [some logic here]
> self.model.digestId(request.value("id"))
> # [some more logic here]
>
> def digestName(self, request):
> """do something with the name"""
>
> # [some logic here]
> self.model.digestName(request.value("name"))
> # [some more logic here]
>
>
> class MyPage (SidebarPage):
> """presentation of data; forwards all actions to
> self.ctl"""
>
> def __init__(self):
> """initialize controller"""
>
> self.ctl = Controller()
>
> def digestId(self):
> """forward request to digest the id"""
>
> self.ctl.digestId(self.request())
>
> def digestName(self):
> """forward request to digest the name"""
>
> self.ctl.digestName(self.request())
>
> def actions(self):
> """these actions are defined"""
>
> return SidebarPage.actions(self) + \
> ["digestId",
> "digestName"]
>
> def methodNameForAction(self, action):
> """map button name to action"""
>
> return {"Set ID": "digestId",
> "Set Name": "digestName"}[action]
>
> You can now test the logic of digestName and digestId
> without having to worry about HTML tables and the like.
> If it's still necessary to test the class MyPage, you can
> feed it with some dummy data and have the test suite compare
> the output with some output which has been proven to be
> correct.
>
> What do you think about this approach? How well does it fit
> the architecture of WebKit?
Everything which works fits (my opinion :-))
I like your MVC approach. It's the way I want
to go myself (+ Workflow classes)
I have one question though. Do you
have a working example for you approach,
just to see how you think it should
work. Does not have to be complicated,
justadd some more code to what you sent..
class MyController:
"""controller for the behaviour of MyPage
Maybe there will be some common logic which
can be placed in a superclass"""
def __init__(self):
"""initialize the necessary data"""
self.model = MyUser()
def digestId(self, request):
"""do something with the id"""
This is one thing I do not like: The request variable
in digestId, because this way the controller is Web-dependant.
Maybe I do not have a request (want to use it in a GUI application
or simple Python script, where the controller should work too).
Also the forwarding of all variables could be done generically
with a MixIn, although I'm not shure yet how.)
Please make a small working example, so I and other people can
extend it and work on the code. I have a lot more suggestions
(the use of Cans for example), but I'd like to see the
whole picture first :-)
I think writing a good and future proof Webware application
is not trivial, but I'm willing to test all kind of approaches
and document the final result (MVC ist of course first on my
list, second different template engines, see e.g.
http://mail.python.org/pipermail/python-list/2001-March/033834.html
and some other ideas which where posted on this list).
--
Tom Schwaller
http://www.linux-community.de
|