Mercurial > p > roundup > code
annotate roundup/test/tx_Source_detector.py @ 7752:b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
Converting to using the ruff linter and its rulesets. Fixed a number
of issues.
admin.py:
sort imports
use immutable tuples as default value markers for parameters where a
None value is valid.
reduced some loops to list comprehensions for performance
used ternary to simplify some if statements
named some variables to make them less magic
(e.g. _default_savepoint_setting = 1000)
fixed some tests for argument counts < 2 becomes != 2 so 3 is an
error.
moved exception handlers outside of loops for performance where
exception handler will abort loop anyway.
renamed variables called 'id' or 'dir' as they shadow builtin
commands.
fix translations of form _("string %s" % value) -> _("string %s") %
value so translation will be looked up with the key before
substitution.
end dicts, tuples with a trailing comma to reduce missing comma
errors if modified
simplified sorted(list(self.setting.keys())) to
sorted(self.setting.keys()) as sorted consumes whole list.
in if conditions put compared variable on left and threshold condition
on right. (no yoda conditions)
multiple noqa: suppression
removed unneeded noqa as lint rulesets are a bit different
do_get - refactor output printing logic: Use fast return if not
special formatting is requested; use isinstance with a tuple
rather than two isinstance calls; cleaned up flow and removed
comments on algorithm as it can be easily read from the code.
do_filter, do_find - refactor output printing logic. Reduce
duplicate code.
do_find - renamed variable 'value' that was set inside a loop. The
loop index variable was also named 'value'.
do_pragma - added hint to use list subcommand if setting was not
found. Replaced condition 'type(x) is bool' with 'isinstance(x,
bool)' for various types.
test_admin.py
added testing for do_list
better test coverage for do_get includes: -S and -d for multilinks,
error case for -d with non-link.
better testing for do_find including all output modes
better testing for do_filter including all output modes
fixed expected output for do_pragma that now includes hint to use
pragma list if setting not found.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 01 Mar 2024 14:53:18 -0500 |
| parents | 137aabd876ad |
| children | 9c3ec0a5c7fc |
| rev | line source |
|---|---|
| 4781 | 1 # |
| 2 # Example output when the web interface changes item 3 and the email | |
| 3 # (non pgp) interface changes item 4: | |
| 4 # | |
| 5 # tx_SourceCheckAudit(3) pre db.tx_Source: cgi | |
| 6 # tx_SourceCheckAudit(4) pre db.tx_Source: email | |
| 7 # tx_SourceCheckAudit(3) post db.tx_Source: cgi | |
| 8 # tx_SourceCheckAudit(4) post db.tx_Source: email | |
| 9 # tx_SourceCheckReact(4) pre db.tx_Source: email | |
| 10 # tx_SourceCheckReact(4) post db.tx_Source: email | |
| 11 # tx_SourceCheckReact(3) pre db.tx_Source: cgi | |
| 12 # tx_SourceCheckReact(3) post db.tx_Source: cgi | |
| 13 # | |
| 14 # Note that the calls are interleaved, but the proper | |
| 15 # tx_Source is associated with the same ticket. | |
| 16 | |
|
5376
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4781
diff
changeset
|
17 from __future__ import print_function |
| 7033 | 18 |
| 4781 | 19 |
| 20 def tx_SourceCheckAudit(db, cl, nodeid, newvalues): | |
| 21 ''' An auditor to print the value of the source of the | |
| 22 transaction that trigger this change. The sleep call | |
| 23 is used to delay the transaction so that multiple changes will | |
| 24 overlap. The expected output from this detector are 2 lines | |
| 25 with the same value for tx_Source. Tx source is: | |
| 26 None - Reported when using a script or it is an error if | |
| 27 the change arrives by another method. | |
| 28 "cli" - reported when using roundup-admin | |
|
5881
9938c40e03bc
Add "rest" and "xmlrpc" values for database tx_Source property
John Rouillard <rouilj@ieee.org>
parents:
5376
diff
changeset
|
29 "web" - reported when using html based web pages |
|
9938c40e03bc
Add "rest" and "xmlrpc" values for database tx_Source property
John Rouillard <rouilj@ieee.org>
parents:
5376
diff
changeset
|
30 "rest" - reported when using the /rest web API |
|
9938c40e03bc
Add "rest" and "xmlrpc" values for database tx_Source property
John Rouillard <rouilj@ieee.org>
parents:
5376
diff
changeset
|
31 "xmlrpc" - reported when using the /xmlrpc web API |
| 4781 | 32 "email" - reported when using an unautheticated email based technique |
| 33 "email-sig-openpgp" - reported when email with a valid pgp | |
| 34 signature is used | |
| 35 ''' | |
| 36 if __debug__ and False: | |
| 7033 | 37 print("\n tx_SourceCheckAudit(%s) db.tx_Source: %s" % ( |
| 38 nodeid, db.tx_Source)) | |
| 4781 | 39 |
| 40 newvalues['tx_Source'] = db.tx_Source | |
| 41 | |
| 42 # example use for real to prevent a change from happening if it's | |
| 43 # submited via email | |
| 44 # | |
| 45 # if db.tx_Source == "email": | |
| 46 # raise Reject, 'Change not allowed via email' | |
| 47 | |
| 7033 | 48 |
| 4781 | 49 def tx_SourceCheckReact(db, cl, nodeid, oldvalues): |
| 50 ''' An reactor to print the value of the source of the | |
| 51 transaction that trigger this change. The sleep call | |
| 52 is used to delay the transaction so that multiple changes will | |
| 53 overlap. The expected output from this detector are 2 lines | |
| 54 with the same value for tx_Source. Tx source is: | |
| 55 None - Reported when using a script or it is an error if | |
| 56 the change arrives by another method. | |
| 57 "cli" - reported when using roundup-admin | |
|
5881
9938c40e03bc
Add "rest" and "xmlrpc" values for database tx_Source property
John Rouillard <rouilj@ieee.org>
parents:
5376
diff
changeset
|
58 "web" - reported when using html based web pages |
|
9938c40e03bc
Add "rest" and "xmlrpc" values for database tx_Source property
John Rouillard <rouilj@ieee.org>
parents:
5376
diff
changeset
|
59 "rest" - reported when using the /rest web API |
|
9938c40e03bc
Add "rest" and "xmlrpc" values for database tx_Source property
John Rouillard <rouilj@ieee.org>
parents:
5376
diff
changeset
|
60 "xmlrpc" - reported when using the /xmlrpc web API |
| 4781 | 61 "email" - reported when using an unautheticated email based technique |
| 62 "email-sig-openpgp" - reported when email with a valid pgp | |
| 63 signature is used | |
| 64 ''' | |
| 65 | |
| 66 if __debug__ and False: | |
| 7033 | 67 print(" tx_SourceCheckReact(%s) db.tx_Source: %s" % ( |
| 68 nodeid, db.tx_Source)) | |
| 4781 | 69 |
| 70 | |
| 71 def init(db): | |
| 72 db.issue.audit('create', tx_SourceCheckAudit) | |
| 73 db.issue.audit('set', tx_SourceCheckAudit) | |
| 74 | |
| 75 db.issue.react('set', tx_SourceCheckReact) | |
| 76 db.issue.react('create', tx_SourceCheckReact) | |
| 77 | |
| 78 db.msg.audit('create', tx_SourceCheckAudit) |
