[ptt-users] patch for agentbase.py

Lars Huttar lars_huttar at sil.org
Mon Oct 1 09:24:02 PDT 2007


Hello,
I made a few modifications to agentbase.py to make it more amenable to 
unit and functional testing of web applications.
As far as I can tell, currently the only kinds of verification supported 
are:
- going to a URL (via click or goto) succeeded, that is, returned an 
HTTP success code
- the title of a page is the expected string

Often, you want to check that data is correct, e.g. that the application 
returned the correct data value for a query. To do this, you want to 
check the content returned.
I modified the get() and post() functions to return the content as a 
string, so that these checks could be performed more easily by jython 
scripts.

The proposed patch is attached.

It would also be useful to add utility functions for checking that the 
returned content contains (or doesn't contain) a specified string:
def mustContain(self, content, requiredString, diagnostic):
    '''Assert that content contains requiredString; else raise exception 
with diagnostic message.'''
def mustNotContain(self, content, requiredString, diagnostic):
    '''Assert that content does not contain requiredString; else raise 
exception with diagnostic message.'''

And it would be nice to have built-in support for XPath expressions, so 
that this doesn't have to be done by hand each time:
def evalXPath(self, content, xpathExpr):
    '''Evaluate XPath expression with regard to content, and return 
result.'''
This could be used either for boolean tests:
    not(/*/body//p[contains(., 'error')])
or retrieving values
    /*/body//table[@class = 'accountDetails']/tr[td[1] = 'State']]/td[2]

Is there already support for these kinds of things, and I missed it?
If not, I would be happy to work on this, although I'm sure there are 
others who are more familiar with the relevant Python libraries.

Regards,
Lars





More information about the Users mailing list