]> git.wh0rd.org - gnudebbugs.git/blob - tests/test_soap.py
initial release
[gnudebbugs.git] / tests / test_soap.py
1 # Copyright (C) 2021 Free Software Foundation, Inc.
2 #
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
6 # later version.
7 #
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
11 # details.
12 #
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/>.
15
16 """Tests for the soap module."""
17
18 from pathlib import Path
19 from typing import Any, List
20 import unittest
21
22 import pytest
23
24 from gnudebbugs import soap
25
26 TEST_DIR = Path(__file__).resolve().parent
27 TEST_DATA = TEST_DIR / 'data'
28
29
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">\
37 <soap:Body>"""
38
39 # The end of every SOAP request.
40 SOAP_FOOTER = """</soap:Body></soap:Envelope>"""
41
42
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>'),
53 ))
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
58
59
60 @pytest.mark.parametrize("filename,expected", (
61 ('get_bug_log-33711.xml', [
62 {
63 'attachments': [],
64 'body': 'I compiled ...',
65 'header': '...',
66 'msg_num': 5,
67 },
68 {
69 'attachments': [],
70 'body': 'reassign 33711 autoconf...',
71 'header': '...',
72 'msg_num': 8,
73 },
74 {
75 'attachments': [],
76 'body': 'reassign 33711 autoconf\nstop\n',
77 'header': '...',
78 'msg_num': 10,
79 },
80 {
81 'attachments': [],
82 'body': 'owner 33711 bug-autoconf@gnu.org\nstop\n',
83 'header': '...',
84 'msg_num': 12,
85 },
86 ]),
87 ('get_bugs-0.xml', []),
88 ('get_bugs-2.xml', [25740, 33711]),
89 ('get_status-0.xml', None),
90 ('get_status-1.xml', {
91 52435: {
92 'affects': '',
93 'archived': 0,
94 'blockedby': '',
95 'blocks': '',
96 'bug_num': 52435,
97 'date': 1639234742,
98 'done': '',
99 'fixed': None,
100 'fixed_date': [],
101 'fixed_versions': [],
102 'forwarded': '',
103 'found': {
104 '29.0.50': None,
105 },
106 'found_date': [],
107 'found_versions': [
108 '29.0.50',
109 ],
110 'id': 52435,
111 'keywords': '',
112 'last_modified': 1639234742,
113 'location': 'db-h',
114 'log_modified': 1639234742,
115 'mergedwith': '',
116 'msgid': '<46037FBE-8DAB-4913-850C-96F4F78622E2@Web.DE>',
117 'originator': 'The Reporter <example@example.com>',
118 'owner': '',
119 'package': 'emacs',
120 'pending': 'pending',
121 'severity': 'normal',
122 'source': 'unknown',
123 'subject': '29.0.50; C-y seems to contain an old contents',
124 'summary': '',
125 'tags': '',
126 'unarchived': '',
127 },
128 }),
129 ('get_status-2.xml', {
130 52435: {
131 'affects': '',
132 'archived': 0,
133 'blockedby': '',
134 'blocks': '',
135 'bug_num': 52435,
136 'date': 1639234742,
137 'done': '',
138 'fixed': None,
139 'fixed_date': [],
140 'fixed_versions': [],
141 'forwarded': '',
142 'found': {
143 '29.0.50': None,
144 '4.16': None,
145 },
146 'found_date': [],
147 'found_versions': [
148 '29.0.50',
149 ],
150 'id': 52435,
151 'keywords': '',
152 'last_modified': 1639234742,
153 'location': 'db-h',
154 'log_modified': 1639234742,
155 'mergedwith': '',
156 'msgid': '<46037FBE-8DAB-4913-850C-96F4F78622E2@Web.DE>',
157 'originator': 'The Reporter <example@example.com>',
158 'owner': '',
159 'package': 'emacs',
160 'pending': 'pending',
161 'severity': 'normal',
162 'source': 'unknown',
163 'subject': '29.0.50; C-y seems to contain an old contents',
164 'summary': '',
165 'tags': '',
166 'unarchived': '',
167 },
168 52436: {
169 'affects': '',
170 'archived': 0,
171 'blockedby': '',
172 'blocks': '',
173 'bug_num': 52436,
174 'date': 1639234742,
175 'done': '',
176 'fixed': None,
177 'fixed_date': [],
178 'fixed_versions': [],
179 'forwarded': '',
180 'found': None,
181 'found_date': [],
182 'found_versions': [],
183 'id': 52436,
184 'keywords': 'patch',
185 'last_modified': 1639234743,
186 'location': 'db-h',
187 'log_modified': 1639234743,
188 'mergedwith': '',
189 'msgid': '<87h7bfrxw9.fsf@web.de>',
190 'originator': '"Dr. Reporter" <example@example.com>',
191 'owner': '',
192 'package': 'guile',
193 'pending': 'pending',
194 'severity': 'normal',
195 'source': 'unknown',
196 'subject': '[patch] autoconf: Check for gperf if running from git',
197 'summary': '',
198 'tags': 'patch',
199 'unarchived': '',
200 },
201 }),
202 ('get_usertag-0.xml', None),
203 ('newest_bugs-0.xml', []),
204 ('newest_bugs-1.xml', [52436]),
205 ('newest_bugs-2.xml', [52435, 52436]),
206 ))
207 def test_parse(filename: str, expected: Any):
208 data = (TEST_DATA / filename).read_text()
209 result = soap.parse(data)
210 assert result == expected