tcms-api 12.9__tar.gz → 13.2__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-12.9/tcms_api.egg-info → tcms_api-13.2}/PKG-INFO +19 -1
- {tcms-api-12.9 → tcms_api-13.2}/README.rst +18 -0
- {tcms-api-12.9 → tcms_api-13.2}/tcms_api/__init__.py +96 -40
- tcms_api-13.2/tcms_api/version.py +1 -0
- {tcms-api-12.9 → tcms_api-13.2}/tcms_api/xmlrpc.py +4 -25
- {tcms-api-12.9 → tcms_api-13.2/tcms_api.egg-info}/PKG-INFO +19 -1
- tcms-api-12.9/tcms_api/version.py +0 -1
- {tcms-api-12.9 → tcms_api-13.2}/LICENSE +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/MANIFEST.in +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/requirements.txt +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/setup.cfg +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/setup.py +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/tcms_api/plugin_helpers.py +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/tcms_api.egg-info/SOURCES.txt +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/tcms_api.egg-info/dependency_links.txt +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/tcms_api.egg-info/requires.txt +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/tcms_api.egg-info/top_level.txt +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/tests/test_api_config.py +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/tests/test_build.py +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/tests/test_case.py +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/tests/test_plan.py +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/tests/test_plantype.py +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/tests/test_product.py +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/tests/test_run.py +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/tests/test_status.py +0 -0
- {tcms-api-12.9 → tcms_api-13.2}/tests/test_version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: tcms-api
|
|
3
|
-
Version:
|
|
3
|
+
Version: 13.2
|
|
4
4
|
Summary: Python API for Kiwi
|
|
5
5
|
Home-page: https://github.com/kiwitcms/tcms-api
|
|
6
6
|
Maintainer: Kiwi TCMS
|
|
@@ -69,6 +69,24 @@ https://tcms-api.readthedocs.io/en/latest/modules/tcms_api.html
|
|
|
69
69
|
CHANGELOG
|
|
70
70
|
---------
|
|
71
71
|
|
|
72
|
+
v13.2 (27 Apr 2024)
|
|
73
|
+
~~~~~~~~~~~~~~~~~~~
|
|
74
|
+
|
|
75
|
+
- Respect configuration passed as arguments to the ``TCMS()`` class, for example::
|
|
76
|
+
|
|
77
|
+
TCMS("https://kiwitcms.example.com/xml-rpc/", "api-bot", "keep-me-secret")
|
|
78
|
+
|
|
79
|
+
- Adjust usage examples and documentation for ``.exec()``. Closes
|
|
80
|
+
`Issue #77 <https://github.com/kiwitcms/tcms-api/issues/77>`_
|
|
81
|
+
- Internal changes related to testing and building this package
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
v12.9.1 (13 Jan 2024)
|
|
85
|
+
~~~~~~~~~~~~~~~~~~~~~
|
|
86
|
+
|
|
87
|
+
- Refactor RPC connection refresh using a proxy-class pattern which also
|
|
88
|
+
takes care to call ``.login()`` upon refresh
|
|
89
|
+
|
|
72
90
|
|
|
73
91
|
v12.9 (12 Jan 2024)
|
|
74
92
|
~~~~~~~~~~~~~~~~~~~
|
|
@@ -40,6 +40,24 @@ https://tcms-api.readthedocs.io/en/latest/modules/tcms_api.html
|
|
|
40
40
|
CHANGELOG
|
|
41
41
|
---------
|
|
42
42
|
|
|
43
|
+
v13.2 (27 Apr 2024)
|
|
44
|
+
~~~~~~~~~~~~~~~~~~~
|
|
45
|
+
|
|
46
|
+
- Respect configuration passed as arguments to the ``TCMS()`` class, for example::
|
|
47
|
+
|
|
48
|
+
TCMS("https://kiwitcms.example.com/xml-rpc/", "api-bot", "keep-me-secret")
|
|
49
|
+
|
|
50
|
+
- Adjust usage examples and documentation for ``.exec()``. Closes
|
|
51
|
+
`Issue #77 <https://github.com/kiwitcms/tcms-api/issues/77>`_
|
|
52
|
+
- Internal changes related to testing and building this package
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
v12.9.1 (13 Jan 2024)
|
|
56
|
+
~~~~~~~~~~~~~~~~~~~~~
|
|
57
|
+
|
|
58
|
+
- Refactor RPC connection refresh using a proxy-class pattern which also
|
|
59
|
+
takes care to call ``.login()`` upon refresh
|
|
60
|
+
|
|
43
61
|
|
|
44
62
|
v12.9 (12 Jan 2024)
|
|
45
63
|
~~~~~~~~~~~~~~~~~~~
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# Copyright (c) 2012 Red Hat, Inc. All rights reserved.
|
|
6
6
|
# Author: Petr Splichal <psplicha@redhat.com>
|
|
7
7
|
#
|
|
8
|
-
# Copyright (c) 2018,2020-
|
|
8
|
+
# Copyright (c) 2018,2020-2024 Kiwi TCMS project. All rights reserved.
|
|
9
9
|
# Author: Alexander Todorov <info@kiwitcms.org>
|
|
10
10
|
#
|
|
11
11
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
@@ -84,11 +84,18 @@ Connect to backend::
|
|
|
84
84
|
|
|
85
85
|
from tcms_api import TCMS
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
rpc = TCMS().exec
|
|
88
88
|
|
|
89
|
-
for test_case in
|
|
89
|
+
for test_case in rpc.TestCase.filter({'pk': 46490}):
|
|
90
90
|
print(test_case)
|
|
91
91
|
|
|
92
|
+
|
|
93
|
+
After tcms-api v13.2 you can pass connection configuration directly as
|
|
94
|
+
arguments when initializing the TCMS() class::
|
|
95
|
+
|
|
96
|
+
TCMS("https://kiwitcms.example.com/xml-rpc/", "api-bot", "keep-me-secret").exec
|
|
97
|
+
|
|
98
|
+
|
|
92
99
|
.. important::
|
|
93
100
|
|
|
94
101
|
For a list of available RPC methods see
|
|
@@ -101,35 +108,50 @@ Connect to backend::
|
|
|
101
108
|
"""
|
|
102
109
|
import os
|
|
103
110
|
from configparser import ConfigParser
|
|
111
|
+
from datetime import datetime, timedelta
|
|
104
112
|
from distutils.util import strtobool # pylint: disable=deprecated-module
|
|
105
113
|
|
|
106
114
|
from tcms_api.xmlrpc import TCMSXmlrpc, TCMSKerbXmlrpc
|
|
107
115
|
|
|
108
116
|
|
|
109
|
-
class
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
117
|
+
class _ConnectionProxy:
|
|
118
|
+
def __init__(self, config):
|
|
119
|
+
self.__connected_since = datetime(2024, 1, 1, 0, 0)
|
|
120
|
+
self.__connection = None
|
|
121
|
+
self.__config = config
|
|
114
122
|
|
|
115
|
-
|
|
116
|
-
|
|
123
|
+
@staticmethod
|
|
124
|
+
def server_url(config):
|
|
125
|
+
"""
|
|
126
|
+
Returns the server URL and performs various sanity checks!
|
|
127
|
+
"""
|
|
128
|
+
# Make sure the server URL is set
|
|
129
|
+
try:
|
|
130
|
+
config["tcms"]["url"] is not None
|
|
131
|
+
except (KeyError, AttributeError) as err:
|
|
132
|
+
raise RuntimeError(f"No url found in {config}") from err
|
|
133
|
+
|
|
134
|
+
return config["tcms"]["url"].replace("json-rpc", "xml-rpc")
|
|
135
|
+
|
|
136
|
+
def create_connection(self):
|
|
137
|
+
# try authentication credentials from Python arguments first
|
|
138
|
+
if self.__config["tcms"]["url"]:
|
|
139
|
+
config = self.__config
|
|
140
|
+
else:
|
|
141
|
+
# if not provided then try reading from the filesystem
|
|
142
|
+
path = os.path.expanduser("~/.tcms.conf")
|
|
117
143
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
144
|
+
# Try system settings when the config does not exist in user directory
|
|
145
|
+
if not os.path.exists(path):
|
|
146
|
+
path = "/etc/tcms.conf"
|
|
147
|
+
if not os.path.exists(path):
|
|
148
|
+
path = "c:/tcms.conf"
|
|
122
149
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
self._path = "/etc/tcms.conf"
|
|
126
|
-
if not os.path.exists(self._path):
|
|
127
|
-
self._path = "c:/tcms.conf"
|
|
128
|
-
if not os.path.exists(self._path):
|
|
129
|
-
raise RuntimeError(f"Config file '{self._path}' not found")
|
|
150
|
+
if not os.path.exists(path):
|
|
151
|
+
raise RuntimeError(f"Config file '{path}' not found")
|
|
130
152
|
|
|
131
|
-
|
|
132
|
-
|
|
153
|
+
config = ConfigParser()
|
|
154
|
+
config.read(path)
|
|
133
155
|
|
|
134
156
|
rpc_implementor = None
|
|
135
157
|
server_url = self.server_url(config)
|
|
@@ -145,29 +167,63 @@ class TCMS: # pylint: disable=too-few-public-methods
|
|
|
145
167
|
server_url,
|
|
146
168
|
)
|
|
147
169
|
except KeyError as err:
|
|
148
|
-
raise RuntimeError(
|
|
149
|
-
|
|
150
|
-
|
|
170
|
+
raise RuntimeError(f"username/password required in '{path}'") from err
|
|
171
|
+
|
|
172
|
+
self.__connected_since = datetime.now()
|
|
173
|
+
return rpc_implementor.server
|
|
174
|
+
|
|
175
|
+
def __getattr__(self, name):
|
|
176
|
+
"""
|
|
177
|
+
refresh the connection every 4 minutes to avoid an
|
|
178
|
+
`ssl.SSLEOFError: EOF occurred in violation of protocol` error with Python >= 3.10
|
|
179
|
+
In practice I've discovered that 5 minutes works as well, 6 minutes fails so
|
|
180
|
+
be more cautious and refresh the connection earlier!
|
|
181
|
+
|
|
182
|
+
Side note: originally I thought this is related to calling
|
|
183
|
+
context.set_alpn_protocols(['http/1.1']) inside http/client.py, introduced in
|
|
184
|
+
https://github.com/python/cpython/commit/f97406be4c0a02c1501c7ab8bc8ef3850eddb962
|
|
185
|
+
but that doesn't seem to be the case (or is much harder for me to debug)!
|
|
186
|
+
"""
|
|
187
|
+
|
|
188
|
+
# NOTE: Method only called for attributes which don't exist, iow
|
|
189
|
+
# XML-RPC methods, see
|
|
190
|
+
# https://medium.com/@satishgoda/python-attribute-access-using-getattr-and-getattribute-6401f7425ce6
|
|
191
|
+
if datetime.now() - self.__connected_since > timedelta(minutes=4):
|
|
192
|
+
self.__connection = self.create_connection()
|
|
193
|
+
elif self.__connection is None:
|
|
194
|
+
self.__connection = self.create_connection()
|
|
151
195
|
|
|
152
|
-
|
|
153
|
-
|
|
196
|
+
return self.__connection.__getattr__(name)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
class TCMS: # pylint: disable=too-few-public-methods
|
|
200
|
+
"""
|
|
201
|
+
Takes care of initiating the connection to the TCMS server and
|
|
202
|
+
parses user configuration using a utilities class!
|
|
203
|
+
"""
|
|
204
|
+
|
|
205
|
+
def __init__(self, url=None, username=None, password=None):
|
|
206
|
+
self.config = {
|
|
207
|
+
"tcms": {
|
|
208
|
+
"url": url,
|
|
209
|
+
"username": username,
|
|
210
|
+
"password": password,
|
|
211
|
+
}
|
|
212
|
+
}
|
|
154
213
|
|
|
155
214
|
@property
|
|
156
215
|
def exec(self):
|
|
157
216
|
"""
|
|
158
217
|
Property that returns the underlying XML-RPC connection on which
|
|
159
218
|
you can call various server-side functions.
|
|
160
|
-
"""
|
|
161
|
-
return TCMS._connection
|
|
162
219
|
|
|
163
|
-
|
|
164
|
-
"""
|
|
165
|
-
Returns the server URL and performs various sanity checks!
|
|
166
|
-
"""
|
|
167
|
-
# Make sure the server URL is set
|
|
168
|
-
try:
|
|
169
|
-
config["tcms"]["url"] is not None
|
|
170
|
-
except (KeyError, AttributeError) as err:
|
|
171
|
-
raise RuntimeError(f"No url found in {self._path}") from err
|
|
220
|
+
.. important::
|
|
172
221
|
|
|
173
|
-
|
|
222
|
+
Call this property once and assign it to a temporary variable as
|
|
223
|
+
shown in the examples above. Then use the ``rpc`` variable to
|
|
224
|
+
access the different RPC methods!
|
|
225
|
+
|
|
226
|
+
Starting with tcms-api v12.9.1 this property is automatically refreshed
|
|
227
|
+
every 4 minutes to avoid SSL connection timeout errors!
|
|
228
|
+
"""
|
|
229
|
+
return _ConnectionProxy(self.config)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "13.2"
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
# pylint: disable=protected-access,too-few-public-methods
|
|
1
|
+
# pylint: disable=protected-access,too-few-public-methods
|
|
2
2
|
|
|
3
3
|
import sys
|
|
4
4
|
import urllib.parse
|
|
5
5
|
|
|
6
6
|
from base64 import b64encode
|
|
7
|
-
from datetime import datetime, timedelta
|
|
8
7
|
from http import HTTPStatus
|
|
9
8
|
from http.client import HTTPSConnection
|
|
10
9
|
from xmlrpc.client import _Method, SafeTransport, Transport, ServerProxy
|
|
@@ -24,26 +23,7 @@ _PYTHON_VERSION = sys.version.replace("\n", "")
|
|
|
24
23
|
|
|
25
24
|
|
|
26
25
|
class TCMSProxy(ServerProxy):
|
|
27
|
-
_connected_since = datetime(2024, 1, 1, 0, 0)
|
|
28
|
-
|
|
29
26
|
def __request(self, methodname, params):
|
|
30
|
-
# refresh the connection every 4 minutes to avoid an
|
|
31
|
-
# `ssl.SSLEOFError: EOF occurred in violation of protocol` error with Python >= 3.10
|
|
32
|
-
# In practice I've discovered that 5 minutes works as well, 6 minutes fails so
|
|
33
|
-
# be more cautious and refresh the connection earlier!
|
|
34
|
-
#
|
|
35
|
-
# Side note: originally I thought this is related to calling
|
|
36
|
-
# context.set_alpn_protocols(['http/1.1']) inside http/client.py, introduced in
|
|
37
|
-
# https://github.com/python/cpython/commit/f97406be4c0a02c1501c7ab8bc8ef3850eddb962
|
|
38
|
-
# but that doesn't seem to be the case (or is much harder for me to debug)!
|
|
39
|
-
if getattr(
|
|
40
|
-
self._ServerProxy__transport, # pylint: disable=access-member-before-definition
|
|
41
|
-
"internal_refresh",
|
|
42
|
-
False,
|
|
43
|
-
) and datetime.now() - self._connected_since > timedelta(minutes=4):
|
|
44
|
-
self._ServerProxy__transport = self._ServerProxy__transport.__class__()
|
|
45
|
-
self._connected_since = datetime.now()
|
|
46
|
-
|
|
47
27
|
self._ServerProxy__transport._extra_headers = [("Referer", methodname)]
|
|
48
28
|
return self._ServerProxy__request(methodname, params)
|
|
49
29
|
|
|
@@ -76,15 +56,12 @@ class CookieTransport(Transport):
|
|
|
76
56
|
class SafeCookieTransport(SafeTransport, CookieTransport):
|
|
77
57
|
"""SafeTransport subclass that supports cookies."""
|
|
78
58
|
|
|
79
|
-
internal_refresh = True
|
|
80
59
|
scheme = "https"
|
|
81
60
|
|
|
82
61
|
|
|
83
62
|
class KerbTransport(SafeCookieTransport):
|
|
84
63
|
"""Handles GSSAPI Negotiation (SPNEGO) authentication."""
|
|
85
64
|
|
|
86
|
-
internal_refresh = False
|
|
87
|
-
|
|
88
65
|
def get_host_info(self, host):
|
|
89
66
|
host, extra_headers, x509 = Transport.get_host_info(self, host)
|
|
90
67
|
|
|
@@ -200,7 +177,9 @@ class TCMSKerbXmlrpc(TCMSXmlrpc):
|
|
|
200
177
|
# note: by default will follow redirects
|
|
201
178
|
with requests.sessions.Session() as session:
|
|
202
179
|
response = session.get(url, headers=headers)
|
|
203
|
-
|
|
180
|
+
if response.status_code != HTTPStatus.OK:
|
|
181
|
+
raise RuntimeError(f"Unexpected HTTP response {response}")
|
|
182
|
+
|
|
204
183
|
self.transport._cookies.append( # pylint: disable=protected-access
|
|
205
184
|
self.session_cookie_name
|
|
206
185
|
+ "="
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: tcms-api
|
|
3
|
-
Version:
|
|
3
|
+
Version: 13.2
|
|
4
4
|
Summary: Python API for Kiwi
|
|
5
5
|
Home-page: https://github.com/kiwitcms/tcms-api
|
|
6
6
|
Maintainer: Kiwi TCMS
|
|
@@ -69,6 +69,24 @@ https://tcms-api.readthedocs.io/en/latest/modules/tcms_api.html
|
|
|
69
69
|
CHANGELOG
|
|
70
70
|
---------
|
|
71
71
|
|
|
72
|
+
v13.2 (27 Apr 2024)
|
|
73
|
+
~~~~~~~~~~~~~~~~~~~
|
|
74
|
+
|
|
75
|
+
- Respect configuration passed as arguments to the ``TCMS()`` class, for example::
|
|
76
|
+
|
|
77
|
+
TCMS("https://kiwitcms.example.com/xml-rpc/", "api-bot", "keep-me-secret")
|
|
78
|
+
|
|
79
|
+
- Adjust usage examples and documentation for ``.exec()``. Closes
|
|
80
|
+
`Issue #77 <https://github.com/kiwitcms/tcms-api/issues/77>`_
|
|
81
|
+
- Internal changes related to testing and building this package
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
v12.9.1 (13 Jan 2024)
|
|
85
|
+
~~~~~~~~~~~~~~~~~~~~~
|
|
86
|
+
|
|
87
|
+
- Refactor RPC connection refresh using a proxy-class pattern which also
|
|
88
|
+
takes care to call ``.login()`` upon refresh
|
|
89
|
+
|
|
72
90
|
|
|
73
91
|
v12.9 (12 Jan 2024)
|
|
74
92
|
~~~~~~~~~~~~~~~~~~~
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "12.9"
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|