Skip to content

Commit

Permalink
Merge branch 'master' into cleanup-tokens-test_cli
Browse files Browse the repository at this point in the history
  • Loading branch information
burnout87 authored Nov 13, 2023
2 parents 1bf53db + b211cf3 commit ddd651f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 11 additions & 1 deletion oda_api/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ def inspect(obj):

@tokencli.command()
@click.option("--disable-email", default=False, is_flag=True)
@click.option("--disable-matrix", default=False, is_flag=True)
@click.option("--matrix-room-id", default=None)
@click.option("--new-validity-hours", default=None, type=float)
@click.pass_obj
def modify(obj, disable_email, new_validity_hours):
def modify(obj, disable_email, disable_matrix, matrix_room_id, new_validity_hours):
token = obj['token']
decoded_token = obj['decoded_token']

Expand All @@ -140,6 +142,14 @@ def mutate_token_payload(payload):
# TODO: think if need this
# new_payload['msfail'] = False

if disable_matrix:
logger.info("disabling matrix submission")
new_payload['mxsub'] = False
new_payload['mxdone'] = False

if matrix_room_id is not None:
logger.info("setting matrix room id")
new_payload['mxroomid'] = matrix_room_id

if new_validity_hours is not None:
new_payload['exp'] = time.time() + new_validity_hours * 3600
Expand Down
13 changes: 8 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def test_token_inspect(token_placement, default_token, monkeypatch, caplog, tmpd
monkeypatch.setenv('ODA_TOKEN', '')

if token_placement == 'env':
monkeypatch.setenv('ODA_TOKEN', default_token)
monkeypatch.setenv('ODA_TOKEN', default_token)

elif token_placement == 'cwddotfile':
with open(oda_token_cwd_fn, "w") as f:
f.write(default_token)
Expand Down Expand Up @@ -57,15 +57,18 @@ def test_token_modify(default_token, secret_key, monkeypatch, caplog):
assert '"msdone": false' not in caplog.text

runner = CliRunner()
result = runner.invoke(cli.tokencli, ['-s', secret_key, 'modify', "--disable-email", "--new-validity-hours", "100"], obj={})
result = runner.invoke(cli.tokencli, ['-s', secret_key, 'modify', "--disable-email", "--new-validity-hours", "100", "--disable-matrix", "--matrix-room-id", "test_room_id:matrix.org"], obj={})
assert result.exit_code == 0

assert '"sub": "[email protected]"' in caplog.text
assert 'your current token payload:' in caplog.text
assert 'your new token payload:' in caplog.text
assert '"msdone": false' in caplog.text
assert '"mssub": false' in caplog.text

assert '"mssub": false' in caplog.text
assert '"mxdone": false' in caplog.text
assert '"mxsub": false' in caplog.text
assert '"mxroomid": "test_room_id:matrix.org"' in caplog.text

def test_get(dispatcher_live_fixture, caplog, monkeypatch, tmpdir):
runner = CliRunner()
result = runner.invoke(cli.cli, ['-u', dispatcher_live_fixture, 'get'], obj={})
Expand Down

0 comments on commit ddd651f

Please sign in to comment.