[XML-SIG] Advice On Testing With XML

Tennis Smith tennis at tripit.com
Thu Jul 9 23:20:53 CEST 2009

On Thu, Jul 9, 2009 at 1:13 PM, Stefan Behnel <stefan_ml at behnel.de> wrote:

> Hi,
> Tennis Smith wrote:
> > First, a little background.  My charter is to generate XML test messages
> to
> > make sure we process them correctly.  These messages are validated
> against a
> > schema.  I'm using generateDS to generate the test messages.  This
> ensures
> > the xml is correct.
> Hmm, I never (really) used generateDS. AFAIR, it generates Python objects
> that you work with. Does it validate their structure while you do so? Or
> did you refer to the schema validation that "ensures" the message
> correctness?

genDS ensures correctness because there are several layers of object types
cascaded in the schema.  Since genDS creates wrappers for all these, it
makes creating schema-compliant objects really easy.

> > Everything works great except for one problem that keeps cropping up.
>  Some
> > elements cannot be defined easily ahead of time when generating the final
> > test document.
> >
> > For example, a field of type "xs:date" will have to be modifed because
> tests
> > are based on a relative date, not an absolute one. That is, dates in
> tests
> > are based on things like "3 days before today".
> >
> > Therefore, I'd like to figure out some way to change certain fields like
> > date so that I can pass a string and _still validate_ it against the
> > schema.  Using the example, "-3" would be passed in the date field so
> that
> > the test harness will recognize it as "today - 3 days".
> Why can't you just write the corresponding date into the messages when you
> generate them?

The messages are generated long before they are actually transmitted.  There
are literally thousands of tests which are created this way.  After
generation, they're stored in svn and then used much later.

> Put another way, the goal is to make this:
> *  <xs:element maxOccurs="1" minOccurs="0" name="date" type="xs:date"/>*
> ...behave like this:
>  *<xs:element maxOccurs="1" minOccurs="0" name="date" type="xs:string"/>*
> Naturally, I can edit and copy/paste into a completely new schema file.
> I was hoping someone could tell me if I can do some kind of XSLT or
> to get the same effect.

I'd just change the schema on the way in. You didn't say what tool you use
> for validation, but at least in lxml, modifying the schema tree is pretty
> trivial. You can simply use XPath to find all date types and then fix their
> type attribute.

The tool I'm using is etree.  That's a great suggestion concerning xpath.
That sounds pretty easy.

Thanks, Stefan!

> Stefan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/xml-sig/attachments/20090709/f9a3559b/attachment.htm>

More information about the XML-SIG mailing list