add basic suds.sax.element unit tests
For now just tests: - basic Element construction, - construction name parameter handling - childAtPath() method Updated todo list, including adding many new todo items related to adding new tests.
This commit is contained in:
parent
d5efc8081f
commit
8f424659d7
51
TODO.txt
51
TODO.txt
|
@ -1356,7 +1356,11 @@ PRIORITIZED:
|
|||
(+) our testing system over to use the tox project.
|
||||
(+) * Update HACKING.rst documentation.
|
||||
|
||||
(30.05.2014.)
|
||||
(14.06.2014.)
|
||||
|
||||
(+) * (Jurko) Add basic suds.sax.Element unit tests.
|
||||
|
||||
(15.06.2014.)
|
||||
|
||||
* (Jurko) Look at the Spyne project and its suds usage.
|
||||
* Try running Spyne's test suite using the suds-jurko fork.
|
||||
|
@ -1707,6 +1711,39 @@ PRIORITIZED:
|
|||
NON PRIORITIZED:
|
||||
=================================================
|
||||
|
||||
* Add suds.sax.element related tests.
|
||||
* append().
|
||||
* Add child element.
|
||||
* Add child attribute.
|
||||
* childAtPath().
|
||||
* With namespaces.
|
||||
* With prefixes.
|
||||
* Empty child name - as initial child - requested.
|
||||
* Empty child name - as initial child - pass through.
|
||||
* Empty child name - as indirect child - requested.
|
||||
* Empty child name - as indirect child - pass through.
|
||||
* Handling multiple children with matching names - is there to
|
||||
specify an index.
|
||||
* Add child by constructing it with a parent argument - should
|
||||
automatically add the element to the parent's children list, while the
|
||||
current implementation only makes the child know about the parent and
|
||||
does not let the parent know about the child.
|
||||
* Constructing an element with '/' in its name should not be allowed
|
||||
since that character is used as a part separator.
|
||||
* See if a way to escape such character usage is needed and if so -
|
||||
how to do it.
|
||||
* Handling multiple children with matching names.
|
||||
* childrenAtPath().
|
||||
* Initializing a new element with a specific namespace.
|
||||
|
||||
* Add suds.sax.document unit tests similar to those already added for
|
||||
suds.sax.element.
|
||||
* Some ideas on what to not forget.
|
||||
* See suds.sax.element related tests & todo notes.
|
||||
* childAtPath().
|
||||
* childrenAtPath().
|
||||
* No root element.
|
||||
|
||||
* Look into CDATA related encoding issues reported at BitBucket (issue #14 +
|
||||
pull requests #25 & #26).
|
||||
* Current status: waiting for further feedback or progress on BitBucket.
|
||||
|
@ -1812,17 +1849,11 @@ NON PRIORITIZED:
|
|||
* This method will automatically download & install pytest from
|
||||
PyPI if needed, but will leave their installations behind in
|
||||
the project's root folder.
|
||||
* May be run from the root project folder by first building the
|
||||
project to a temporary location: 'setup.py build & pytest build'.
|
||||
* This method allows specifying additional pytest command-line
|
||||
arguments.
|
||||
* May be run by first building the project by installing the
|
||||
project, e.g. by running 'setup.py develop' and then running
|
||||
'pytest' from the project's 'tests' folder.
|
||||
* Do some more thinking on this and, when done, update related HACKING
|
||||
notes.
|
||||
* Some ideas from reading through the setuptools documentation.
|
||||
* 'setup.py test' command could be implemented better to support
|
||||
pytest arguments - look at the setuptools project's
|
||||
test_loader setup keyword (https://pythonhosted.org/setuptools
|
||||
/setuptools.html#test-loader).
|
||||
|
||||
* Generate suds Python library documentation (epydoc).
|
||||
* Research.
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the (LGPL) GNU Lesser General Public License as published by the
|
||||
# Free Software Foundation; either version 3 of the License, or (at your
|
||||
# option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU Library Lesser General Public License
|
||||
# for more details at ( http://www.gnu.org/licenses/lgpl.html ).
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
# written by: Jurko Gospodnetić ( jurko.gospodnetic@pke.hr )
|
||||
|
||||
"""
|
||||
Suds SAX Element unit tests.
|
||||
|
||||
Implemented using the 'pytest' testing framework.
|
||||
|
||||
"""
|
||||
|
||||
if __name__ == "__main__":
|
||||
import testutils
|
||||
testutils.run_using_pytest(globals())
|
||||
|
||||
from suds.sax.element import Element
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
class TestChildAtPath:
|
||||
|
||||
def test_backslash_as_path_separator(self):
|
||||
name1 = "child"
|
||||
name2 = "grandchild"
|
||||
root = self.__create_single_branch("root", name1, name2)[0]
|
||||
result = root.childAtPath(name1 + "\\" + name2)
|
||||
assert result is None
|
||||
|
||||
def test_backslash_in_name(self):
|
||||
root, a, _, _ = self.__create_single_branch("root", "a", "b", "c")
|
||||
b_c = Element("b\\c")
|
||||
a.append(b_c)
|
||||
result = root.childAtPath("a/b\\c")
|
||||
assert result is b_c
|
||||
|
||||
def test_child_leaf(self):
|
||||
root, child = self.__create_single_branch("root", "child")
|
||||
result = root.childAtPath("child")
|
||||
assert result is child
|
||||
|
||||
def test_child_not_leaf(self):
|
||||
root, child, _ = self.__create_single_branch("root", "child",
|
||||
"grandchild")
|
||||
result = root.childAtPath("child")
|
||||
assert result is child
|
||||
|
||||
def test_grandchild_leaf(self):
|
||||
root, _, grandchild = self.__create_single_branch("root", "child",
|
||||
"grandchild")
|
||||
result = root.childAtPath("child/grandchild")
|
||||
assert result is grandchild
|
||||
|
||||
def test_grandchild_not_leaf(self):
|
||||
root, _, grandchild, _ = self.__create_single_branch("root", "child",
|
||||
"grandchild", "great grandchild")
|
||||
result = root.childAtPath("child/grandchild")
|
||||
assert result is grandchild
|
||||
|
||||
def test_misplaced(self):
|
||||
root = self.__create_single_branch("root", "a", "x", "b")[0]
|
||||
result = root.childAtPath("a/b")
|
||||
assert result is None
|
||||
|
||||
def test_missing(self):
|
||||
root = Element("root")
|
||||
result = root.childAtPath("an invalid path")
|
||||
assert result is None
|
||||
|
||||
def test_name_including_spaces(self):
|
||||
root, _, child, _ = self.__create_single_branch("root", "dumbo",
|
||||
"foo - bar", "baz")
|
||||
result = root.childAtPath("dumbo/foo - bar")
|
||||
assert result is child
|
||||
|
||||
@pytest.mark.parametrize("n", (2, 3))
|
||||
def test_repeated_path_separators(self, n):
|
||||
root, child, grandchild = self.__create_single_branch("root", "child",
|
||||
"grandchild")
|
||||
sep = "/" * n
|
||||
path = "child" + sep + "grandchild"
|
||||
result = root.childAtPath(path)
|
||||
assert result is grandchild
|
||||
|
||||
def test_same_named(self):
|
||||
root, _, child, _ = self.__create_single_branch("root", "a", "a", "a")
|
||||
result = root.childAtPath("a/a")
|
||||
assert result is child
|
||||
|
||||
@staticmethod
|
||||
def __create_single_branch(*args):
|
||||
"""
|
||||
Construct a single branch element tree with given element names.
|
||||
|
||||
Returns a list of constructed Element nodes from root to leaf.
|
||||
|
||||
"""
|
||||
result = []
|
||||
parent = None
|
||||
for name in args:
|
||||
e = Element(name)
|
||||
result.append(e)
|
||||
if parent is not None:
|
||||
parent.append(e)
|
||||
parent = e
|
||||
return result
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name, expected_prefix, expected_name", (
|
||||
("", None, ""),
|
||||
("bazinga", None, "bazinga"),
|
||||
("test element name", None, "test element name"),
|
||||
("aaa:bbb", "aaa", "bbb"),
|
||||
("aaa:", "aaa", ""),
|
||||
(":aaa", "", "aaa"),
|
||||
("aaa::bbb", "aaa", ":bbb"),
|
||||
("aaa:bbb:ccc", "aaa", "bbb:ccc")))
|
||||
def test_init_name(name, expected_prefix, expected_name):
|
||||
e = Element(name)
|
||||
assert e.prefix == expected_prefix
|
||||
assert e.name == expected_name
|
Loading…
Reference in New Issue