orangebeard-client 2.7.2__tar.gz → 2.8.0__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.
Files changed (36) hide show
  1. {orangebeard_client-2.7.2/orangebeard_client.egg-info → orangebeard_client-2.8.0}/PKG-INFO +9 -3
  2. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/Cli.py +0 -1
  3. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/OrangebeardClient.py +176 -35
  4. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0/orangebeard_client.egg-info}/PKG-INFO +9 -3
  5. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard_client.egg-info/SOURCES.txt +2 -1
  6. orangebeard_client-2.8.0/orangebeard_client.egg-info/requires.txt +5 -0
  7. orangebeard_client-2.8.0/pyproject.toml +36 -0
  8. orangebeard_client-2.8.0/tests/test_background_loop.py +215 -0
  9. orangebeard_client-2.7.2/orangebeard_client.egg-info/requires.txt +0 -2
  10. orangebeard_client-2.7.2/pyproject.toml +0 -23
  11. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/LICENSE +0 -0
  12. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/__init__.py +0 -0
  13. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/config/AutoConfig.py +0 -0
  14. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/Attachment.py +0 -0
  15. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/Attribute.py +0 -0
  16. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/FinishStep.py +0 -0
  17. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/FinishTest.py +0 -0
  18. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/FinishTestRun.py +0 -0
  19. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/Log.py +0 -0
  20. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/LogFormat.py +0 -0
  21. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/LogLevel.py +0 -0
  22. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/OrangebeardParameters.py +0 -0
  23. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/SUTComponent.py +0 -0
  24. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/Serializable.py +0 -0
  25. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/StartStep.py +0 -0
  26. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/StartSuite.py +0 -0
  27. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/StartTest.py +0 -0
  28. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/StartTestRun.py +0 -0
  29. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/Suite.py +0 -0
  30. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/TestStatus.py +0 -0
  31. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/TestType.py +0 -0
  32. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard/entity/__init__.py +0 -0
  33. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard_client.egg-info/dependency_links.txt +0 -0
  34. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard_client.egg-info/entry_points.txt +0 -0
  35. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/orangebeard_client.egg-info/top_level.txt +0 -0
  36. {orangebeard_client-2.7.2 → orangebeard_client-2.8.0}/setup.cfg +0 -0
@@ -1,16 +1,22 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: orangebeard-client
3
- Version: 2.7.2
3
+ Version: 2.8.0
4
4
  Summary: A python3 client for Orangebeard
5
5
  Author-email: Tom Heintzberger <tom@orangebeard.io>
6
6
  License-Expression: AGPL-3.0-or-later
7
7
  Project-URL: Homepage, https://github.com/orangebeard-io/python-client
8
8
  Project-URL: Bug Tracker, https://github.com/orangebeard-io/python-client/issues
9
9
  Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
10
14
  Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.7
15
+ Requires-Python: >=3.10
12
16
  Description-Content-Type: text/markdown
13
17
  License-File: LICENSE
14
18
  Requires-Dist: pytz
15
- Requires-Dist: aiohttp
19
+ Requires-Dist: aiohttp>=3.13.0
20
+ Provides-Extra: test
21
+ Requires-Dist: pytest>=8.0; extra == "test"
16
22
  Dynamic: license-file
@@ -43,7 +43,6 @@ def main():
43
43
 
44
44
  if args.cmd == "start":
45
45
  temp_uuid = client.start_test_run(StartTestRun(config.testset, datetime.now(tz), config.description, config.attributes), True)
46
- asyncio.gather(client.call_events[temp_uuid].wait())
47
46
  print(client.uuid_mapping[temp_uuid])
48
47
  sys.exit(0)
49
48
 
@@ -1,5 +1,9 @@
1
1
  import asyncio
2
+ import atexit
3
+ import json
4
+ import threading
2
5
  import uuid
6
+ import weakref
3
7
  from asyncio.locks import Event
4
8
  from types import MappingProxyType
5
9
 
@@ -23,25 +27,45 @@ from orangebeard.entity.StartTest import StartTest
23
27
  from orangebeard.entity.StartTestRun import StartTestRun
24
28
  from orangebeard.entity.Suite import Suite
25
29
 
30
+ _LIVE_CLIENTS = weakref.WeakSet()
31
+
32
+
33
+ @atexit.register
34
+ def _flush_live_clients_at_exit():
35
+ """Safety net: send batched logs that were never flushed because the run was not finished properly."""
36
+ for client in list(_LIVE_CLIENTS):
37
+ try:
38
+ client.flush_logs(timeout=10)
39
+ except Exception: # pragma: no cover - never fail interpreter shutdown
40
+ pass
41
+
42
+
43
+ class _JsonList(Serializable):
44
+ """A list of Serializables, serialized as a JSON array."""
45
+
46
+ def __init__(self, items):
47
+ self.items = items
48
+
49
+ def to_json(self):
50
+ return json.dumps([json.loads(item.to_json()) for item in self.items])
51
+
26
52
 
27
53
  class OrangebeardClient:
28
54
  """
29
55
  OrangebeardClient class for interacting with the Orangebeard API.
30
56
 
57
+ All API calls are executed by a private asyncio event loop that runs on a background (daemon) thread.
58
+ Public methods return immediately (the returned UUIDs are client side placeholders that are resolved to
59
+ the real UUIDs just in time, respecting parent/child ordering). Call finish_test_run (or flush_logs) to wait
60
+ until everything has been sent.
61
+
31
62
  Args:
32
63
  endpoint (str): The Orangebeard API endpoint.
33
64
  access_token (UUID): The access token for authentication.
34
65
  project_name (str): The name of the Orangebeard project.
35
-
36
- Attributes:
37
- __endpoint (str): The Orangebeard API endpoint.
38
- __access_token (UUID): The access token for authentication.
39
- __project_name (str): The name of the Orangebeard project.
40
- __connection_with_orangebeard_is_valid (bool): Flag indicating whether the connection with
41
- Orangebeard is valid.
42
- __uuid_mapping (dict): Mapping of temporary UUIDs to actual UUIDs.
43
- __call_events (dict): Mapping of UUIDs to asyncio.Event objects.
44
- __client (aiohttp.ClientSession): A client session for making API requests.
66
+ orangebeard_config (OrangebeardParameters): Alternative way to provide the above (and more).
67
+ log_batch_size (int): Number of logs sent by log_batch() in one request.
68
+ log_batch_interval (float): Maximum time in seconds a log added with log_batch() waits before sending.
45
69
  """
46
70
 
47
71
  def __init__(
@@ -49,16 +73,10 @@ class OrangebeardClient:
49
73
  endpoint: str = None,
50
74
  access_token: UUID = None,
51
75
  project_name: str = None,
52
- orangebeard_config: OrangebeardParameters = None
76
+ orangebeard_config: OrangebeardParameters = None,
77
+ log_batch_size: int = 50,
78
+ log_batch_interval: float = 1.0
53
79
  ) -> None:
54
- """
55
- Initialize the OrangebeardClient.
56
-
57
- Args:
58
- endpoint (str): The Orangebeard API endpoint.
59
- access_token (UUID): The access token for authentication.
60
- project_name (str): The name of the Orangebeard project.
61
- """
62
80
  if orangebeard_config is not None:
63
81
  endpoint = orangebeard_config.endpoint if endpoint is None else endpoint
64
82
  access_token = orangebeard_config.token if access_token is None else access_token
@@ -83,8 +101,18 @@ class OrangebeardClient:
83
101
 
84
102
  self.__uuid_mapping = {}
85
103
  self.__call_events = {}
104
+
105
+ self.__log_batch_size = log_batch_size
106
+ self.__log_batch_interval = log_batch_interval
107
+ self.__log_buffer = []
108
+ self.__log_flush_task = None
109
+
110
+ # The client owns a private event loop on a daemon thread, so it never touches (or conflicts with) an
111
+ # event loop of the calling thread, and API calls do not block the caller.
86
112
  self.__event_loop = asyncio.new_event_loop()
87
- asyncio.set_event_loop(self.__event_loop)
113
+ self.__loop_thread = threading.Thread(target=self.__run_loop, name='orangebeard-client', daemon=True)
114
+ self.__loop_thread.start()
115
+ _LIVE_CLIENTS.add(self)
88
116
 
89
117
  if orangebeard_config is not None and orangebeard_config.testrun_uuid is not None:
90
118
  self.__external_run_lifecycle = True
@@ -92,13 +120,59 @@ class OrangebeardClient:
92
120
  self.__uuid_mapping[orangebeard_config.testrun_uuid] = orangebeard_config.testrun_uuid
93
121
  self.__call_events[orangebeard_config.testrun_uuid].set()
94
122
 
123
+ # ------------------------------------------------------------------ loop plumbing
124
+
125
+ def __run_loop(self) -> None:
126
+ asyncio.set_event_loop(self.__event_loop)
127
+ self.__event_loop.run_forever()
128
+
129
+ def __submit(self, coroutine, event: Event = None):
130
+ """Schedule a coroutine on the client loop. The event (if any) is always released, even when it fails."""
131
+
132
+ async def guarded():
133
+ try:
134
+ return await coroutine
135
+ except Exception as error: # a failing call must never hang dependants or finish_test_run
136
+ print(f'Orangebeard call failed: {error}')
137
+ finally:
138
+ if event is not None and not event.is_set():
139
+ event.set()
140
+
141
+ return asyncio.run_coroutine_threadsafe(guarded(), self.__event_loop)
142
+
143
+ def __run_blocking(self, coroutine, event: Event = None, timeout: float = None):
144
+ return self.__submit(coroutine, event).result(timeout)
145
+
146
+ def close(self) -> None:
147
+ """Stop the background loop. Optional: the loop thread is a daemon and ends with the process."""
148
+ if self.__event_loop.is_closed() or not self.__loop_thread.is_alive():
149
+ return
150
+ try:
151
+ self.flush_logs(timeout=10)
152
+ finally:
153
+ async def shutdown():
154
+ if self.__log_flush_task is not None and not self.__log_flush_task.done():
155
+ self.__log_flush_task.cancel()
156
+ if self.__client is not None and not self.__client.closed:
157
+ await self.__client.close()
158
+
159
+ try:
160
+ asyncio.run_coroutine_threadsafe(shutdown(), self.__event_loop).result(10)
161
+ except Exception:
162
+ pass
163
+ self.__event_loop.call_soon_threadsafe(self.__event_loop.stop)
164
+ self.__loop_thread.join(5)
165
+ _LIVE_CLIENTS.discard(self)
166
+
167
+ # ------------------------------------------------------------------ public API
168
+
95
169
  def start_test_run(self, start_test_run: StartTestRun, direct=False) -> UUID:
96
170
  """
97
171
  Start a new test run.
98
172
 
99
173
  Args:
100
174
  start_test_run (StartTestRun): The StartTestRun object containing information about the test run.
101
- direct: boolean indicating a standalone, direct cli call
175
+ direct: boolean indicating a standalone, direct cli call (blocks until the run is started)
102
176
 
103
177
  Returns:
104
178
  UUID: The UUID associated with the started test run.
@@ -108,7 +182,11 @@ class OrangebeardClient:
108
182
 
109
183
  self.__call_events[temp_uuid] = start_test_run_event
110
184
 
111
- self.__event_loop.run_until_complete(self.__exec_start_test_run(start_test_run, temp_uuid, direct))
185
+ coroutine = self.__exec_start_test_run(start_test_run, temp_uuid, direct)
186
+ if direct:
187
+ self.__run_blocking(coroutine, start_test_run_event)
188
+ else:
189
+ self.__submit(coroutine, start_test_run_event)
112
190
  return temp_uuid
113
191
 
114
192
  def start_announced_test_run(self, test_run_uuid: UUID) -> None:
@@ -120,7 +198,7 @@ class OrangebeardClient:
120
198
  """
121
199
  start_test_run_event = asyncio.Event()
122
200
  self.__call_events[test_run_uuid] = start_test_run_event
123
- self.__event_loop.run_until_complete(self.__exec_start_announced_test_run(test_run_uuid))
201
+ self.__run_blocking(self.__exec_start_announced_test_run(test_run_uuid), start_test_run_event)
124
202
 
125
203
  def finish_test_run(self, test_run_uuid: UUID, finish_test_run: FinishTestRun, direct=False) -> None:
126
204
  """
@@ -132,8 +210,7 @@ class OrangebeardClient:
132
210
  test run.
133
211
  direct (Bool): indication that a standalone finish call is required. True for CLI
134
212
  """
135
- self.__event_loop.run_until_complete(
136
- self.__exec_finish_test_run(test_run_uuid, finish_test_run, direct))
213
+ self.__run_blocking(self.__exec_finish_test_run(test_run_uuid, finish_test_run, direct))
137
214
 
138
215
  def start_suite(self, start_suite: StartSuite) -> list[UUID]:
139
216
  """
@@ -154,7 +231,7 @@ class OrangebeardClient:
154
231
  else start_suite.parentSuiteUUID
155
232
  parent_event = self.__call_events[parent_event_uuid]
156
233
 
157
- self.__event_loop.run_until_complete(self.__exec_start_suite(start_suite, temp_uuids, parent_event))
234
+ self.__submit(self.__exec_start_suite(start_suite, temp_uuids, parent_event), start_suite_event)
158
235
  return temp_uuids
159
236
 
160
237
  def start_test(self, start_test: StartTest) -> UUID:
@@ -172,7 +249,7 @@ class OrangebeardClient:
172
249
  self.__call_events[temp_uuid] = start_test_event
173
250
 
174
251
  parent_event = self.__call_events[start_test.suiteUUID]
175
- self.__event_loop.run_until_complete(self.__exec_start_test(start_test, temp_uuid, parent_event))
252
+ self.__submit(self.__exec_start_test(start_test, temp_uuid, parent_event), start_test_event)
176
253
  return temp_uuid
177
254
 
178
255
  def finish_test(self, test_uuid: UUID, finish_test: FinishTest) -> None:
@@ -188,7 +265,7 @@ class OrangebeardClient:
188
265
  self.__call_events[temp_uuid] = finish_test_event
189
266
 
190
267
  parent_event = self.__call_events[test_uuid]
191
- asyncio.ensure_future(self.__exec_finish_test(test_uuid, finish_test, temp_uuid, parent_event))
268
+ self.__submit(self.__exec_finish_test(test_uuid, finish_test, temp_uuid, parent_event), finish_test_event)
192
269
 
193
270
  def start_step(self, start_step: StartStep) -> UUID:
194
271
  """
@@ -209,7 +286,7 @@ class OrangebeardClient:
209
286
 
210
287
  parent_event = self.__call_events[parent_event_uuid]
211
288
 
212
- self.__event_loop.run_until_complete(self.__exec_start_step(start_step, temp_uuid, parent_event))
289
+ self.__submit(self.__exec_start_step(start_step, temp_uuid, parent_event), start_step_event)
213
290
  return temp_uuid
214
291
 
215
292
  def finish_step(self, step_uuid: UUID, finish_step: FinishStep) -> None:
@@ -225,11 +302,11 @@ class OrangebeardClient:
225
302
  self.__call_events[temp_uuid] = finish_step_event
226
303
 
227
304
  parent_event = self.__call_events[step_uuid]
228
- asyncio.ensure_future(self.__exec_finish_step(step_uuid, finish_step, temp_uuid, parent_event))
305
+ self.__submit(self.__exec_finish_step(step_uuid, finish_step, temp_uuid, parent_event), finish_step_event)
229
306
 
230
307
  def log(self, log: Log) -> UUID:
231
308
  """
232
- Send a log.
309
+ Send a log. The returned UUID can be used to attach an attachment to the log (see send_attachment).
233
310
 
234
311
  Args:
235
312
  log (Log): The Log object containing information to store.
@@ -245,9 +322,40 @@ class OrangebeardClient:
245
322
  else log.stepUUID
246
323
  parent_event = self.__call_events[parent_event_uuid]
247
324
 
248
- asyncio.ensure_future(self.__exec_log(log, temp_uuid, parent_event))
325
+ self.__submit(self.__exec_log(log, temp_uuid, parent_event), log_event)
249
326
  return temp_uuid
250
327
 
328
+ def log_batch(self, log: Log) -> None:
329
+ """
330
+ Send a log as part of a batch. Cheaper than log() when producing many logs, but the server does not return
331
+ a log id, so an attachment cannot be linked to it (use log() for that).
332
+ Logs are sent when log_batch_size is reached, after log_batch_interval seconds, when a test is finished,
333
+ and on finish_test_run / flush_logs.
334
+
335
+ Args:
336
+ log (Log): The Log object containing information to store.
337
+ """
338
+ log_event = asyncio.Event()
339
+ temp_uuid = uuid.uuid4()
340
+ self.__call_events[temp_uuid] = log_event
341
+
342
+ parent_event_uuid = log.testUUID if log.stepUUID is None \
343
+ else log.stepUUID
344
+ parent_event = self.__call_events[parent_event_uuid]
345
+
346
+ self.__submit(self.__exec_log_batch(log, parent_event), log_event)
347
+
348
+ def flush_logs(self, timeout: float = None) -> None:
349
+ """Send all buffered batch logs and wait until that is done."""
350
+ if self.__event_loop.is_closed() or not self.__loop_thread.is_alive():
351
+ return
352
+ self.__run_blocking(self.__exec_wait_and_flush_logs(), timeout=timeout)
353
+
354
+ async def __exec_wait_and_flush_logs(self) -> None:
355
+ for event in list(self.__call_events.values()): # queued calls (e.g. log_batch) must be buffered first
356
+ await event.wait()
357
+ await self.__exec_flush_logs()
358
+
251
359
  def send_attachment(self, attachment: Attachment) -> UUID:
252
360
  """
253
361
  Send an attachment. (to attach to a log)
@@ -263,9 +371,11 @@ class OrangebeardClient:
263
371
  self.__call_events[temp_uuid] = attachment_event
264
372
 
265
373
  parent_event = self.__call_events[attachment.AttachmentMetaData.logUUID]
266
- asyncio.ensure_future(self.__exec_send_attachment(attachment, temp_uuid, parent_event))
374
+ self.__submit(self.__exec_send_attachment(attachment, temp_uuid, parent_event), attachment_event)
267
375
  return temp_uuid
268
376
 
377
+ # ------------------------------------------------------------------ execution (runs on the client loop)
378
+
269
379
  async def __ensure_client(self):
270
380
  if self.__client is None or self.__client.closed:
271
381
  if not self.__endpoint.endswith('/'):
@@ -326,8 +436,9 @@ class OrangebeardClient:
326
436
  async def __exec_finish_test_run(self, test_run_uuid: UUID, finish_test_run: FinishTestRun, direct=False) -> None:
327
437
  print(f'Waiting for {len(self.__call_events.values()) + 1} Orangebeard events to finish...')
328
438
 
329
- for event in self.__call_events.values():
439
+ for event in list(self.__call_events.values()):
330
440
  await event.wait()
441
+ await self.__exec_flush_logs()
331
442
 
332
443
  if direct is True:
333
444
  real_test_run_uuid = test_run_uuid
@@ -340,10 +451,11 @@ class OrangebeardClient:
340
451
  f'listener/v3/{self.__project_name}/test-run/finish/{real_test_run_uuid}',
341
452
  finish_test_run
342
453
  )
343
- print('Done. Test run finished!')
454
+ print(f'Done. Orangebeard Report: {self.__endpoint}p/{self.__project_name}/test-results')
344
455
  else:
345
456
  print('Done. Remember to finish run using CLI!')
346
457
 
458
+ await self.__ensure_client()
347
459
  await self.__client.close()
348
460
 
349
461
  async def __exec_start_suite(self, start_suite: StartSuite, suite_temp_ids: list[UUID],
@@ -382,6 +494,7 @@ class OrangebeardClient:
382
494
  async def __exec_finish_test(self, test_uuid: UUID, finish_test: FinishTest, temp_uuid: UUID,
383
495
  parent_event: Event) -> None:
384
496
  await parent_event.wait()
497
+ await self.__exec_flush_logs() # logs of a test are sent before the test itself is finished
385
498
  test_uuid = await self.__get_real_uuid(test_uuid)
386
499
  finish_test.testRunUUID = await self.__get_real_uuid(finish_test.testRunUUID)
387
500
 
@@ -440,6 +553,34 @@ class OrangebeardClient:
440
553
  self.__uuid_mapping[temp_uuid] = actual_uuid
441
554
  self.__call_events[temp_uuid].set()
442
555
 
556
+ async def __exec_log_batch(self, log: Log, parent_event: Event) -> None:
557
+ await parent_event.wait()
558
+ if log.message.strip() == '':
559
+ log.message = '_empty_'
560
+ log.testRunUUID = await self.__get_real_uuid(log.testRunUUID)
561
+ log.testUUID = await self.__get_real_uuid(log.testUUID)
562
+ log.stepUUID = await self.__get_real_uuid(log.stepUUID) if log.stepUUID is not None else None
563
+
564
+ self.__log_buffer.append(log)
565
+ if len(self.__log_buffer) >= self.__log_batch_size:
566
+ await self.__exec_flush_logs()
567
+ elif self.__log_flush_task is None or self.__log_flush_task.done():
568
+ self.__log_flush_task = asyncio.ensure_future(self.__flush_logs_later())
569
+
570
+ async def __flush_logs_later(self) -> None:
571
+ await asyncio.sleep(self.__log_batch_interval)
572
+ await self.__exec_flush_logs()
573
+
574
+ async def __exec_flush_logs(self) -> None:
575
+ if not self.__log_buffer:
576
+ return
577
+ logs, self.__log_buffer = self.__log_buffer, []
578
+ await self.__make_api_request(
579
+ 'POST',
580
+ f'listener/v3/{self.__project_name}/log/batch',
581
+ _JsonList(logs)
582
+ )
583
+
443
584
  async def __exec_send_attachment(self, attachment: Attachment, temp_uuid: UUID, parent_event: Event) -> None:
444
585
  await parent_event.wait()
445
586
  attachment.AttachmentMetaData.testRunUUID = await self.__get_real_uuid(
@@ -1,16 +1,22 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: orangebeard-client
3
- Version: 2.7.2
3
+ Version: 2.8.0
4
4
  Summary: A python3 client for Orangebeard
5
5
  Author-email: Tom Heintzberger <tom@orangebeard.io>
6
6
  License-Expression: AGPL-3.0-or-later
7
7
  Project-URL: Homepage, https://github.com/orangebeard-io/python-client
8
8
  Project-URL: Bug Tracker, https://github.com/orangebeard-io/python-client/issues
9
9
  Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
10
14
  Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.7
15
+ Requires-Python: >=3.10
12
16
  Description-Content-Type: text/markdown
13
17
  License-File: LICENSE
14
18
  Requires-Dist: pytz
15
- Requires-Dist: aiohttp
19
+ Requires-Dist: aiohttp>=3.13.0
20
+ Provides-Extra: test
21
+ Requires-Dist: pytest>=8.0; extra == "test"
16
22
  Dynamic: license-file
@@ -28,4 +28,5 @@ orangebeard_client.egg-info/SOURCES.txt
28
28
  orangebeard_client.egg-info/dependency_links.txt
29
29
  orangebeard_client.egg-info/entry_points.txt
30
30
  orangebeard_client.egg-info/requires.txt
31
- orangebeard_client.egg-info/top_level.txt
31
+ orangebeard_client.egg-info/top_level.txt
32
+ tests/test_background_loop.py
@@ -0,0 +1,5 @@
1
+ pytz
2
+ aiohttp>=3.13.0
3
+
4
+ [test]
5
+ pytest>=8.0
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = [ "setuptools>=77.0",]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "orangebeard-client"
7
+ version = "2.8.0"
8
+ description = "A python3 client for Orangebeard"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "AGPL-3.0-or-later"
12
+ classifiers = [
13
+ "Programming Language :: Python :: 3",
14
+ "Programming Language :: Python :: 3.10",
15
+ "Programming Language :: Python :: 3.11",
16
+ "Programming Language :: Python :: 3.12",
17
+ "Programming Language :: Python :: 3.13",
18
+ "Operating System :: OS Independent",
19
+ ]
20
+ dependencies = [ "pytz", "aiohttp>=3.13.0",]
21
+ [[project.authors]]
22
+ name = "Tom Heintzberger"
23
+ email = "tom@orangebeard.io"
24
+
25
+ [project.optional-dependencies]
26
+ test = [ "pytest>=8.0",]
27
+
28
+ [project.scripts]
29
+ orangebeard-cli = "orangebeard.Cli:main"
30
+
31
+ [project.urls]
32
+ Homepage = "https://github.com/orangebeard-io/python-client"
33
+ "Bug Tracker" = "https://github.com/orangebeard-io/python-client/issues"
34
+
35
+ [tool.pytest.ini_options]
36
+ testpaths = ["tests"]
@@ -0,0 +1,215 @@
1
+ import asyncio
2
+ import json
3
+ import subprocess
4
+ import sys
5
+ import textwrap
6
+ import threading
7
+ import time
8
+ from datetime import datetime
9
+
10
+ from orangebeard.entity.Attachment import Attachment, AttachmentFile, AttachmentMetaData
11
+ from orangebeard.entity.FinishStep import FinishStep
12
+ from orangebeard.entity.FinishTest import FinishTest
13
+ from orangebeard.entity.FinishTestRun import FinishTestRun
14
+ from orangebeard.entity.Log import Log
15
+ from orangebeard.entity.LogFormat import LogFormat
16
+ from orangebeard.entity.LogLevel import LogLevel
17
+ from orangebeard.entity.StartStep import StartStep
18
+ from orangebeard.entity.StartSuite import StartSuite
19
+ from orangebeard.entity.StartTest import StartTest
20
+ from orangebeard.entity.StartTestRun import StartTestRun
21
+ from orangebeard.entity.TestStatus import TestStatus as Status
22
+ from orangebeard.entity.TestType import TestType as Kind
23
+ from tests.conftest import TOKEN
24
+ from tests.fake_server import FakeOrangebeardServer
25
+
26
+ NOW = datetime.now().astimezone()
27
+
28
+
29
+ def run_rf_like_sequence(client, with_attachment=True):
30
+ """The call sequence the Robot Framework listener performs (public API only)."""
31
+ run = client.start_test_run(StartTestRun('set', NOW, 'desc'))
32
+ suites = client.start_suite(StartSuite(run, ['Parent', 'Child']))
33
+ test = client.start_test(StartTest(run, suites[-1], 'a test', NOW, Kind.TEST))
34
+ step = client.start_step(StartStep(run, test, 'a step', NOW))
35
+ log = client.log(Log(run, test, 'hello', LogLevel.INFO, LogFormat.PLAIN_TEXT, step, NOW))
36
+ if with_attachment:
37
+ client.send_attachment(Attachment(AttachmentFile('a.txt', b'data'), AttachmentMetaData(run, test, log, step)))
38
+ client.finish_step(step, FinishStep(run, Status.PASSED, NOW))
39
+ client.finish_test(test, FinishTest(run, Status.PASSED, NOW))
40
+ client.finish_test_run(run, FinishTestRun(NOW))
41
+ return run
42
+
43
+
44
+ def test_dependent_calls_carry_real_uuids(server, make_client):
45
+ client = make_client()
46
+ run_rf_like_sequence(client)
47
+
48
+ suite_req = server.of('/suite/start')[0]['body']
49
+ paths = server.paths()
50
+ assert paths[0] == ('POST', 'test-run/start')
51
+ assert ('POST', 'suite/start') in paths and ('POST', 'test/start') in paths and ('POST', 'step/start') in paths
52
+ assert paths[-1][0] == 'PUT' and paths[-1][1].startswith('test-run/finish/')
53
+
54
+ # the finish url must carry the real (server issued) run uuid, not the client side temp uuid
55
+ run_uuid = paths[-1][1].rsplit('/', 1)[1]
56
+ assert suite_req['testRunUUID'] == run_uuid
57
+ test_req = server.of('/test/start')[0]['body']
58
+ assert test_req['testRunUUID'] == run_uuid
59
+ assert test_req['suiteUUID'] and test_req['suiteUUID'] != run_uuid
60
+ log_req = server.of('/log')[0]['body']
61
+ assert log_req['testUUID'] and log_req['stepUUID'] and log_req['testRunUUID'] == run_uuid
62
+ attachment = server.of('/attachment')[0]
63
+ assert attachment['method'] == 'POST'
64
+
65
+
66
+ def test_finish_test_run_flushes_pending_fire_and_forget_calls():
67
+ srv = FakeOrangebeardServer(delay=0.05).start()
68
+ try:
69
+ from orangebeard.OrangebeardClient import OrangebeardClient
70
+ client = OrangebeardClient(endpoint=srv.url, access_token=TOKEN, project_name='proj')
71
+ run_rf_like_sequence(client)
72
+ names = [p[1] for p in srv.paths()]
73
+ assert names.count('log') == 1
74
+ assert any(n.startswith('step/finish/') for n in names)
75
+ assert any(n.startswith('test/finish/') for n in names)
76
+ assert names[-1].startswith('test-run/finish/')
77
+ client.close()
78
+ finally:
79
+ srv.stop()
80
+
81
+
82
+ def test_start_calls_do_not_block_the_caller():
83
+ srv = FakeOrangebeardServer(delay=0.3).start()
84
+ try:
85
+ from orangebeard.OrangebeardClient import OrangebeardClient
86
+ client = OrangebeardClient(endpoint=srv.url, access_token=TOKEN, project_name='proj')
87
+ began = time.monotonic()
88
+ run = client.start_test_run(StartTestRun('set', NOW, 'desc'))
89
+ suites = client.start_suite(StartSuite(run, ['S']))
90
+ test = client.start_test(StartTest(run, suites[0], 't', NOW, Kind.TEST))
91
+ client.start_step(StartStep(run, test, 's', NOW))
92
+ assert time.monotonic() - began < 0.25 # four sequential 0.3s calls would take >1.2s
93
+ client.finish_test_run(run, FinishTestRun(NOW))
94
+ assert len(srv.of('/step/start')) == 1
95
+ client.close()
96
+ finally:
97
+ srv.stop()
98
+
99
+
100
+ def test_works_while_an_event_loop_is_running_in_the_calling_thread(server, make_client):
101
+ client = make_client()
102
+
103
+ async def inside_running_loop():
104
+ run_rf_like_sequence(client)
105
+
106
+ asyncio.run(inside_running_loop())
107
+ assert server.paths()[-1][1].startswith('test-run/finish/')
108
+
109
+
110
+ def test_constructing_a_client_does_not_install_an_event_loop_in_the_calling_thread(server):
111
+ from orangebeard.OrangebeardClient import OrangebeardClient
112
+ outcome = {}
113
+
114
+ def work():
115
+ client = OrangebeardClient(endpoint=server.url, access_token=TOKEN, project_name='proj')
116
+ try:
117
+ asyncio.get_event_loop()
118
+ outcome['loop'] = True
119
+ except RuntimeError:
120
+ outcome['loop'] = False
121
+ client.close()
122
+
123
+ t = threading.Thread(target=work)
124
+ t.start()
125
+ t.join(10)
126
+ assert outcome['loop'] is False
127
+
128
+
129
+ def test_log_batch_is_sent_as_one_batch_request(server, make_client):
130
+ client = make_client()
131
+ run = client.start_test_run(StartTestRun('set', NOW, 'desc'))
132
+ suites = client.start_suite(StartSuite(run, ['S']))
133
+ test = client.start_test(StartTest(run, suites[0], 't', NOW, Kind.TEST))
134
+ for i in range(5):
135
+ client.log_batch(Log(run, test, f'm{i}', LogLevel.INFO, LogFormat.PLAIN_TEXT, None, NOW))
136
+ client.finish_test(test, FinishTest(run, Status.PASSED, NOW))
137
+ client.finish_test_run(run, FinishTestRun(NOW))
138
+
139
+ batches = server.of('/log/batch')
140
+ assert len(batches) == 1
141
+ entries = batches[0]['body']
142
+ assert [e['message'] for e in entries] == [f'm{i}' for i in range(5)]
143
+ assert all(e['testUUID'] and e['testRunUUID'] for e in entries) # real uuids, not None
144
+ assert server.of('/log') == []
145
+ # the log batch lands before the test is finished
146
+ names = [p[1] for p in server.paths()]
147
+ assert names.index('log/batch') < next(i for i, n in enumerate(names) if n.startswith('test/finish/'))
148
+
149
+
150
+ def test_log_batch_flushes_when_the_buffer_is_full(server, make_client):
151
+ client = make_client(log_batch_size=3)
152
+ run = client.start_test_run(StartTestRun('set', NOW, 'desc'))
153
+ suites = client.start_suite(StartSuite(run, ['S']))
154
+ test = client.start_test(StartTest(run, suites[0], 't', NOW, Kind.TEST))
155
+ for i in range(7):
156
+ client.log_batch(Log(run, test, f'm{i}', LogLevel.INFO, LogFormat.PLAIN_TEXT, None, NOW))
157
+ client.finish_test_run(run, FinishTestRun(NOW))
158
+ sizes = [len(b['body']) for b in server.of('/log/batch')]
159
+ assert sizes == [3, 3, 1]
160
+
161
+
162
+ def test_log_batch_flushes_on_interval(server, make_client):
163
+ client = make_client(log_batch_interval=0.2)
164
+ run = client.start_test_run(StartTestRun('set', NOW, 'desc'))
165
+ suites = client.start_suite(StartSuite(run, ['S']))
166
+ test = client.start_test(StartTest(run, suites[0], 't', NOW, Kind.TEST))
167
+ client.log_batch(Log(run, test, 'lonely', LogLevel.INFO, LogFormat.PLAIN_TEXT, None, NOW))
168
+ deadline = time.monotonic() + 3
169
+ while not server.of('/log/batch') and time.monotonic() < deadline:
170
+ time.sleep(0.05)
171
+ assert len(server.of('/log/batch')) == 1
172
+
173
+
174
+ def test_external_run_lifecycle_does_not_finish_the_run(server):
175
+ from orangebeard.OrangebeardClient import OrangebeardClient
176
+ from orangebeard.entity.OrangebeardParameters import OrangebeardParameters
177
+ import uuid
178
+ run = uuid.uuid4()
179
+ cfg = OrangebeardParameters(token=TOKEN, endpoint=server.url, project='proj', testrun_uuid=run)
180
+ client = OrangebeardClient(orangebeard_config=cfg)
181
+ suites = client.start_suite(StartSuite(run, ['S']))
182
+ assert suites
183
+ client.finish_test_run(run, FinishTestRun(NOW))
184
+ assert not any(p[1].startswith('test-run/finish') for p in server.paths())
185
+ client.close()
186
+
187
+
188
+ def test_unflushed_batch_logs_are_sent_at_interpreter_exit(server):
189
+ script = textwrap.dedent(f"""
190
+ from datetime import datetime
191
+ from orangebeard.OrangebeardClient import OrangebeardClient
192
+ from orangebeard.entity.Log import Log
193
+ from orangebeard.entity.StartSuite import StartSuite
194
+ from orangebeard.entity.StartTest import StartTest
195
+ from orangebeard.entity.StartTestRun import StartTestRun
196
+ from orangebeard.entity.TestType import TestType
197
+ now = datetime.now().astimezone()
198
+ c = OrangebeardClient(endpoint={server.url!r}, access_token={TOKEN!r}, project_name='proj')
199
+ run = c.start_test_run(StartTestRun('set', now, 'd'))
200
+ s = c.start_suite(StartSuite(run, ['S']))
201
+ t = c.start_test(StartTest(run, s[0], 't', now, TestType.TEST))
202
+ c.log_batch(Log(run, t, 'left behind', 'INFO', 'PLAIN_TEXT', None, now))
203
+ """)
204
+ subprocess.run([sys.executable, '-c', script], check=True, timeout=60)
205
+ batches = server.of('/log/batch')
206
+ assert len(batches) == 1 and batches[0]['body'][0]['message'] == 'left behind'
207
+
208
+
209
+ def test_public_contract_is_unchanged(make_client):
210
+ client = make_client()
211
+ assert isinstance(client.call_events, dict)
212
+ assert isinstance(client.uuid_mapping, dict)
213
+ for name in ('start_test_run', 'start_announced_test_run', 'finish_test_run', 'start_suite', 'start_test',
214
+ 'finish_test', 'start_step', 'finish_step', 'log', 'send_attachment'):
215
+ assert callable(getattr(client, name))
@@ -1,2 +0,0 @@
1
- pytz
2
- aiohttp
@@ -1,23 +0,0 @@
1
- [build-system]
2
- requires = [ "setuptools>=67.0",]
3
- build-backend = "setuptools.build_meta"
4
-
5
- [project]
6
- name = "orangebeard-client"
7
- version = "2.7.2"
8
- description = "A python3 client for Orangebeard"
9
- readme = "README.md"
10
- requires-python = ">=3.7"
11
- license = "AGPL-3.0-or-later"
12
- classifiers = [ "Programming Language :: Python :: 3", "Operating System :: OS Independent",]
13
- dependencies = [ "pytz", "aiohttp",]
14
- [[project.authors]]
15
- name = "Tom Heintzberger"
16
- email = "tom@orangebeard.io"
17
-
18
- [project.scripts]
19
- orangebeard-cli = "orangebeard.Cli:main"
20
-
21
- [project.urls]
22
- Homepage = "https://github.com/orangebeard-io/python-client"
23
- "Bug Tracker" = "https://github.com/orangebeard-io/python-client/issues"