tcms-api 15.0__tar.gz → 17.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tcms_api-15.0/tcms_api.egg-info → tcms_api-17.3}/PKG-INFO +19 -23
- {tcms_api-15.0 → tcms_api-17.3}/README.rst +15 -9
- tcms_api-17.3/requirements.txt +0 -0
- {tcms_api-15.0 → tcms_api-17.3}/setup.cfg +4 -0
- {tcms_api-15.0 → tcms_api-17.3}/setup.py +3 -11
- {tcms_api-15.0 → tcms_api-17.3}/tcms_api/__init__.py +64 -40
- {tcms_api-15.0 → tcms_api-17.3}/tcms_api/plugin_helpers.py +75 -6
- tcms_api-17.3/tcms_api/version.py +1 -0
- tcms_api-17.3/tcms_api/xmlrpc.py +100 -0
- {tcms_api-15.0 → tcms_api-17.3/tcms_api.egg-info}/PKG-INFO +19 -23
- {tcms_api-15.0 → tcms_api-17.3}/tcms_api.egg-info/SOURCES.txt +1 -1
- tcms_api-17.3/tests/test_case.py +178 -0
- tcms_api-17.3/tests/test_token_auth.py +118 -0
- tcms_api-15.0/requirements.txt +0 -2
- tcms_api-15.0/tcms_api/version.py +0 -1
- tcms_api-15.0/tcms_api/xmlrpc.py +0 -189
- tcms_api-15.0/tcms_api.egg-info/requires.txt +0 -5
- tcms_api-15.0/tests/test_case.py +0 -45
- {tcms_api-15.0 → tcms_api-17.3}/LICENSE +0 -0
- {tcms_api-15.0 → tcms_api-17.3}/MANIFEST.in +0 -0
- {tcms_api-15.0 → tcms_api-17.3}/tcms_api.egg-info/dependency_links.txt +0 -0
- {tcms_api-15.0 → tcms_api-17.3}/tcms_api.egg-info/top_level.txt +0 -0
- {tcms_api-15.0 → tcms_api-17.3}/tests/test_api_config.py +0 -0
- {tcms_api-15.0 → tcms_api-17.3}/tests/test_build.py +0 -0
- {tcms_api-15.0 → tcms_api-17.3}/tests/test_plan.py +0 -0
- {tcms_api-15.0 → tcms_api-17.3}/tests/test_plantype.py +0 -0
- {tcms_api-15.0 → tcms_api-17.3}/tests/test_product.py +0 -0
- {tcms_api-15.0 → tcms_api-17.3}/tests/test_run.py +0 -0
- {tcms_api-15.0 → tcms_api-17.3}/tests/test_status.py +0 -0
- {tcms_api-15.0 → tcms_api-17.3}/tests/test_version.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tcms-api
|
|
3
|
-
Version:
|
|
4
|
-
Summary: Python API for Kiwi
|
|
3
|
+
Version: 17.3
|
|
4
|
+
Summary: Python API for Kiwi TCMS
|
|
5
5
|
Home-page: https://github.com/kiwitcms/tcms-api
|
|
6
6
|
Maintainer: Kiwi TCMS
|
|
7
7
|
Maintainer-email: info@kiwitcms.org
|
|
@@ -10,33 +10,23 @@ Classifier: Development Status :: 5 - Production/Stable
|
|
|
10
10
|
Classifier: Environment :: Console
|
|
11
11
|
Classifier: Intended Audience :: Developers
|
|
12
12
|
Classifier: Intended Audience :: System Administrators
|
|
13
|
-
Classifier: License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)
|
|
14
13
|
Classifier: Operating System :: POSIX
|
|
15
14
|
Classifier: Programming Language :: Python
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
16
|
Classifier: Topic :: Software Development
|
|
20
17
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
18
|
Classifier: Topic :: Software Development :: Quality Assurance
|
|
22
19
|
Classifier: Topic :: Software Development :: Testing
|
|
23
|
-
Requires-Python: >=3.
|
|
20
|
+
Requires-Python: >=3.9
|
|
24
21
|
Description-Content-Type: text/x-rst
|
|
25
22
|
License-File: LICENSE
|
|
26
|
-
Requires-Dist: requests
|
|
27
|
-
Requires-Dist: setuptools
|
|
28
|
-
Provides-Extra: gssapi
|
|
29
|
-
Requires-Dist: gssapi; extra == "gssapi"
|
|
30
23
|
Dynamic: classifier
|
|
31
24
|
Dynamic: description
|
|
32
25
|
Dynamic: description-content-type
|
|
33
26
|
Dynamic: home-page
|
|
34
|
-
Dynamic: license
|
|
35
27
|
Dynamic: license-file
|
|
36
28
|
Dynamic: maintainer
|
|
37
29
|
Dynamic: maintainer-email
|
|
38
|
-
Dynamic: provides-extra
|
|
39
|
-
Dynamic: requires-dist
|
|
40
30
|
Dynamic: requires-python
|
|
41
31
|
Dynamic: summary
|
|
42
32
|
|
|
@@ -57,14 +47,6 @@ Python API for Kiwi TCMS
|
|
|
57
47
|
:target: https://codecov.io/gh/kiwitcms/tcms-api
|
|
58
48
|
:alt: Code coverage
|
|
59
49
|
|
|
60
|
-
.. image:: https://tidelift.com/badges/package/pypi/tcms-api
|
|
61
|
-
:target: https://tidelift.com/subscription/pkg/pypi-tcms-api?utm_source=pypi-tcms-api&utm_medium=github&utm_campaign=readme
|
|
62
|
-
:alt: Tidelift
|
|
63
|
-
|
|
64
|
-
.. image:: https://opencollective.com/kiwitcms/tiers/sponsor/badge.svg?label=sponsors&color=brightgreen
|
|
65
|
-
:target: https://opencollective.com/kiwitcms#contributors
|
|
66
|
-
:alt: Become a sponsor
|
|
67
|
-
|
|
68
50
|
.. image:: https://img.shields.io/twitter/follow/KiwiTCMS.svg
|
|
69
51
|
:target: https://twitter.com/KiwiTCMS
|
|
70
52
|
:alt: Kiwi TCMS on Twitter
|
|
@@ -82,6 +64,20 @@ https://tcms-api.readthedocs.io/en/latest/modules/tcms_api.html
|
|
|
82
64
|
CHANGELOG
|
|
83
65
|
---------
|
|
84
66
|
|
|
67
|
+
v17.3 (03 Dec 2026)
|
|
68
|
+
~~~~~~~~~~~~~~~~~~~
|
|
69
|
+
|
|
70
|
+
- Allow additional HTTP headers (Josh Lubawy)
|
|
71
|
+
- Add reference in CI yaml how to override CA trust stores. Closes
|
|
72
|
+
`Issue #56 <https://github.com/kiwitcms/tcms-api/issues/56>`_
|
|
73
|
+
- Add ``TestCase`` decorator for stable test case identification. Closes
|
|
74
|
+
`Issue #126 <https://github.com/kiwitcms/tcms-api/issues/126>`_
|
|
75
|
+
- Add support for bearer token authentication - specify ``token`` field in
|
|
76
|
+
``tcms.conf`` or pass via ``extra_headers`` to ``TCMS()`` class
|
|
77
|
+
- Remove Kerberos integration - removed in Kiwi TCMS Enterprise v16.5-mt
|
|
78
|
+
- Require Python 3.9 or later
|
|
79
|
+
|
|
80
|
+
|
|
85
81
|
v15.0 (22 Sep 2025)
|
|
86
82
|
~~~~~~~~~~~~~~~~~~~
|
|
87
83
|
|
|
@@ -237,7 +233,7 @@ v9.0 (12 January 2021)
|
|
|
237
233
|
- Compatible with Kiwi TCMS v9.0 or later
|
|
238
234
|
- Method ``Backend.build_id()`` doesn't receive ``product_id`` as firsts
|
|
239
235
|
parameter anymore! Related to Kiwi TCMS
|
|
240
|
-
`Issue #246 <https://github.com/kiwitcms/
|
|
236
|
+
`Issue #246 <https://github.com/kiwitcms/kiwitcms/issues/246>`_
|
|
241
237
|
|
|
242
238
|
|
|
243
239
|
v8.6.0 (28 October 2020)
|
|
@@ -15,14 +15,6 @@ Python API for Kiwi TCMS
|
|
|
15
15
|
:target: https://codecov.io/gh/kiwitcms/tcms-api
|
|
16
16
|
:alt: Code coverage
|
|
17
17
|
|
|
18
|
-
.. image:: https://tidelift.com/badges/package/pypi/tcms-api
|
|
19
|
-
:target: https://tidelift.com/subscription/pkg/pypi-tcms-api?utm_source=pypi-tcms-api&utm_medium=github&utm_campaign=readme
|
|
20
|
-
:alt: Tidelift
|
|
21
|
-
|
|
22
|
-
.. image:: https://opencollective.com/kiwitcms/tiers/sponsor/badge.svg?label=sponsors&color=brightgreen
|
|
23
|
-
:target: https://opencollective.com/kiwitcms#contributors
|
|
24
|
-
:alt: Become a sponsor
|
|
25
|
-
|
|
26
18
|
.. image:: https://img.shields.io/twitter/follow/KiwiTCMS.svg
|
|
27
19
|
:target: https://twitter.com/KiwiTCMS
|
|
28
20
|
:alt: Kiwi TCMS on Twitter
|
|
@@ -40,6 +32,20 @@ https://tcms-api.readthedocs.io/en/latest/modules/tcms_api.html
|
|
|
40
32
|
CHANGELOG
|
|
41
33
|
---------
|
|
42
34
|
|
|
35
|
+
v17.3 (03 Dec 2026)
|
|
36
|
+
~~~~~~~~~~~~~~~~~~~
|
|
37
|
+
|
|
38
|
+
- Allow additional HTTP headers (Josh Lubawy)
|
|
39
|
+
- Add reference in CI yaml how to override CA trust stores. Closes
|
|
40
|
+
`Issue #56 <https://github.com/kiwitcms/tcms-api/issues/56>`_
|
|
41
|
+
- Add ``TestCase`` decorator for stable test case identification. Closes
|
|
42
|
+
`Issue #126 <https://github.com/kiwitcms/tcms-api/issues/126>`_
|
|
43
|
+
- Add support for bearer token authentication - specify ``token`` field in
|
|
44
|
+
``tcms.conf`` or pass via ``extra_headers`` to ``TCMS()`` class
|
|
45
|
+
- Remove Kerberos integration - removed in Kiwi TCMS Enterprise v16.5-mt
|
|
46
|
+
- Require Python 3.9 or later
|
|
47
|
+
|
|
48
|
+
|
|
43
49
|
v15.0 (22 Sep 2025)
|
|
44
50
|
~~~~~~~~~~~~~~~~~~~
|
|
45
51
|
|
|
@@ -195,7 +201,7 @@ v9.0 (12 January 2021)
|
|
|
195
201
|
- Compatible with Kiwi TCMS v9.0 or later
|
|
196
202
|
- Method ``Backend.build_id()`` doesn't receive ``product_id`` as firsts
|
|
197
203
|
parameter anymore! Related to Kiwi TCMS
|
|
198
|
-
`Issue #246 <https://github.com/kiwitcms/
|
|
204
|
+
`Issue #246 <https://github.com/kiwitcms/kiwitcms/issues/246>`_
|
|
199
205
|
|
|
200
206
|
|
|
201
207
|
v8.6.0 (28 October 2020)
|
|
File without changes
|
|
@@ -35,30 +35,22 @@ setup(
|
|
|
35
35
|
name="tcms-api",
|
|
36
36
|
version=get_version(),
|
|
37
37
|
packages=["tcms_api"],
|
|
38
|
-
description="Python API for Kiwi",
|
|
38
|
+
description="Python API for Kiwi TCMS",
|
|
39
39
|
long_description=LONG_DESCRIPTION,
|
|
40
40
|
long_description_content_type="text/x-rst",
|
|
41
41
|
maintainer="Kiwi TCMS",
|
|
42
42
|
maintainer_email="info@kiwitcms.org",
|
|
43
|
-
license="LGPLv2+",
|
|
44
43
|
url="https://github.com/kiwitcms/tcms-api",
|
|
45
|
-
python_requires=">=3.
|
|
44
|
+
python_requires=">=3.9",
|
|
46
45
|
install_requires=get_install_requires("requirements.txt"),
|
|
47
|
-
extras_require={
|
|
48
|
-
"gssapi": ["gssapi"],
|
|
49
|
-
},
|
|
50
46
|
classifiers=[
|
|
51
47
|
"Development Status :: 5 - Production/Stable",
|
|
52
48
|
"Environment :: Console",
|
|
53
49
|
"Intended Audience :: Developers",
|
|
54
50
|
"Intended Audience :: System Administrators",
|
|
55
|
-
"License :: OSI Approved :: GNU Lesser General Public License v2"
|
|
56
|
-
+ " or later (LGPLv2+)",
|
|
57
51
|
"Operating System :: POSIX",
|
|
58
52
|
"Programming Language :: Python",
|
|
59
|
-
"Programming Language :: Python :: 3.
|
|
60
|
-
"Programming Language :: Python :: 3.9",
|
|
61
|
-
"Programming Language :: Python :: 3.11",
|
|
53
|
+
"Programming Language :: Python :: 3.14",
|
|
62
54
|
"Topic :: Software Development",
|
|
63
55
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
64
56
|
"Topic :: Software Development :: Quality Assurance",
|
|
@@ -32,22 +32,6 @@ Installation::
|
|
|
32
32
|
pip install tcms-api
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
If you want to use Kerberos then::
|
|
36
|
-
|
|
37
|
-
pip install tcms-api[gssapi]
|
|
38
|
-
|
|
39
|
-
**WARNING:** on Windows you need to install MIT Kerberos and make sure
|
|
40
|
-
``C:\\Program Files\\MIT\\Kerberos\\bin`` is included in ``%PATH%`` -
|
|
41
|
-
this is usually the case when you install and restart! It must be
|
|
42
|
-
a 64bit installation, see
|
|
43
|
-
`MIT Kerberos for Windows 4.1 <https://web.mit.edu/kerberos/dist/index.html#kfw-4.1>`_
|
|
44
|
-
|
|
45
|
-
**WARNING:** on Linux you will need gcc, Python and kerberos devel packages to
|
|
46
|
-
build ``gssapi`` because it doesn't provide binary packages via PyPI. Try
|
|
47
|
-
``dnf install gcc krb5-devel python3-devel`` (Red Hat/Fedora) or
|
|
48
|
-
``apt-get install gcc libkrb5-dev libpython3-dev`` (Debian/Ubuntu).
|
|
49
|
-
|
|
50
|
-
|
|
51
35
|
Minimal config file ``~/.tcms.conf``::
|
|
52
36
|
|
|
53
37
|
[tcms]
|
|
@@ -55,13 +39,15 @@ Minimal config file ``~/.tcms.conf``::
|
|
|
55
39
|
username = your-username
|
|
56
40
|
password = your-password
|
|
57
41
|
|
|
58
|
-
|
|
59
|
-
and password! Also make sure that your ``/etc/krb5.conf`` contains::
|
|
42
|
+
To authenticate with an OAuth2 bearer token instead of username/password::
|
|
60
43
|
|
|
61
|
-
[
|
|
62
|
-
|
|
44
|
+
[tcms]
|
|
45
|
+
url = https://tcms.server/xml-rpc/
|
|
46
|
+
token = your-access-token
|
|
63
47
|
|
|
64
|
-
|
|
48
|
+
Token authentication requires HTTPS. When both ``token`` and ``username``/``password``
|
|
49
|
+
are configured, the token takes precedence. An explicit ``Authorization`` header
|
|
50
|
+
passed via ``extra_headers`` takes precedence over a configured ``token``.
|
|
65
51
|
|
|
66
52
|
|
|
67
53
|
.. important::
|
|
@@ -95,6 +81,13 @@ arguments when initializing the TCMS() class::
|
|
|
95
81
|
|
|
96
82
|
TCMS("https://kiwitcms.example.com/xml-rpc/", "api-bot", "keep-me-secret").exec
|
|
97
83
|
|
|
84
|
+
Tokens can also be passed as an HTTP header, without username/password::
|
|
85
|
+
|
|
86
|
+
TCMS(
|
|
87
|
+
"https://kiwitcms.example.com/xml-rpc/",
|
|
88
|
+
extra_headers={"Authorization": "Bearer <token>"},
|
|
89
|
+
).exec
|
|
90
|
+
|
|
98
91
|
|
|
99
92
|
.. important::
|
|
100
93
|
|
|
@@ -106,23 +99,25 @@ arguments when initializing the TCMS() class::
|
|
|
106
99
|
to open a pull request with your own examples!
|
|
107
100
|
|
|
108
101
|
"""
|
|
102
|
+
|
|
109
103
|
import os
|
|
110
104
|
from configparser import ConfigParser
|
|
111
105
|
from datetime import datetime, timedelta
|
|
106
|
+
from typing import Optional
|
|
112
107
|
|
|
113
|
-
|
|
114
|
-
from distutils.util import strtobool # pylint: disable=deprecated-module
|
|
115
|
-
except ModuleNotFoundError:
|
|
116
|
-
from setuptools.dist import strtobool
|
|
117
|
-
|
|
118
|
-
from tcms_api.xmlrpc import TCMSXmlrpc, TCMSKerbXmlrpc
|
|
108
|
+
from tcms_api.xmlrpc import TCMSXmlrpc
|
|
119
109
|
|
|
120
110
|
|
|
121
111
|
class _ConnectionProxy:
|
|
122
|
-
def __init__(
|
|
112
|
+
def __init__(
|
|
113
|
+
self,
|
|
114
|
+
config,
|
|
115
|
+
extra_headers: Optional[dict[str, str]] = None,
|
|
116
|
+
):
|
|
123
117
|
self.__connected_since = datetime(2024, 1, 1, 0, 0)
|
|
124
118
|
self.__connection = None
|
|
125
119
|
self.__config = config
|
|
120
|
+
self.__extra_headers = extra_headers or {}
|
|
126
121
|
|
|
127
122
|
@staticmethod
|
|
128
123
|
def server_url(config):
|
|
@@ -138,6 +133,8 @@ class _ConnectionProxy:
|
|
|
138
133
|
return config["tcms"]["url"].replace("json-rpc", "xml-rpc")
|
|
139
134
|
|
|
140
135
|
def create_connection(self):
|
|
136
|
+
path = None
|
|
137
|
+
|
|
141
138
|
# try authentication credentials from Python arguments first
|
|
142
139
|
if self.__config["tcms"]["url"]:
|
|
143
140
|
config = self.__config
|
|
@@ -157,22 +154,38 @@ class _ConnectionProxy:
|
|
|
157
154
|
config = ConfigParser()
|
|
158
155
|
config.read(path)
|
|
159
156
|
|
|
160
|
-
rpc_implementor = None
|
|
161
157
|
server_url = self.server_url(config)
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
158
|
+
|
|
159
|
+
token = config["tcms"].get("token")
|
|
160
|
+
extra_headers = dict(self.__extra_headers)
|
|
161
|
+
has_authorization = any(
|
|
162
|
+
header.lower() == "authorization" for header in extra_headers
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
# use a configured token only when no Authorization header was passed
|
|
166
|
+
if token and not has_authorization:
|
|
167
|
+
extra_headers["Authorization"] = f"Bearer {token}"
|
|
168
|
+
has_authorization = True
|
|
169
|
+
|
|
170
|
+
if has_authorization:
|
|
171
|
+
username = None
|
|
172
|
+
password = None
|
|
165
173
|
else:
|
|
166
174
|
try:
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
server_url,
|
|
172
|
-
)
|
|
175
|
+
username = config["tcms"]["username"]
|
|
176
|
+
password = config["tcms"]["password"]
|
|
177
|
+
if not (username and password):
|
|
178
|
+
raise KeyError("username/password")
|
|
173
179
|
except KeyError as err:
|
|
174
180
|
raise RuntimeError(f"username/password required in '{path}'") from err
|
|
175
181
|
|
|
182
|
+
rpc_implementor = TCMSXmlrpc(
|
|
183
|
+
username,
|
|
184
|
+
password,
|
|
185
|
+
server_url,
|
|
186
|
+
extra_headers=extra_headers,
|
|
187
|
+
)
|
|
188
|
+
|
|
176
189
|
self.__connected_since = datetime.now()
|
|
177
190
|
return rpc_implementor.server
|
|
178
191
|
|
|
@@ -206,7 +219,13 @@ class TCMS: # pylint: disable=too-few-public-methods
|
|
|
206
219
|
parses user configuration using a utilities class!
|
|
207
220
|
"""
|
|
208
221
|
|
|
209
|
-
def __init__(
|
|
222
|
+
def __init__(
|
|
223
|
+
self,
|
|
224
|
+
url=None,
|
|
225
|
+
username=None,
|
|
226
|
+
password=None,
|
|
227
|
+
extra_headers: Optional[dict[str, str]] = None,
|
|
228
|
+
):
|
|
210
229
|
self.config = {
|
|
211
230
|
"tcms": {
|
|
212
231
|
"url": url,
|
|
@@ -215,6 +234,8 @@ class TCMS: # pylint: disable=too-few-public-methods
|
|
|
215
234
|
}
|
|
216
235
|
}
|
|
217
236
|
|
|
237
|
+
self.extra_headers = extra_headers or {}
|
|
238
|
+
|
|
218
239
|
@property
|
|
219
240
|
def exec(self):
|
|
220
241
|
"""
|
|
@@ -230,4 +251,7 @@ class TCMS: # pylint: disable=too-few-public-methods
|
|
|
230
251
|
Starting with tcms-api v12.9.1 this property is automatically refreshed
|
|
231
252
|
every 4 minutes to avoid SSL connection timeout errors!
|
|
232
253
|
"""
|
|
233
|
-
return _ConnectionProxy(
|
|
254
|
+
return _ConnectionProxy(
|
|
255
|
+
config=self.config,
|
|
256
|
+
extra_headers=self.extra_headers,
|
|
257
|
+
)
|
|
@@ -9,6 +9,55 @@ from functools import lru_cache as cache
|
|
|
9
9
|
from . import TCMS
|
|
10
10
|
from .version import __version__
|
|
11
11
|
|
|
12
|
+
_TEST_CASE_FIELDS_ATTRIBUTE = "__kiwitcms_TestCase_fields__"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class TestCase: # pylint: disable=too-few-public-methods
|
|
16
|
+
"""
|
|
17
|
+
Decorator which attaches ``tcms.testcases.models.TestCase`` model
|
|
18
|
+
fields to a test function. Test suite authors can use it to tell
|
|
19
|
+
Python test runner plugins which test case a test function belongs
|
|
20
|
+
to::
|
|
21
|
+
|
|
22
|
+
from tcms_api.plugin_helpers import TestCase
|
|
23
|
+
|
|
24
|
+
@TestCase(id=45)
|
|
25
|
+
def test_coupon_guest():
|
|
26
|
+
...
|
|
27
|
+
|
|
28
|
+
@TestCase(summary="Guest can apply a coupon at checkout")
|
|
29
|
+
def test_coupon_guest_v2():
|
|
30
|
+
...
|
|
31
|
+
|
|
32
|
+
The keyword arguments are passed to ``TestCase.create()`` verbatim.
|
|
33
|
+
|
|
34
|
+
.. versionadded:: 17.3
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(self, **fields):
|
|
38
|
+
self.fields = fields
|
|
39
|
+
|
|
40
|
+
def __call__(self, test_case):
|
|
41
|
+
setattr(test_case, _TEST_CASE_FIELDS_ATTRIBUTE, self.fields)
|
|
42
|
+
return test_case
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def get_test_case_fields(test_case):
|
|
46
|
+
"""
|
|
47
|
+
Return the ``tcms.testcases.models.TestCase`` model fields attached
|
|
48
|
+
by the :class:`TestCase` decorator.
|
|
49
|
+
|
|
50
|
+
:param test_case: decorated callable, dictionary of fields or ``None``
|
|
51
|
+
:type test_case: callable or dict or None
|
|
52
|
+
:return: field values or an empty dictionary
|
|
53
|
+
:rtype: dict
|
|
54
|
+
"""
|
|
55
|
+
if test_case is None:
|
|
56
|
+
return {}
|
|
57
|
+
if isinstance(test_case, dict):
|
|
58
|
+
return test_case
|
|
59
|
+
return getattr(test_case, _TEST_CASE_FIELDS_ATTRIBUTE, {}) or {}
|
|
60
|
+
|
|
12
61
|
|
|
13
62
|
# pylint: disable=too-many-instance-attributes, too-many-public-methods
|
|
14
63
|
class Backend:
|
|
@@ -496,31 +545,50 @@ class Backend:
|
|
|
496
545
|
},
|
|
497
546
|
)
|
|
498
547
|
|
|
499
|
-
def test_case_get_or_create(self, summary):
|
|
548
|
+
def test_case_get_or_create(self, summary=None, test_case_data=None):
|
|
500
549
|
"""
|
|
501
|
-
Search for a TestCase
|
|
502
|
-
|
|
550
|
+
Search for a TestCase and return it, creating a new one when it
|
|
551
|
+
doesn't exist in the database!
|
|
503
552
|
|
|
504
553
|
.. important::
|
|
505
554
|
|
|
506
555
|
Test runner plugins **must** call this method!
|
|
507
556
|
|
|
557
|
+
The optional ``test_case_data`` argument may be a callable decorated
|
|
558
|
+
with :class:`TestCase` or a dictionary of TestCase model fields.
|
|
559
|
+
|
|
508
560
|
:param summary: A TestCase summary
|
|
509
561
|
:type summary: str
|
|
562
|
+
:param test_case_data: Decorated callable or TestCase model fields
|
|
563
|
+
:type test_case_data: callable or dict
|
|
510
564
|
:return: Serialized ``tcms.testcase.models.TestCase`` and boolean
|
|
511
565
|
flag to indicate if the TestCase has just been created!
|
|
512
566
|
:rtype: (dict, bool)
|
|
513
567
|
"""
|
|
568
|
+
fields = dict(get_test_case_fields(test_case_data))
|
|
569
|
+
|
|
570
|
+
# a summary supplied by the decorator is authoritative
|
|
571
|
+
summary = fields.get("summary", summary)
|
|
514
572
|
summary = summary[:255]
|
|
515
573
|
created = False
|
|
516
|
-
|
|
517
|
-
|
|
574
|
+
|
|
575
|
+
# anything inside the decorator is an explicit decision by the
|
|
576
|
+
# user and is the canonical identifier; fall back to the automatic
|
|
577
|
+
# summary + product lookup only when the decorator has no fields
|
|
578
|
+
query = dict(fields)
|
|
579
|
+
query.pop("category__product", None)
|
|
580
|
+
if not query:
|
|
581
|
+
query = {
|
|
518
582
|
"summary": summary,
|
|
519
583
|
"category__product": self.product_id,
|
|
520
584
|
}
|
|
521
|
-
)
|
|
522
585
|
|
|
586
|
+
test_case = self.rpc.TestCase.filter(query)
|
|
523
587
|
if not test_case:
|
|
588
|
+
# `id` and `pk` are not model fields accepted by TestCase.create()
|
|
589
|
+
fields.pop("id", None)
|
|
590
|
+
fields.pop("pk", None)
|
|
591
|
+
|
|
524
592
|
test_case = [
|
|
525
593
|
self.rpc.TestCase.create(
|
|
526
594
|
{
|
|
@@ -530,6 +598,7 @@ class Backend:
|
|
|
530
598
|
"case_status": self.confirmed_id,
|
|
531
599
|
"notes": self.created_by_text,
|
|
532
600
|
"is_automated": True,
|
|
601
|
+
**fields,
|
|
533
602
|
}
|
|
534
603
|
)
|
|
535
604
|
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "17.3"
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# pylint: disable=protected-access,too-few-public-methods
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from typing import Optional
|
|
6
|
+
from xmlrpc.client import _Method, SafeTransport, Transport, ServerProxy
|
|
7
|
+
|
|
8
|
+
from tcms_api.version import __version__
|
|
9
|
+
|
|
10
|
+
VERBOSE = 0
|
|
11
|
+
_PYTHON_VERSION = sys.version.replace("\n", "")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TCMSProxy(ServerProxy):
|
|
15
|
+
def __request(self, methodname, params):
|
|
16
|
+
self._ServerProxy__transport._extra_headers = [
|
|
17
|
+
("Referer", f"{methodname}@{self._ServerProxy__host}")
|
|
18
|
+
]
|
|
19
|
+
return self._ServerProxy__request(methodname, params)
|
|
20
|
+
|
|
21
|
+
def __getattr__(self, name):
|
|
22
|
+
return _Method(self.__request, name)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class CookieTransport(Transport):
|
|
26
|
+
"""A subclass of xmlrpc.client.Transport that supports cookies."""
|
|
27
|
+
|
|
28
|
+
scheme = "http"
|
|
29
|
+
user_agent = f"tcms-api/{__version__}/Python {_PYTHON_VERSION}"
|
|
30
|
+
|
|
31
|
+
def __init__(self, *args, **kwargs):
|
|
32
|
+
super().__init__(*args, **kwargs)
|
|
33
|
+
self._cookies = []
|
|
34
|
+
|
|
35
|
+
def send_headers(self, connection, headers):
|
|
36
|
+
if self._cookies:
|
|
37
|
+
connection.putheader("Cookie", "; ".join(self._cookies))
|
|
38
|
+
super().send_headers(connection, headers)
|
|
39
|
+
|
|
40
|
+
def parse_response(self, response):
|
|
41
|
+
for header in response.msg.get_all("Set-Cookie", []):
|
|
42
|
+
cookie = header.split(";", 1)[0]
|
|
43
|
+
self._cookies.append(cookie)
|
|
44
|
+
return super().parse_response(response)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class SafeCookieTransport(SafeTransport, CookieTransport):
|
|
48
|
+
"""SafeTransport subclass that supports cookies."""
|
|
49
|
+
|
|
50
|
+
scheme = "https"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class TCMSXmlrpc:
|
|
54
|
+
"""
|
|
55
|
+
XML-RPC client for username/password or bearer token authentication.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
session_cookie_name = "sessionid"
|
|
59
|
+
transport = None
|
|
60
|
+
|
|
61
|
+
def __init__(
|
|
62
|
+
self,
|
|
63
|
+
username,
|
|
64
|
+
password,
|
|
65
|
+
url,
|
|
66
|
+
extra_headers: Optional[dict[str, str]] = None,
|
|
67
|
+
):
|
|
68
|
+
has_authorization = any(
|
|
69
|
+
header.lower() == "authorization" for header in (extra_headers or {})
|
|
70
|
+
)
|
|
71
|
+
headers = list((extra_headers or {}).items())
|
|
72
|
+
|
|
73
|
+
if has_authorization and not url.startswith("https://"):
|
|
74
|
+
raise RuntimeError(
|
|
75
|
+
f"https:// required for token authentication. URL provided: {url}"
|
|
76
|
+
)
|
|
77
|
+
if self.transport is None:
|
|
78
|
+
if url.startswith("https://"):
|
|
79
|
+
self.transport = SafeCookieTransport(headers=headers)
|
|
80
|
+
elif url.startswith("http://"):
|
|
81
|
+
self.transport = CookieTransport(headers=headers)
|
|
82
|
+
else:
|
|
83
|
+
raise RuntimeError("Unrecognized URL scheme")
|
|
84
|
+
|
|
85
|
+
self.server = TCMSProxy(
|
|
86
|
+
url, transport=self.transport, verbose=VERBOSE, allow_none=1
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
self.username = username
|
|
90
|
+
self.password = password
|
|
91
|
+
self.url = url
|
|
92
|
+
|
|
93
|
+
if not has_authorization:
|
|
94
|
+
self.login()
|
|
95
|
+
|
|
96
|
+
def login(self):
|
|
97
|
+
"""
|
|
98
|
+
Login in the web app to save a session cookie in the cookie jar!
|
|
99
|
+
"""
|
|
100
|
+
self.server.Auth.login(self.username, self.password)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tcms-api
|
|
3
|
-
Version:
|
|
4
|
-
Summary: Python API for Kiwi
|
|
3
|
+
Version: 17.3
|
|
4
|
+
Summary: Python API for Kiwi TCMS
|
|
5
5
|
Home-page: https://github.com/kiwitcms/tcms-api
|
|
6
6
|
Maintainer: Kiwi TCMS
|
|
7
7
|
Maintainer-email: info@kiwitcms.org
|
|
@@ -10,33 +10,23 @@ Classifier: Development Status :: 5 - Production/Stable
|
|
|
10
10
|
Classifier: Environment :: Console
|
|
11
11
|
Classifier: Intended Audience :: Developers
|
|
12
12
|
Classifier: Intended Audience :: System Administrators
|
|
13
|
-
Classifier: License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)
|
|
14
13
|
Classifier: Operating System :: POSIX
|
|
15
14
|
Classifier: Programming Language :: Python
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
16
|
Classifier: Topic :: Software Development
|
|
20
17
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
18
|
Classifier: Topic :: Software Development :: Quality Assurance
|
|
22
19
|
Classifier: Topic :: Software Development :: Testing
|
|
23
|
-
Requires-Python: >=3.
|
|
20
|
+
Requires-Python: >=3.9
|
|
24
21
|
Description-Content-Type: text/x-rst
|
|
25
22
|
License-File: LICENSE
|
|
26
|
-
Requires-Dist: requests
|
|
27
|
-
Requires-Dist: setuptools
|
|
28
|
-
Provides-Extra: gssapi
|
|
29
|
-
Requires-Dist: gssapi; extra == "gssapi"
|
|
30
23
|
Dynamic: classifier
|
|
31
24
|
Dynamic: description
|
|
32
25
|
Dynamic: description-content-type
|
|
33
26
|
Dynamic: home-page
|
|
34
|
-
Dynamic: license
|
|
35
27
|
Dynamic: license-file
|
|
36
28
|
Dynamic: maintainer
|
|
37
29
|
Dynamic: maintainer-email
|
|
38
|
-
Dynamic: provides-extra
|
|
39
|
-
Dynamic: requires-dist
|
|
40
30
|
Dynamic: requires-python
|
|
41
31
|
Dynamic: summary
|
|
42
32
|
|
|
@@ -57,14 +47,6 @@ Python API for Kiwi TCMS
|
|
|
57
47
|
:target: https://codecov.io/gh/kiwitcms/tcms-api
|
|
58
48
|
:alt: Code coverage
|
|
59
49
|
|
|
60
|
-
.. image:: https://tidelift.com/badges/package/pypi/tcms-api
|
|
61
|
-
:target: https://tidelift.com/subscription/pkg/pypi-tcms-api?utm_source=pypi-tcms-api&utm_medium=github&utm_campaign=readme
|
|
62
|
-
:alt: Tidelift
|
|
63
|
-
|
|
64
|
-
.. image:: https://opencollective.com/kiwitcms/tiers/sponsor/badge.svg?label=sponsors&color=brightgreen
|
|
65
|
-
:target: https://opencollective.com/kiwitcms#contributors
|
|
66
|
-
:alt: Become a sponsor
|
|
67
|
-
|
|
68
50
|
.. image:: https://img.shields.io/twitter/follow/KiwiTCMS.svg
|
|
69
51
|
:target: https://twitter.com/KiwiTCMS
|
|
70
52
|
:alt: Kiwi TCMS on Twitter
|
|
@@ -82,6 +64,20 @@ https://tcms-api.readthedocs.io/en/latest/modules/tcms_api.html
|
|
|
82
64
|
CHANGELOG
|
|
83
65
|
---------
|
|
84
66
|
|
|
67
|
+
v17.3 (03 Dec 2026)
|
|
68
|
+
~~~~~~~~~~~~~~~~~~~
|
|
69
|
+
|
|
70
|
+
- Allow additional HTTP headers (Josh Lubawy)
|
|
71
|
+
- Add reference in CI yaml how to override CA trust stores. Closes
|
|
72
|
+
`Issue #56 <https://github.com/kiwitcms/tcms-api/issues/56>`_
|
|
73
|
+
- Add ``TestCase`` decorator for stable test case identification. Closes
|
|
74
|
+
`Issue #126 <https://github.com/kiwitcms/tcms-api/issues/126>`_
|
|
75
|
+
- Add support for bearer token authentication - specify ``token`` field in
|
|
76
|
+
``tcms.conf`` or pass via ``extra_headers`` to ``TCMS()`` class
|
|
77
|
+
- Remove Kerberos integration - removed in Kiwi TCMS Enterprise v16.5-mt
|
|
78
|
+
- Require Python 3.9 or later
|
|
79
|
+
|
|
80
|
+
|
|
85
81
|
v15.0 (22 Sep 2025)
|
|
86
82
|
~~~~~~~~~~~~~~~~~~~
|
|
87
83
|
|
|
@@ -237,7 +233,7 @@ v9.0 (12 January 2021)
|
|
|
237
233
|
- Compatible with Kiwi TCMS v9.0 or later
|
|
238
234
|
- Method ``Backend.build_id()`` doesn't receive ``product_id`` as firsts
|
|
239
235
|
parameter anymore! Related to Kiwi TCMS
|
|
240
|
-
`Issue #246 <https://github.com/kiwitcms/
|
|
236
|
+
`Issue #246 <https://github.com/kiwitcms/kiwitcms/issues/246>`_
|
|
241
237
|
|
|
242
238
|
|
|
243
239
|
v8.6.0 (28 October 2020)
|
|
@@ -11,7 +11,6 @@ tcms_api/xmlrpc.py
|
|
|
11
11
|
tcms_api.egg-info/PKG-INFO
|
|
12
12
|
tcms_api.egg-info/SOURCES.txt
|
|
13
13
|
tcms_api.egg-info/dependency_links.txt
|
|
14
|
-
tcms_api.egg-info/requires.txt
|
|
15
14
|
tcms_api.egg-info/top_level.txt
|
|
16
15
|
tests/test_api_config.py
|
|
17
16
|
tests/test_build.py
|
|
@@ -21,4 +20,5 @@ tests/test_plantype.py
|
|
|
21
20
|
tests/test_product.py
|
|
22
21
|
tests/test_run.py
|
|
23
22
|
tests/test_status.py
|
|
23
|
+
tests/test_token_auth.py
|
|
24
24
|
tests/test_version.py
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from unittest.mock import MagicMock
|
|
3
|
+
|
|
4
|
+
from tcms_api.plugin_helpers import TestCase as TcmsTestCaseDecorator
|
|
5
|
+
from tcms_api.plugin_helpers import get_test_case_fields
|
|
6
|
+
|
|
7
|
+
from . import PluginTestCase
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class GivenTestCaseExistsInDatabase(PluginTestCase):
|
|
11
|
+
@classmethod
|
|
12
|
+
def setUpClass(cls):
|
|
13
|
+
super().setUpClass()
|
|
14
|
+
cls.backend.product_id = 42
|
|
15
|
+
cls.backend.rpc = MagicMock()
|
|
16
|
+
cls.backend.rpc.TestCase.filter = MagicMock(return_value=[{"case_id": 34}])
|
|
17
|
+
cls.backend.rpc.TestCase.create = MagicMock()
|
|
18
|
+
|
|
19
|
+
def test_when_test_case_get_or_create_then_reuses_it(self):
|
|
20
|
+
test_case, created = self.backend.test_case_get_or_create("Automated test case")
|
|
21
|
+
self.assertEqual(test_case["case_id"], 34)
|
|
22
|
+
self.assertFalse(created)
|
|
23
|
+
self.backend.rpc.TestCase.filter.assert_called_once_with(
|
|
24
|
+
{"summary": "Automated test case", "category__product": 42}
|
|
25
|
+
)
|
|
26
|
+
self.backend.rpc.TestCase.create.assert_not_called()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class GivenTestCaseDoesNotExistInDatabase(PluginTestCase):
|
|
30
|
+
@classmethod
|
|
31
|
+
def setUpClass(cls):
|
|
32
|
+
super().setUpClass()
|
|
33
|
+
cls.backend.rpc = MagicMock()
|
|
34
|
+
cls.backend.rpc.TestCase.filter = MagicMock(return_value=[])
|
|
35
|
+
cls.backend.rpc.TestCase.create = MagicMock(return_value={"case_id": 43})
|
|
36
|
+
cls.backend.product_id = 42
|
|
37
|
+
cls.backend.category_id = 999
|
|
38
|
+
cls.backend.priority_id = 777
|
|
39
|
+
cls.backend.confirmed_id = 666
|
|
40
|
+
|
|
41
|
+
def test_when_test_case_get_or_create_then_creates_it(self):
|
|
42
|
+
test_case, created = self.backend.test_case_get_or_create("Automated test case")
|
|
43
|
+
self.assertEqual(test_case["case_id"], 43)
|
|
44
|
+
self.assertTrue(created)
|
|
45
|
+
self.backend.rpc.TestCase.filter.assert_called_once_with(
|
|
46
|
+
{"summary": "Automated test case", "category__product": 42}
|
|
47
|
+
)
|
|
48
|
+
self.backend.rpc.TestCase.create.assert_called_with(
|
|
49
|
+
{
|
|
50
|
+
"summary": "Automated test case",
|
|
51
|
+
"category": 999,
|
|
52
|
+
"priority": 777,
|
|
53
|
+
"case_status": 666,
|
|
54
|
+
"notes": self.backend.created_by_text,
|
|
55
|
+
"is_automated": True,
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class TestTcmsTestCaseDecorator(unittest.TestCase):
|
|
61
|
+
def test_fields_are_attached_to_callable(self):
|
|
62
|
+
@TcmsTestCaseDecorator(id=45, summary="Guest can apply a coupon at checkout")
|
|
63
|
+
def test_coupon_guest():
|
|
64
|
+
"""This docstring is not used as a summary."""
|
|
65
|
+
|
|
66
|
+
self.assertEqual(
|
|
67
|
+
get_test_case_fields(test_coupon_guest),
|
|
68
|
+
{"id": 45, "summary": "Guest can apply a coupon at checkout"},
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
def test_fields_are_returned_for_dicts_and_empty_for_none(self):
|
|
72
|
+
self.assertEqual(get_test_case_fields({"id": 1}), {"id": 1})
|
|
73
|
+
self.assertEqual(get_test_case_fields(None), {})
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class GivenDecoratedTestCaseExistsInDatabase(PluginTestCase):
|
|
77
|
+
@classmethod
|
|
78
|
+
def setUpClass(cls):
|
|
79
|
+
super().setUpClass()
|
|
80
|
+
cls.backend.product_id = 42
|
|
81
|
+
cls.backend.rpc = MagicMock()
|
|
82
|
+
cls.backend.rpc.TestCase.filter = MagicMock(
|
|
83
|
+
return_value=[{"id": 45, "summary": "test_coupon_guest"}]
|
|
84
|
+
)
|
|
85
|
+
cls.backend.rpc.TestCase.create = MagicMock()
|
|
86
|
+
|
|
87
|
+
def setUp(self):
|
|
88
|
+
self.backend.rpc.reset_mock()
|
|
89
|
+
|
|
90
|
+
def test_when_id_is_specified_then_reuses_case_by_id(self):
|
|
91
|
+
@TcmsTestCaseDecorator(id=45)
|
|
92
|
+
def test_coupon_guest():
|
|
93
|
+
pass
|
|
94
|
+
|
|
95
|
+
test_case, created = self.backend.test_case_get_or_create(
|
|
96
|
+
"test_coupon_guest", test_case_data=test_coupon_guest
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
self.assertEqual(test_case["id"], 45)
|
|
100
|
+
self.assertFalse(created)
|
|
101
|
+
self.backend.rpc.TestCase.filter.assert_called_once_with({"id": 45})
|
|
102
|
+
self.backend.rpc.TestCase.create.assert_not_called()
|
|
103
|
+
|
|
104
|
+
def test_when_decorator_supplies_fields_then_uses_them_in_filter(self):
|
|
105
|
+
@TcmsTestCaseDecorator(id=45, summary="Guest can apply a coupon at checkout")
|
|
106
|
+
def test_renamed_by_a_healer():
|
|
107
|
+
pass
|
|
108
|
+
|
|
109
|
+
test_case, created = self.backend.test_case_get_or_create(
|
|
110
|
+
test_case_data=test_renamed_by_a_healer
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
self.assertEqual(test_case["id"], 45)
|
|
114
|
+
self.assertFalse(created)
|
|
115
|
+
self.backend.rpc.TestCase.filter.assert_called_once_with(
|
|
116
|
+
{"id": 45, "summary": "Guest can apply a coupon at checkout"}
|
|
117
|
+
)
|
|
118
|
+
self.backend.rpc.TestCase.create.assert_not_called()
|
|
119
|
+
|
|
120
|
+
def test_when_decorator_supplies_only_summary_then_uses_it_in_filter(self):
|
|
121
|
+
@TcmsTestCaseDecorator(summary="Guest can apply a coupon at checkout")
|
|
122
|
+
def test_coupon_guest():
|
|
123
|
+
pass
|
|
124
|
+
|
|
125
|
+
test_case, created = self.backend.test_case_get_or_create(
|
|
126
|
+
"test_coupon_guest", test_case_data=test_coupon_guest
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
self.assertEqual(test_case["id"], 45)
|
|
130
|
+
self.assertFalse(created)
|
|
131
|
+
self.backend.rpc.TestCase.filter.assert_called_once_with(
|
|
132
|
+
{"summary": "Guest can apply a coupon at checkout"}
|
|
133
|
+
)
|
|
134
|
+
self.backend.rpc.TestCase.create.assert_not_called()
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class GivenDecoratedTestCaseDoesNotExistInDatabase(PluginTestCase):
|
|
138
|
+
@classmethod
|
|
139
|
+
def setUpClass(cls):
|
|
140
|
+
super().setUpClass()
|
|
141
|
+
cls.backend.product_id = 42
|
|
142
|
+
cls.backend.category_id = 999
|
|
143
|
+
cls.backend.priority_id = 777
|
|
144
|
+
cls.backend.confirmed_id = 666
|
|
145
|
+
cls.backend.rpc = MagicMock()
|
|
146
|
+
cls.backend.rpc.TestCase.filter = MagicMock(return_value=[])
|
|
147
|
+
cls.backend.rpc.TestCase.create = MagicMock(return_value={"id": 43})
|
|
148
|
+
|
|
149
|
+
def test_when_test_case_is_not_found_then_creates_it(self):
|
|
150
|
+
@TcmsTestCaseDecorator(
|
|
151
|
+
id=45, summary="Guest can apply a coupon at checkout", priority=1
|
|
152
|
+
)
|
|
153
|
+
def test_coupon_guest():
|
|
154
|
+
pass
|
|
155
|
+
|
|
156
|
+
test_case, created = self.backend.test_case_get_or_create(
|
|
157
|
+
test_case_data=test_coupon_guest
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
self.assertEqual(test_case["id"], 43)
|
|
161
|
+
self.assertTrue(created)
|
|
162
|
+
self.backend.rpc.TestCase.filter.assert_called_once_with(
|
|
163
|
+
{
|
|
164
|
+
"id": 45,
|
|
165
|
+
"summary": "Guest can apply a coupon at checkout",
|
|
166
|
+
"priority": 1,
|
|
167
|
+
}
|
|
168
|
+
)
|
|
169
|
+
self.backend.rpc.TestCase.create.assert_called_once_with(
|
|
170
|
+
{
|
|
171
|
+
"summary": "Guest can apply a coupon at checkout",
|
|
172
|
+
"category": 999,
|
|
173
|
+
"priority": 1,
|
|
174
|
+
"case_status": 666,
|
|
175
|
+
"notes": self.backend.created_by_text,
|
|
176
|
+
"is_automated": True,
|
|
177
|
+
}
|
|
178
|
+
)
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# pylint: disable=missing-docstring,protected-access
|
|
2
|
+
|
|
3
|
+
import tempfile
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from unittest import TestCase, mock
|
|
6
|
+
|
|
7
|
+
from tcms_api import TCMS
|
|
8
|
+
from tcms_api.xmlrpc import TCMSXmlrpc
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class GivenAuthorizationHeader(TestCase):
|
|
12
|
+
url = "https://tcms.example.com/xml-rpc/"
|
|
13
|
+
headers = {"Authorization": "Bearer secret"}
|
|
14
|
+
|
|
15
|
+
def test_when_authorization_header_then_login_is_not_attempted(self):
|
|
16
|
+
with mock.patch.object(TCMSXmlrpc, "login") as login:
|
|
17
|
+
rpc = TCMSXmlrpc(None, None, self.url, extra_headers=self.headers)
|
|
18
|
+
|
|
19
|
+
login.assert_not_called()
|
|
20
|
+
self.assertIn(("Authorization", "Bearer secret"), rpc.transport._headers)
|
|
21
|
+
|
|
22
|
+
def test_when_no_authorization_header_then_login_is_attempted(self):
|
|
23
|
+
with mock.patch.object(TCMSXmlrpc, "login") as login:
|
|
24
|
+
TCMSXmlrpc("user", "secret", self.url)
|
|
25
|
+
|
|
26
|
+
login.assert_called_once_with()
|
|
27
|
+
|
|
28
|
+
def test_when_authorization_header_then_https_is_required(self):
|
|
29
|
+
with self.assertRaises(RuntimeError):
|
|
30
|
+
TCMSXmlrpc(
|
|
31
|
+
None,
|
|
32
|
+
None,
|
|
33
|
+
"http://tcms.example.com/xml-rpc/",
|
|
34
|
+
extra_headers=self.headers,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class GivenTokenInConfigFile(TestCase):
|
|
39
|
+
url = "https://tcms.example.com/xml-rpc/"
|
|
40
|
+
|
|
41
|
+
@staticmethod
|
|
42
|
+
def call_create_connection(contents, extra_headers=None):
|
|
43
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
44
|
+
config_path = Path(tmpdir) / "tcms.conf"
|
|
45
|
+
config_path.write_text(contents, encoding="utf-8")
|
|
46
|
+
|
|
47
|
+
with mock.patch(
|
|
48
|
+
"tcms_api.os.path.expanduser", return_value=str(config_path)
|
|
49
|
+
):
|
|
50
|
+
return TCMS(extra_headers=extra_headers).exec.create_connection()
|
|
51
|
+
|
|
52
|
+
def test_token_takes_precedence_over_username_and_password(self):
|
|
53
|
+
with mock.patch("tcms_api.TCMSXmlrpc") as xmlrpc:
|
|
54
|
+
self.call_create_connection(
|
|
55
|
+
f"[tcms]\nurl = {self.url}\nusername = user\n"
|
|
56
|
+
f"password = secret\ntoken = token-secret\n"
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
xmlrpc.assert_called_once_with(
|
|
60
|
+
None,
|
|
61
|
+
None,
|
|
62
|
+
self.url,
|
|
63
|
+
extra_headers={"Authorization": "Bearer token-secret"},
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
def test_explicit_authorization_header_takes_precedence_over_token(self):
|
|
67
|
+
headers = {"Authorization": "Bearer explicit"}
|
|
68
|
+
with mock.patch("tcms_api.TCMSXmlrpc") as xmlrpc:
|
|
69
|
+
self.call_create_connection(
|
|
70
|
+
f"[tcms]\nurl = {self.url}\ntoken = token-secret\n",
|
|
71
|
+
extra_headers=headers,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
xmlrpc.assert_called_once_with(
|
|
75
|
+
None,
|
|
76
|
+
None,
|
|
77
|
+
self.url,
|
|
78
|
+
extra_headers=headers,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
def test_username_and_password_config_still_works(self):
|
|
82
|
+
with mock.patch("tcms_api.TCMSXmlrpc") as xmlrpc:
|
|
83
|
+
self.call_create_connection(
|
|
84
|
+
f"[tcms]\nurl = {self.url}\nusername = user\npassword = secret\n"
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
xmlrpc.assert_called_once_with(
|
|
88
|
+
"user",
|
|
89
|
+
"secret",
|
|
90
|
+
self.url,
|
|
91
|
+
extra_headers={},
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
def test_no_username_no_password_no_token_fails(self):
|
|
95
|
+
with self.assertRaises(RuntimeError):
|
|
96
|
+
self.call_create_connection(f"[tcms]\nurl = {self.url}\n")
|
|
97
|
+
|
|
98
|
+
def test_token_requires_https(self):
|
|
99
|
+
with self.assertRaises(RuntimeError):
|
|
100
|
+
self.call_create_connection(
|
|
101
|
+
"[tcms]\nurl = http://tcms.example.com/xml-rpc/\ntoken = secret\n"
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class GivenAuthorizationHeaderInConstructor(TestCase):
|
|
106
|
+
url = "https://tcms.example.com/xml-rpc/"
|
|
107
|
+
headers = {"Authorization": "Bearer secret"}
|
|
108
|
+
|
|
109
|
+
def test_extra_headers_are_forwarded_without_credentials(self):
|
|
110
|
+
with mock.patch("tcms_api.TCMSXmlrpc") as xmlrpc:
|
|
111
|
+
TCMS(self.url, extra_headers=self.headers).exec.create_connection()
|
|
112
|
+
|
|
113
|
+
xmlrpc.assert_called_once_with(
|
|
114
|
+
None,
|
|
115
|
+
None,
|
|
116
|
+
self.url,
|
|
117
|
+
extra_headers=self.headers,
|
|
118
|
+
)
|
tcms_api-15.0/requirements.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "15.0"
|
tcms_api-15.0/tcms_api/xmlrpc.py
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
# pylint: disable=protected-access,too-few-public-methods
|
|
2
|
-
|
|
3
|
-
import sys
|
|
4
|
-
import urllib.parse
|
|
5
|
-
|
|
6
|
-
from base64 import b64encode
|
|
7
|
-
from http import HTTPStatus
|
|
8
|
-
from http.client import HTTPSConnection
|
|
9
|
-
from xmlrpc.client import _Method, SafeTransport, Transport, ServerProxy
|
|
10
|
-
|
|
11
|
-
try:
|
|
12
|
-
import gssapi
|
|
13
|
-
except ImportError:
|
|
14
|
-
gssapi = None
|
|
15
|
-
|
|
16
|
-
import requests
|
|
17
|
-
|
|
18
|
-
from tcms_api.version import __version__
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
VERBOSE = 0
|
|
22
|
-
_PYTHON_VERSION = sys.version.replace("\n", "")
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class TCMSProxy(ServerProxy):
|
|
26
|
-
def __request(self, methodname, params):
|
|
27
|
-
self._ServerProxy__transport._extra_headers = [
|
|
28
|
-
("Referer", f"{methodname}@{self._ServerProxy__host}")
|
|
29
|
-
]
|
|
30
|
-
return self._ServerProxy__request(methodname, params)
|
|
31
|
-
|
|
32
|
-
def __getattr__(self, name):
|
|
33
|
-
return _Method(self.__request, name)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
class CookieTransport(Transport):
|
|
37
|
-
"""A subclass of xmlrpc.client.Transport that supports cookies."""
|
|
38
|
-
|
|
39
|
-
scheme = "http"
|
|
40
|
-
user_agent = f"tcms-api/{__version__}/Python {_PYTHON_VERSION}"
|
|
41
|
-
|
|
42
|
-
def __init__(self, *args, **kwargs):
|
|
43
|
-
super().__init__(*args, **kwargs)
|
|
44
|
-
self._cookies = []
|
|
45
|
-
|
|
46
|
-
def send_headers(self, connection, headers):
|
|
47
|
-
if self._cookies:
|
|
48
|
-
connection.putheader("Cookie", "; ".join(self._cookies))
|
|
49
|
-
super().send_headers(connection, headers)
|
|
50
|
-
|
|
51
|
-
def parse_response(self, response):
|
|
52
|
-
for header in response.msg.get_all("Set-Cookie", []):
|
|
53
|
-
cookie = header.split(";", 1)[0]
|
|
54
|
-
self._cookies.append(cookie)
|
|
55
|
-
return super().parse_response(response)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
class SafeCookieTransport(SafeTransport, CookieTransport):
|
|
59
|
-
"""SafeTransport subclass that supports cookies."""
|
|
60
|
-
|
|
61
|
-
scheme = "https"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
class KerbTransport(SafeCookieTransport):
|
|
65
|
-
"""Handles GSSAPI Negotiation (SPNEGO) authentication."""
|
|
66
|
-
|
|
67
|
-
def get_host_info(self, host):
|
|
68
|
-
host, extra_headers, x509 = Transport.get_host_info(self, host)
|
|
69
|
-
|
|
70
|
-
# Set the remote host principal
|
|
71
|
-
hostinfo = host.split(":")
|
|
72
|
-
service = "HTTP@" + hostinfo[0]
|
|
73
|
-
|
|
74
|
-
service_name = gssapi.Name(service, gssapi.NameType.hostbased_service)
|
|
75
|
-
context = gssapi.SecurityContext(usage="initiate", name=service_name)
|
|
76
|
-
token = context.step()
|
|
77
|
-
token = b64encode(token).decode()
|
|
78
|
-
extra_headers = [("Authorization", f"Negotiate {token}")]
|
|
79
|
-
|
|
80
|
-
return host, extra_headers, x509
|
|
81
|
-
|
|
82
|
-
def make_connection(self, host):
|
|
83
|
-
"""
|
|
84
|
-
Return an individual HTTPS connection for each request.
|
|
85
|
-
|
|
86
|
-
Fix https://bugzilla.redhat.com/show_bug.cgi?id=735937
|
|
87
|
-
"""
|
|
88
|
-
chost, self._extra_headers, x509 = self.get_host_info(host)
|
|
89
|
-
# Kiwi TCMS isn't ready to use HTTP/1.1 persistent connections,
|
|
90
|
-
# so tell server current opened HTTP connection should be closed after
|
|
91
|
-
# request is handled. And there will be a new connection for the next
|
|
92
|
-
# request.
|
|
93
|
-
self._extra_headers.append(("Connection", "close"))
|
|
94
|
-
self._connection = host, HTTPSConnection( # nosec:B309:blacklist
|
|
95
|
-
chost, None, **(x509 or {})
|
|
96
|
-
)
|
|
97
|
-
return self._connection[1]
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def get_hostname(url):
|
|
101
|
-
"""
|
|
102
|
-
Performs the same parsing of the URL as the Transport
|
|
103
|
-
class and returns only the hostname which is used to
|
|
104
|
-
generate the service principal name for Kiwi TCMS and
|
|
105
|
-
the respective Authorize header!
|
|
106
|
-
"""
|
|
107
|
-
result = urllib.parse.urlparse(url)
|
|
108
|
-
return result.netloc
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
class TCMSXmlrpc:
|
|
112
|
-
"""
|
|
113
|
-
XML-RPC client for username/password authentication.
|
|
114
|
-
"""
|
|
115
|
-
|
|
116
|
-
session_cookie_name = "sessionid"
|
|
117
|
-
transport = None
|
|
118
|
-
|
|
119
|
-
def __init__(self, username, password, url):
|
|
120
|
-
if self.transport is None:
|
|
121
|
-
if url.startswith("https://"):
|
|
122
|
-
self.transport = SafeCookieTransport()
|
|
123
|
-
elif url.startswith("http://"):
|
|
124
|
-
self.transport = CookieTransport()
|
|
125
|
-
else:
|
|
126
|
-
raise RuntimeError("Unrecognized URL scheme")
|
|
127
|
-
|
|
128
|
-
self.server = TCMSProxy(
|
|
129
|
-
url, transport=self.transport, verbose=VERBOSE, allow_none=1
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
self.username = username
|
|
133
|
-
self.password = password
|
|
134
|
-
self.url = url
|
|
135
|
-
|
|
136
|
-
self.login()
|
|
137
|
-
|
|
138
|
-
def login(self):
|
|
139
|
-
# note: do not override .login()
|
|
140
|
-
self._do_login()
|
|
141
|
-
|
|
142
|
-
def _do_login(self):
|
|
143
|
-
"""
|
|
144
|
-
Login in the web app to save a session cookie in the cookie jar!
|
|
145
|
-
"""
|
|
146
|
-
self.server.Auth.login(self.username, self.password)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
class TCMSKerbXmlrpc(TCMSXmlrpc):
|
|
150
|
-
"""
|
|
151
|
-
XML-RPC client for server deployed with python-social-auth-kerberos.
|
|
152
|
-
|
|
153
|
-
Should also work for servers deployed with mod_auth_gssapi but
|
|
154
|
-
that is not supported nor guaranteed!
|
|
155
|
-
"""
|
|
156
|
-
|
|
157
|
-
transport = KerbTransport()
|
|
158
|
-
|
|
159
|
-
def __init__(self, username, password, url):
|
|
160
|
-
if not url.startswith("https://"):
|
|
161
|
-
raise RuntimeError(
|
|
162
|
-
f"https:// required for GSSAPI authentication. URL provided: {url}"
|
|
163
|
-
)
|
|
164
|
-
|
|
165
|
-
if gssapi is None:
|
|
166
|
-
raise RuntimeError("gssapi not found! Try pip install tcms-api[gssapi]")
|
|
167
|
-
|
|
168
|
-
super().__init__(username, password, url)
|
|
169
|
-
|
|
170
|
-
def _do_login(self):
|
|
171
|
-
url = self.url.replace("xml-rpc", "login/kerberos")
|
|
172
|
-
hostname = get_hostname(url)
|
|
173
|
-
|
|
174
|
-
_, headers, _ = self.transport.get_host_info(hostname)
|
|
175
|
-
# transport returns list of tuples but requests needs a dictionary
|
|
176
|
-
headers = dict(headers)
|
|
177
|
-
headers["User-Agent"] = self.transport.user_agent
|
|
178
|
-
|
|
179
|
-
# note: by default will follow redirects
|
|
180
|
-
with requests.sessions.Session() as session:
|
|
181
|
-
response = session.get(url, headers=headers)
|
|
182
|
-
if response.status_code != HTTPStatus.OK:
|
|
183
|
-
raise RuntimeError(f"Unexpected HTTP response {response}")
|
|
184
|
-
|
|
185
|
-
self.transport._cookies.append( # pylint: disable=protected-access
|
|
186
|
-
self.session_cookie_name
|
|
187
|
-
+ "="
|
|
188
|
-
+ session.cookies[self.session_cookie_name]
|
|
189
|
-
)
|
tcms_api-15.0/tests/test_case.py
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
from unittest.mock import MagicMock
|
|
2
|
-
|
|
3
|
-
from . import PluginTestCase
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class GivenTestCaseExistsInDatabase(PluginTestCase):
|
|
7
|
-
@classmethod
|
|
8
|
-
def setUpClass(cls):
|
|
9
|
-
super().setUpClass()
|
|
10
|
-
cls.backend.rpc = MagicMock()
|
|
11
|
-
cls.backend.rpc.TestCase.filter = MagicMock(return_value=[{"case_id": 34}])
|
|
12
|
-
cls.backend.rpc.TestCase.create = MagicMock()
|
|
13
|
-
|
|
14
|
-
def test_when_test_case_get_or_create_then_reuses_it(self):
|
|
15
|
-
test_case, created = self.backend.test_case_get_or_create("Automated test case")
|
|
16
|
-
self.assertEqual(test_case["case_id"], 34)
|
|
17
|
-
self.assertFalse(created)
|
|
18
|
-
self.backend.rpc.TestCase.create.assert_not_called()
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class GivenTestCaseDoesNotExistInDatabase(PluginTestCase):
|
|
22
|
-
@classmethod
|
|
23
|
-
def setUpClass(cls):
|
|
24
|
-
super().setUpClass()
|
|
25
|
-
cls.backend.rpc = MagicMock()
|
|
26
|
-
cls.backend.rpc.TestCase.filter = MagicMock(return_value=[])
|
|
27
|
-
cls.backend.rpc.TestCase.create = MagicMock(return_value={"case_id": 43})
|
|
28
|
-
cls.backend.category_id = 999
|
|
29
|
-
cls.backend.priority_id = 777
|
|
30
|
-
cls.backend.confirmed_id = 666
|
|
31
|
-
|
|
32
|
-
def test_when_test_case_get_or_create_then_creates_it(self):
|
|
33
|
-
test_case, created = self.backend.test_case_get_or_create("Automated test case")
|
|
34
|
-
self.assertEqual(test_case["case_id"], 43)
|
|
35
|
-
self.assertTrue(created)
|
|
36
|
-
self.backend.rpc.TestCase.create.assert_called_with(
|
|
37
|
-
{
|
|
38
|
-
"summary": "Automated test case",
|
|
39
|
-
"category": 999,
|
|
40
|
-
"priority": 777,
|
|
41
|
-
"case_status": 666,
|
|
42
|
-
"notes": self.backend.created_by_text,
|
|
43
|
-
"is_automated": True,
|
|
44
|
-
}
|
|
45
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|