|
1
|
|
|
# Copyright (C) 2020 Greenbone Networks GmbH |
|
2
|
|
|
# |
|
3
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later |
|
4
|
|
|
# |
|
5
|
|
|
# This program is free software; you can redistribute it and/or |
|
6
|
|
|
# modify it under the terms of the GNU General Public License |
|
7
|
|
|
# as published by the Free Software Foundation; either version 2 |
|
8
|
|
|
# of the License, or (at your option) any later version. |
|
9
|
|
|
# |
|
10
|
|
|
# This program is distributed in the hope that it will be useful, |
|
11
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
# GNU General Public License for more details. |
|
14
|
|
|
# |
|
15
|
|
|
# You should have received a copy of the GNU General Public License |
|
16
|
|
|
# along with this program; if not, write to the Free Software |
|
17
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18
|
|
|
|
|
19
|
|
|
from collections import OrderedDict |
|
20
|
|
|
|
|
21
|
|
|
from unittest import TestCase |
|
22
|
|
|
|
|
23
|
|
|
from ospd.xml import elements_as_text |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
class ElementsAsText(TestCase): |
|
27
|
|
|
def test_simple_element(self): |
|
28
|
|
|
elements = {'foo': 'bar'} |
|
29
|
|
|
text = elements_as_text(elements) |
|
30
|
|
|
|
|
31
|
|
|
self.assertEqual(text, '\t foo bar\n') |
|
32
|
|
|
|
|
33
|
|
|
def test_simple_elements(self): |
|
34
|
|
|
elements = OrderedDict([('foo', 'bar'), ('lorem', 'ipsum')]) |
|
35
|
|
|
text = elements_as_text(elements) |
|
36
|
|
|
|
|
37
|
|
|
self.assertEqual( |
|
38
|
|
|
text, |
|
39
|
|
|
'\t foo bar\n' |
|
40
|
|
|
'\t lorem ipsum\n', |
|
41
|
|
|
) |
|
42
|
|
|
|
|
43
|
|
|
def test_elements(self): |
|
44
|
|
|
elements = OrderedDict( |
|
45
|
|
|
[ |
|
46
|
|
|
('foo', 'bar'), |
|
47
|
|
|
( |
|
48
|
|
|
'lorem', |
|
49
|
|
|
OrderedDict( |
|
50
|
|
|
[ |
|
51
|
|
|
('dolor', 'sit amet'), |
|
52
|
|
|
('consectetur', 'adipiscing elit'), |
|
53
|
|
|
] |
|
54
|
|
|
), |
|
55
|
|
|
), |
|
56
|
|
|
] |
|
57
|
|
|
) |
|
58
|
|
|
text = elements_as_text(elements) |
|
59
|
|
|
|
|
60
|
|
|
self.assertEqual( |
|
61
|
|
|
text, |
|
62
|
|
|
'\t foo bar\n' |
|
63
|
|
|
'\t lorem \n' |
|
64
|
|
|
'\t dolor sit amet\n' |
|
65
|
|
|
'\t consectetur adipiscing elit\n', |
|
66
|
|
|
) |
|
67
|
|
|
|