Quantcast

Advice On Testing With XML

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Advice On Testing With XML

Tennis Smith-3
Hi,

I'm looking for some guidence in handling a testing issue.  I'm new to XML/XSLT, so please bear with me.

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.

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". 

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. But I was hoping someone could tell me if I can do some kind of XSLT or whatever to get the same effect.

Thanks,


_______________________________________________
XML-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/xml-sig
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Advice On Testing With XML

Stefan Behnel-3
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?


> 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?


> 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. But
> I was hoping someone could tell me if I can do some kind of XSLT or whatever
> 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.

Stefan

_______________________________________________
XML-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/xml-sig
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Advice On Testing With XML

Tennis Smith-3


On Thu, Jul 9, 2009 at 1:13 PM, Stefan Behnel <[hidden email]> 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. But
> I was hoping someone could tell me if I can do some kind of XSLT or whatever
> 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



_______________________________________________
XML-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/xml-sig
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Advice On Testing With XML

Peter Bigot-4
In reply to this post by Tennis Smith-3
I don't grasp exactly what you're trying to do, but if you need a program that generates XML documents that conform to a schema for which date values are relative to today, I agree having the harness write the older date seems to make sense.

If generateDS doesn't fully support all the XML Schema date types, you could do that using PyXB with a program like this:

  import schema
  import pyxb.binding.datatypes as xsd
  import datetime

  delta = xsd.duration('P3D')

  s = schema.instance()
  s.setElt(datetime.date.today() - delta)
  print s.toxml()


with output:

 <?xml version="1.0" ?><instance><elt>2009-07-06</elt></instance>

assuming the schema is:

  <?xml version="1.0" encoding="UTF-8"?>
  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="instance" type="structure"/>
    <xs:complexType name="structure">
      <xs:sequence>
        <xs:element name="elt" minOccurs="0" type="xs:date"/>
      </xs:sequence>
    </xs:complexType>
  </xs:schema>


PyXB (see http://pyxb.sourceforge.net) is definitely beta software, but it's coming along nicely.  It makes a strong effort to validate the data written into the binding instances (in fact, a weakness is that you can't stop it from trying to validate).  It can also handle very complex schemas, such as those from OpenGIS.

If you really need to change the type of an element in a complex type at runtime, it could be done by generating a customized binding (though you'd have to modify the runtime support class pyxb.binding.basis.element to allow this particular kind of customization).

Peter

Tennis Smith wrote:
Hi,

I'm looking for some guidence in handling a testing issue.  I'm new to XML/XSLT, so please bear with me.

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.

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". 

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. But I was hoping someone could tell me if I can do some kind of XSLT or whatever to get the same effect.

Thanks,


_______________________________________________ XML-SIG maillist - [hidden email] http://mail.python.org/mailman/listinfo/xml-sig


_______________________________________________
XML-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/xml-sig
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Advice On Testing With XML

Robert Kim Wireless Internet Advisor
In reply to this post by Tennis Smith-3
Are you guys on twitter? whats your twitter address?
im @journik

On Thu, Jul 9, 2009 at 12:06 PM, Tennis Smith<[hidden email]> wrote:

> Hi,
>
> I'm looking for some guidence in handling a testing issue.  I'm new to
> XML/XSLT, so please bear with me.
>
> 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.
>
> 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".
>
> 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. But
> I was hoping someone could tell me if I can do some kind of XSLT or whatever
> to get the same effect.
>
> Thanks,
>
>
> _______________________________________________
> XML-SIG maillist  -  [hidden email]
> http://mail.python.org/mailman/listinfo/xml-sig
>
>



--
Robert Q Kim, Wireless Internet Provider
http://journik.com
http://journik.posterous.com
http://twitter.com/journik
_______________________________________________
XML-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/xml-sig
Loading...