|
1 | 1 | #! /usr/bin/env python |
2 | 2 | # -*- coding: utf-8 -*- |
3 | 3 |
|
| 4 | +import io |
| 5 | +import json |
4 | 6 | import os |
| 7 | +import random |
5 | 8 | import sys |
6 | | -import time |
7 | 9 | import textwrap |
| 10 | +import time |
8 | 11 | import unittest |
9 | | -from irods.models import DataObject |
| 12 | +from io import open as io_open |
| 13 | + |
| 14 | +from irods.column import Like |
10 | 15 | from irods.exception import ( |
11 | 16 | FAIL_ACTION_ENCOUNTERED_ERR, |
12 | 17 | RULE_ENGINE_ERROR, |
13 | 18 | UnknowniRODSError, |
14 | 19 | ) |
15 | | -import irods.test.helpers as helpers |
| 20 | +from irods.models import DataObject, RuleExec |
16 | 21 | from irods.rule import Rule |
17 | | -from io import open as io_open |
18 | | -import io |
19 | | - |
| 22 | +from irods.test import helpers |
20 | 23 |
|
21 | 24 | RE_Plugins_installed_run_condition_args = ( |
22 | 25 | os.environ.get("PYTHON_RULE_ENGINE_INSTALLED", "*").lower()[:1] == "y", |
@@ -436,6 +439,35 @@ def test_rulefile_in_file_like_object_2__336(self): |
436 | 439 | self.assertRegex(lines[0], r"\[INTEGER\]\[5\]") |
437 | 440 | self.assertRegex(lines[1], r"\[STRING\]\[A String\]") |
438 | 441 |
|
| 442 | + def test_rule_exec_context_column_is_available_via_genquery1__issue_823(self): |
| 443 | + rule_id = -1 |
| 444 | + |
| 445 | + try: |
| 446 | + # Schedule a delayed rule. The amount of delay does not matter as only its existence |
| 447 | + # in the catalog matters and we'll be cancelling it immediately after the test. |
| 448 | + delay_seconds = 15 * 60 |
| 449 | + |
| 450 | + # Generate a unique number for use in querying the rule. |
| 451 | + random_int = random.randint(1 << 30, (1 << 31) - 1) # noqa: S311 |
| 452 | + r = Rule( |
| 453 | + self.sess, |
| 454 | + body=f'''delay("<PLUSET>{delay_seconds}</PLUSET>") {{ writeLine("serverLog","{random_int}") }}''', |
| 455 | + ) |
| 456 | + # Schedule the delayed rule. |
| 457 | + r.execute() |
| 458 | + |
| 459 | + # Get the delayed rule's ID, needed for cancellation. |
| 460 | + results = list(self.sess.query(RuleExec).filter(Like(RuleExec.name, f'%"{random_int}"%'))) |
| 461 | + rule_id = results[0][RuleExec.id] |
| 462 | + |
| 463 | + # Assert context exists, and is JSON-parsable with a non-null-length result. |
| 464 | + rule_context = results[0][RuleExec.context] |
| 465 | + self.assertGreater(len(json.loads(rule_context)), 0) |
| 466 | + finally: |
| 467 | + # Remove the delayed rule from the queue. |
| 468 | + if rule_id >= 0: |
| 469 | + r.remove_by_id(rule_id) |
| 470 | + |
439 | 471 |
|
440 | 472 | if __name__ == "__main__": |
441 | 473 | # let the tests find the parent irods lib |
|
0 commit comments