Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unittest-xml

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unittest-xml

Additional assertion methods for testing XML

  • 0.2.2
  • PyPI
  • Socket score

Maintainers
1

========================= Testing XML with unittest

This library is a set of helper methods for testing XML with Python's unittest library. The new assertion methods use XPath_ to select the XML elements that assertions are being made about.

.. _XPath: http://en.wikipedia.org/wiki/XPath

Sample usage

To use these additional assertions, simply mix the xmltest.XMLAssertions class into your test class::

import unittest
from xmltest import XMLAssertions

class MyTestCase(unittest.TestCase, XMLAssertions):
    pass

Now suppose you have the following XML string that you wish to examine::

response_xml = """<?xml version="1.0" encoding="UTF-8" ?>
<Response>
    <CardTxn>
        <authcode>060642</authcode>
        <card_scheme>Switch</card_scheme>
        <issuer country="UK">HSBC</issuer>
    </CardTxn>
    <reference>3000000088888888</reference>
    <merchantreference>1000001</merchantreference>
    <mode>LIVE</mode>
    <reason>ACCEPTED</reason>
    <status>1</status>
    <time>1071567305</time>
</Response>"""

Assert the number of elements matching an XPath query::

self.assertXPathNodeCount(response_xml, 1, 'CardTxn/issuer[@country="UK"]')
self.assertXPathNodeCount(response_xml, 1, 'status')

Assert the value of a particular element::

self.assertXPathNodeText(response_xml, 'ACCEPTED', 'reason')

Assert the attribute values of an element::

self.assertXPathNodeAttributes(xml, {'country': 'UK'}, 'CardTxn/issuer'}

Installation

From PyPi::

pip install unittest-xml

Contributing

To run the tests, install nose and mock::

pip install nose mock

and use::

nosetests

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc