-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathtest_mx_appender.py
110 lines (89 loc) · 3.92 KB
/
test_mx_appender.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# -*- 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ć ( [email protected] )
"""
Suds MX appender unit tests.
Implemented using the 'pytest' testing framework.
"""
if __name__ == "__main__":
import testutils
testutils.run_using_pytest(globals())
from suds.mx.appender import PrimitiveAppender, TextAppender
from suds.xsd.sxbasic import Attribute
from suds.sax.element import Element
from unittest.mock import Mock
class MockContent:
def __init__(self, tag, value):
self.tag = tag
self.value = value
self.type = Mock(spec=Attribute)
class TestPrimitiveAppender:
def test_append_string(self):
parent = Element('foo')
content = MockContent("_TEST_TAG", "")
primitive_appender = PrimitiveAppender(Mock())
primitive_appender.append(parent, content)
assert parent.get("TEST_TAG") == ""
parent = Element('foo')
content = MockContent("_TEST_TAG", "bar")
primitive_appender = PrimitiveAppender(Mock())
primitive_appender.append(parent, content)
assert parent.get("TEST_TAG") == "bar"
def test_append_string_to_child(self):
parent = Mock()
content = MockContent("TEST_TAG", "")
primitive_appender = PrimitiveAppender(Mock())
mock_node = Mock()
primitive_appender.node = Mock(return_value=mock_node)
primitive_appender.append(parent, content)
mock_node.setText.assert_called_once_with("")
parent.append.assert_called_once_with(mock_node)
parent = Mock()
content = MockContent("TEST_TAG", "bar")
primitive_appender = PrimitiveAppender(Mock())
mock_node = Mock()
primitive_appender.node = Mock(return_value=mock_node)
primitive_appender.append(parent, content)
mock_node.setText.assert_called_once_with("bar")
parent.append.assert_called_once_with(mock_node)
class TestTextAppender:
def test_append_string(self):
parent = Element('foo')
content = MockContent("_TEST_TAG", "")
primitive_appender = TextAppender(Mock())
primitive_appender.append(parent, content)
assert parent.get("TEST_TAG") == ""
parent = Element('foo')
content = MockContent("_TEST_TAG", "bar")
primitive_appender = TextAppender(Mock())
primitive_appender.append(parent, content)
assert parent.get("TEST_TAG") == "bar"
def test_append_string_to_child(self):
parent = Mock()
content = MockContent("TEST_TAG", "")
primitive_appender = TextAppender(Mock())
mock_node = Mock()
primitive_appender.node = Mock(return_value=mock_node)
primitive_appender.append(parent, content)
mock_node.setText.assert_called_once_with("")
parent.append.assert_called_once_with(mock_node)
parent = Mock()
content = MockContent("TEST_TAG", "bar")
primitive_appender = TextAppender(Mock())
mock_node = Mock()
primitive_appender.node = Mock(return_value=mock_node)
primitive_appender.append(parent, content)
mock_node.setText.assert_called_once_with("bar")
parent.append.assert_called_once_with(mock_node)