|
1 | 1 | #! /usr/bin/env python |
2 | 2 | # -*- coding: utf-8 -*- |
3 | 3 |
|
| 4 | +import io |
4 | 5 | import json |
5 | 6 | import os |
6 | | -import sys |
7 | 7 | import random |
8 | | -import time |
| 8 | +import sys |
9 | 9 | import textwrap |
| 10 | +import time |
10 | 11 | import unittest |
| 12 | +from io import open as io_open |
| 13 | + |
11 | 14 | from irods.column import Like |
12 | | -from irods.models import DataObject, RuleExec |
13 | 15 | from irods.exception import ( |
14 | 16 | FAIL_ACTION_ENCOUNTERED_ERR, |
15 | 17 | RULE_ENGINE_ERROR, |
16 | 18 | UnknowniRODSError, |
17 | 19 | ) |
18 | | -import irods.test.helpers as helpers |
| 20 | +from irods.models import DataObject, RuleExec |
19 | 21 | from irods.rule import Rule |
20 | | -from io import open as io_open |
21 | | -import io |
22 | | - |
| 22 | +from irods.test import helpers |
23 | 23 |
|
24 | 24 | RE_Plugins_installed_run_condition_args = ( |
25 | 25 | os.environ.get("PYTHON_RULE_ENGINE_INSTALLED", "*").lower()[:1] == "y", |
@@ -439,29 +439,29 @@ def test_rulefile_in_file_like_object_2__336(self): |
439 | 439 | self.assertRegex(lines[0], r"\[INTEGER\]\[5\]") |
440 | 440 | self.assertRegex(lines[1], r"\[STRING\]\[A String\]") |
441 | 441 |
|
442 | | - |
443 | | - def test_rule_exec_context(self): |
444 | | - if self.sess.server_version < (4, 3): |
445 | | - self.skipTest("""RuleExec's "context" attribute not available before 4.3.0""") |
446 | | - |
| 442 | + def test_rule_exec_context_column_is_available_via_genquery1__issue_823(self): |
447 | 443 | rule_id = -1 |
448 | 444 |
|
449 | 445 | try: |
450 | | - # Schedule a delayed rule. |
451 | | - n_minutes = 15 |
452 | | - random_int = random.randint(1<<30, (1<<31)-1) |
| 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 |
453 | 452 | r = Rule( |
454 | 453 | self.sess, |
455 | | - body=f'''delay("<PLUSET>{n_minutes}m</PLUSET>") {{ writeLine("serverLog","{random_int}") }}''' |
| 454 | + body=f'''delay("<PLUSET>{delay_seconds}</PLUSET>") {{ writeLine("serverLog","{random_int}") }}''', |
456 | 455 | ) |
| 456 | + # Schedule the delayed rule. |
457 | 457 | r.execute() |
458 | 458 |
|
459 | 459 | # Get the delayed rule's ID, needed for cancellation. |
460 | | - l = list(self.sess.query(RuleExec).filter(Like(RuleExec.name,f'%"{random_int}"%'))) |
461 | | - rule_id = l[0][RuleExec.id] |
| 460 | + results = list(self.sess.query(RuleExec).filter(Like(RuleExec.name, f'%"{random_int}"%'))) |
| 461 | + rule_id = results[0][RuleExec.id] |
462 | 462 |
|
463 | 463 | # Assert context exists, and is JSON-parsable with a non-null-length result. |
464 | | - rule_context = l[0][RuleExec.context] |
| 464 | + rule_context = results[0][RuleExec.context] |
465 | 465 | self.assertGreater(len(json.loads(rule_context)), 0) |
466 | 466 | finally: |
467 | 467 | # Remove the delayed rule from the queue. |
|
0 commit comments