Commit d4a3df78 authored by matograine's avatar matograine
Browse files

TEST-REVOKE test errors on --now and --publish.

parent 5a89f9f4
Pipeline #12728 failed with stages
in 1 minute and 58 seconds
......@@ -25,6 +25,7 @@ import pytest
from click.testing import CliRunner
from duniterpy.api import bma, errors
from duniterpy.api.client import Client
from duniterpy.api.errors import DuniterError
from duniterpy.documents.identity import Identity
from duniterpy.documents.revocation import Revocation
......@@ -199,6 +200,11 @@ IdtyTimestamp: 703902-00002D6BC5E4FC540A4E188C3880A0ACCA06CD77017D26231A51531216
IdtySignature: 3RNQcKNI1VMmuCpK7wer8haOA959EQSDIR1v0Ue/7TpTCOmsU2zYCpC+tqgLQFxDX4A79sB61c11J5C/3Z/TCw==\
42D2vbIJnv2aGqUMbD+BF+eChzzGo4R3CVPAl5hpIGvoTcZQCfKBsRRlZDx6Gwn6lsJ3KLiIwPQeJKGYCW2YBg=="
error_code = 1005
error_message = "Document has unkown fields or wrong line ending format"
## patched functions
async def patch_get_id_block(node, number):
return idty_block
......@@ -224,6 +230,10 @@ async def patched_choose_identity(pubkey):
)
async def patched_send_bma_revoke_error(wot_useless, rev_doc_useless):
raise DuniterError({"ucode": error_code, "message": error_message})
### tests ###
# test cli dry-run
......@@ -784,6 +794,85 @@ def test_revoke_cli_publish(
assert expect in result.output
# test cli publish send errors
@pytest.mark.parametrize(
"display, file, user_input, expected",
[
(
False,
"",
"yes\n",
[
"| Public key |",
"Do you confirm sending this revocation document immediately?",
"ERROR: Revocation has not been sent: Document has unkown fields or wrong line ending format",
],
),
(
True,
"",
"yes\n",
[
"| Public key |",
"Do you confirm sending this revocation document immediately?",
"Version: 10",
"ERROR: Revocation has not been sent: Document has unkown fields or wrong line ending format",
],
),
(
False,
"test_doc",
"yes\n",
[
"| Public key |",
"Do you confirm sending this revocation document immediately?",
"ERROR: Revocation has not been sent: Document has unkown fields or wrong line ending format",
],
),
(
True,
"test_doc",
"yes\n",
[
"| Public key |",
"Do you confirm sending this revocation document immediately?",
"Version: 10",
"ERROR: Revocation has not been sent: Document has unkown fields or wrong line ending format",
],
),
],
)
def test_revoke_cli_publish_send_errors(
display, file, user_input, expected, monkeypatch
):
async def patched_lookup(node, id_pubkey):
return lookup_one
monkeypatch.setattr(bma.wot, "lookup", patched_lookup)
monkeypatch.setattr(HeadBlock, "get_head", patched_head_block_gtest)
monkeypatch.setattr(bma.blockchain, "block", patch_get_id_block)
monkeypatch.setattr(bma.wot, "revoke", patched_send_bma_revoke_error)
# prepare command
command = display_dry_options(display, False)
command.extend(["revoke", "--publish"])
if file:
command.extend(["--file", file])
else:
file = revoke.REVOCATION_LOCAL_PATH
# test publication
client = ClientInstance().client
runner = CliRunner()
with runner.isolated_filesystem():
with open(file, "w") as f:
f.write(rev_doc.signed_raw())
result = runner.invoke(cli, args=command, input=user_input)
for expect in expected:
assert expect in result.output
assert result.exit_code == 1
# test cli now
@pytest.mark.parametrize(
"display, dry_run, user_input, doc, expected",
......@@ -864,6 +953,51 @@ def test_revoke_cli_now(display, dry_run, user_input, doc, expected, monkeypatch
patched_send_bma_revoke.assert_not_awaited()
# test cli now errors
@pytest.mark.parametrize(
"display, user_input, doc, expected",
[
(
False,
"yes\n",
rev_doc,
[
"6upqFiJ66WV6N3bPc8x8y7rXT3syqKRmwnVyunCtEj7o",
"Do you confirm sending this revocation document immediately?",
"ERROR: Revocation has not been sent: Document has unkown fields or wrong line ending format",
],
),
(
True,
"yes\n",
rev_doc,
[
"6upqFiJ66WV6N3bPc8x8y7rXT3syqKRmwnVyunCtEj7o",
"Do you confirm sending this revocation document immediately?",
"Version: 10",
"ERROR: Revocation has not been sent: Document has unkown fields or wrong line ending format",
],
),
],
)
def test_revoke_cli_now_errors(display, user_input, doc, expected, monkeypatch):
monkeypatch.setattr(auth, "auth_method", patched_auth_method_Claude)
monkeypatch.setattr(HeadBlock, "get_head", patched_head_block_gtest)
monkeypatch.setattr(wot, "choose_identity", patched_choose_identity)
monkeypatch.setattr(bma.blockchain, "block", patch_get_id_block)
monkeypatch.setattr(bma.wot, "revoke", patched_send_bma_revoke_error)
command = display_dry_options(display, False)
command.extend(["revoke", "--now"])
client = ClientInstance().client
result = CliRunner().invoke(cli, args=command, input=user_input)
for expect in expected:
assert expect in result.output
assert result.exit_code == 1
# test create_revocation_doc
@pytest.mark.parametrize("idty, lookup", [(identity, lookup_one)])
def test_create_revocation_doc(idty, lookup):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment