[qmtest] derivation issues?

eichin at metacarta.com eichin at metacarta.com
Sat Dec 21 03:34:25 UTC 2002


hmm, working with this version (cvs head from earlier today), I get

> Error
> A value for the "base_url" parameter is missing.

when I try to submit any changes to the derived class.  Here's the
sample:

# more public domain code from Mark Eichin <eichin at metacarta.com>

import os
import re
import qm.common
import qm.fields
from qm.test.test import Test
from url_field import *
import urllib

class URLQuery(Test):
    """Test class to query a URL for a result."""

    arguments = [
        URLField(name="base_url",
                 title="Base URL",
                 description="""URL to add the search arguments to"""),
        TextField(name="match",
                  title="match",
                  description="""Regexp to match against URL result, should have one () group"""),
        TextField(name="result",
                  title="Result",
                  description="""Result string to check against match regexp"""),
        ]

    def GetDoc(self, url):
        """Get the URL, return as string"""
        u = urllib.urlopen(url)
        doc = u.read()
        u.close()
        return doc

    def Run(self, context, result):
        """Run the test."""
        causes = []
        doc = self.GetDoc(self.base_url)
        res = re.search(self.match, doc)
        if res == None:
            causes.append("regexp match")
            result["URLQuery.match"] = str(self.match)
            result["URLQuery.actual_doc"] = str(doc)
        elif res.group(1) != self.result:
            causes.append("regexp result")
            result["URLQuery.expected_result"] = str(self.result)
            result["URLQuery.actual_result"] = res.group(1)
            # result["URLQuery.actual_doc"] = str(doc)
        if causes:
            result.Fail("Failed %s." % string.join(causes, ", "))

class CGIArgumentField(qm.fields.TupleField):
    """A field which is a tag and value for a CGI search argument."""

    class_name = "ifacequery.CGIArgumentField"

    def __init__(self, name, **properties):
        """Create a new CGIArgumentField''.
        
        By default, the tag and value string are empty."""

        # Initialize the base class.
        fields = (qm.fields.TextField(name = "tag",
                                      title = "Tag",),
                  qm.fields.TextField(name = "value",
                                      title = "Value"))
        qm.fields.TupleField.__init__(self, name, fields, **properties)

class SearchQuery(URLQuery):
    """Test class to query a standard cgi-options style interface."""

    arguments = [
        SetField(CGIArgumentField(name="search_constraints",
                                  title="Search Constraints",
                                  description="""Tags and Values that constrain the search""")),
        URLField(name="base_url", computed="true"),
        URLField(name="search_url_base",
                 title="Search URL Base",
                 description="""Base URL for search strings"""),
        ]

    def GetTags(self):
        """extract the tags from the arguments, as a quoted list"""
        cgi_quoted_tags = []
        for tag, value in self.search_constraints:
            tag = urllib.quote_plus(tag)
            value = urllib.quote_plus(value)
            cgi_quoted_tags.extend(tag + "=" + value)
        return cgi_quoted_tags

    def __init__(self, name, **properties):
        self.base_url = self.search_url_base +
        string.join(self.GetTags(),"&")
        URLQuery.__init__(self, name, properties)

Oh, and urlfield.py is just a trivial derivation of TextField:

import qm.common
from qm.fields import *

class URLField(TextField):
    """A text field containing a URL."""

    class_name = "url_field.URLField"

    def GetTypeDescription(self):
        return "a URL"

    def FormatValueAsHtml(self, value, style, name=None):
        if style != "new" and style != "edit":
            return '<a href="%s">%s</a>' % (value, value)
        else:
            return TextField.FormatValueAsHtml(self, value, style, name)


Anyway, to duplicate, register these, qmtest gui, file->'new test',
name=foosearch, class=query.SearchQuery, and then you get a display
screen with the fields to fill in... and any change from there (like
any of the "add something" buttons, or hitting OK at the bottom) gives
the error described at the top.

I haven't figured out if this is a side effect of the recent changes
or not, or just something I've missed...

                                                        _Mark_



More information about the qmtest mailing list