From 9a353cea3dbffdb8d185f5582039bffaf9c30ef3 Mon Sep 17 00:00:00 2001 From: matograine <tom.ngr@zaclys.net> Date: Sun, 22 Mar 2020 11:39:39 +0100 Subject: [PATCH] [test] #197: add test for auth_method() * add patched auth functions --- tests/patched/auth.py | 17 +++++++++++++++++ tests/test_auth.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 tests/patched/auth.py create mode 100644 tests/test_auth.py diff --git a/tests/patched/auth.py b/tests/patched/auth.py new file mode 100644 index 00000000..c681ed47 --- /dev/null +++ b/tests/patched/auth.py @@ -0,0 +1,17 @@ +# This file contains patches for auth functions. + + +def patched_auth_by_seed(): + return "call_auth_by_seed" + + +def patched_auth_by_wif(): + return "call_auth_by_wif" + + +def patched_auth_by_auth_file(): + return "call_auth_by_auth_file" + + +def patched_auth_by_scrypt(): + return "call_auth_by_scrypt" diff --git a/tests/test_auth.py b/tests/test_auth.py new file mode 100644 index 00000000..a238ee6d --- /dev/null +++ b/tests/test_auth.py @@ -0,0 +1,32 @@ +import pytest +import click + +from silkaj import auth + +from patched.auth import ( + patched_auth_by_seed, + patched_auth_by_wif, + patched_auth_by_auth_file, + patched_auth_by_scrypt, +) + +# test auth_method +@pytest.mark.parametrize( + "seed, file, wif, auth_method_called", + [ + (True, False, False, "call_auth_by_seed"), + (False, True, False, "call_auth_by_auth_file"), + (False, False, True, "call_auth_by_wif"), + (False, False, False, "call_auth_by_scrypt"), + ], +) +def test_auth_method(seed, file, wif, auth_method_called, monkeypatch): + monkeypatch.setattr("silkaj.auth.auth_by_seed", patched_auth_by_seed) + monkeypatch.setattr("silkaj.auth.auth_by_wif", patched_auth_by_wif) + monkeypatch.setattr("silkaj.auth.auth_by_auth_file", patched_auth_by_auth_file) + monkeypatch.setattr("silkaj.auth.auth_by_scrypt", patched_auth_by_scrypt) + ctx = click.Context( + click.Command(""), obj={"AUTH_SEED": seed, "AUTH_FILE": file, "AUTH_WIF": wif} + ) + with ctx: + assert auth_method_called == auth.auth_method() -- GitLab