]>
git.wh0rd.org - gnudebbugs.git/blob - tests/test_soap.py
1 # Copyright (C) 2021 Free Software Foundation, Inc.
3 # This program is free software: you can redistribute it and/or modify it under
4 # the terms of the GNU Lesser General Public License as published by the Free
5 # Software Foundation, either version 3 of the License, or at your option) any
8 # This program is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 # You should have received a copy of the GNU Lesser General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 """Tests for the soap module."""
18 from pathlib
import Path
19 from typing
import Any
, List
24 from gnudebbugs
import soap
26 TEST_DIR
= Path(__file__
).resolve().parent
27 TEST_DATA
= TEST_DIR
/ 'data'
30 # The start of every SOAP request.
31 SOAP_HEADER
= """<?xml version="1.0" encoding="UTF-8"?>\
32 <soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" \
33 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" \
34 xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" \
35 xmlns:xsd="http://www.w3.org/2001/XMLSchema" \
36 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\
39 # The end of every SOAP request.
40 SOAP_FOOTER
= """</soap:Body></soap:Envelope>"""
43 @pytest.mark
.parametrize("func,args,kwargs,expected", (
44 (soap
.Api
.get_bug_log
, [1234], {}, '<get_bug_log><xsd:int>1234</xsd:int></get_bug_log>'),
45 (soap
.Api
.get_bugs
, [], {}, '<get_bugs></get_bugs>'),
46 (soap
.Api
.get_bugs
, [], {'package': 'automake'}, '<get_bugs><a0>package</a0><a1>automake</a1></get_bugs>'),
47 (soap
.Api
.get_status
, [[]], {}, '<get_status></get_status>'),
48 (soap
.Api
.get_status
, [[1]], {}, '<get_status><xsd:int>1</xsd:int></get_status>'),
49 (soap
.Api
.get_status
, [[1, 2]], {}, '<get_status><xsd:int>1</xsd:int><xsd:int>2</xsd:int></get_status>'),
50 # (soap.Api.get_usertag, ['v@b', []], {}, '<get_status><xsd:int>1</xsd:int><xsd:int>2</xsd:int></get_status>'),
51 (soap
.Api
.newest_bugs
, [0], {}, '<newest_bugs><xsd:int>0</xsd:int></newest_bugs>'),
52 (soap
.Api
.newest_bugs
, [100], {}, '<newest_bugs><xsd:int>100</xsd:int></newest_bugs>'),
54 def test_encode(func
, args
: List
[Any
], kwargs
, expected
: str):
55 expected
= SOAP_HEADER
+ expected
+ SOAP_FOOTER
56 result
= func(*args
, **kwargs
)
57 assert result
== expected
60 @pytest.mark
.parametrize("filename,expected", (
61 ('get_bug_log-33711.xml', [
64 'body': 'I compiled ...',
70 'body': 'reassign 33711 autoconf...',
76 'body': 'reassign 33711 autoconf\nstop\n',
82 'body': 'owner 33711 bug-autoconf@gnu.org\nstop\n',
87 ('get_bugs-0.xml', []),
88 ('get_bugs-2.xml', [25740, 33711]),
89 ('get_status-0.xml', None),
90 ('get_status-1.xml', {
101 'fixed_versions': [],
112 'last_modified': 1639234742,
114 'log_modified': 1639234742,
116 'msgid': '<46037FBE-8DAB-4913-850C-96F4F78622E2@Web.DE>',
117 'originator': 'The Reporter <example@example.com>',
120 'pending': 'pending',
121 'severity': 'normal',
123 'subject': '29.0.50; C-y seems to contain an old contents',
129 ('get_status-2.xml', {
140 'fixed_versions': [],
152 'last_modified': 1639234742,
154 'log_modified': 1639234742,
156 'msgid': '<46037FBE-8DAB-4913-850C-96F4F78622E2@Web.DE>',
157 'originator': 'The Reporter <example@example.com>',
160 'pending': 'pending',
161 'severity': 'normal',
163 'subject': '29.0.50; C-y seems to contain an old contents',
178 'fixed_versions': [],
182 'found_versions': [],
185 'last_modified': 1639234743,
187 'log_modified': 1639234743,
189 'msgid': '<87h7bfrxw9.fsf@web.de>',
190 'originator': '"Dr. Reporter" <example@example.com>',
193 'pending': 'pending',
194 'severity': 'normal',
196 'subject': '[patch] autoconf: Check for gperf if running from git',
202 ('get_usertag-0.xml', None),
203 ('newest_bugs-0.xml', []),
204 ('newest_bugs-1.xml', [52436]),
205 ('newest_bugs-2.xml', [52435, 52436]),
207 def test_parse(filename
: str, expected
: Any
):
208 data
= (TEST_DATA
/ filename
).read_text()
209 result
= soap
.parse(data
)
210 assert result
== expected