From 63c9f9f2190c5571637aa06ecf5f8857011af5f7 Mon Sep 17 00:00:00 2001 From: Marcelo Jorge Vieira Date: Wed, 26 Jan 2022 17:27:47 -0300 Subject: [PATCH] doctor: fix errors when there is no config (#1397) --- tests/snapshots/snap_test_doctor.py | 39 +++++++++++++++++++++++++++++ tests/test_doctor.py | 14 +++++++++++ thumbor/doctor.py | 6 +++-- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/tests/snapshots/snap_test_doctor.py b/tests/snapshots/snap_test_doctor.py index 168101f71..03b10f756 100644 --- a/tests/snapshots/snap_test_doctor.py +++ b/tests/snapshots/snap_test_doctor.py @@ -169,3 +169,42 @@ Don't forget to copy this log and add it to the description. Open an issue at https://github.com/thumbor/thumbor/issues/new ''' + +snapshots['test_get_doctor_output_no_config 1'] = ''' +Thumbor doctor will analyze your install and verify if everything is working as expected. + +Verifying libraries support... + +✅ pycurl is installed correctly. +✅ cairosvg is installed correctly. +✅ cv2 is installed correctly. + +Verifying thumbor compiled extensions... + +✅ _alpha +✅ _bounding_box +✅ _brightness +✅ _colorize +✅ _composite +✅ _contrast +✅ _convolution +✅ _curve +✅ _equalize +✅ _fill +✅ _nine_patch +✅ _noise +✅ _rgb +✅ _round_corner +✅ _saturation +✅ _sharpen + +Verifying extension programs... + +✅ jpegtran is installed correctly. +✅ ffmpeg is installed correctly. +✅ gifsicle is installed correctly. +Verifying security... + + +🎉 Congratulations! No errors found! 🎉 +''' diff --git a/tests/test_doctor.py b/tests/test_doctor.py index 568048418..25f43dc3d 100644 --- a/tests/test_doctor.py +++ b/tests/test_doctor.py @@ -24,3 +24,17 @@ def test_get_doctor_output(snapshot, capsys): ) result = capsys.readouterr() snapshot.assert_match(result.out) + + +def test_get_doctor_output_no_config(snapshot, capsys): + run_doctor( + { + "nocolor": True, + "config": None, + }, + print_version=False, + exit_with_error=False, + check_pyexiv=False, + ) + result = capsys.readouterr() + snapshot.assert_match(result.out) diff --git a/thumbor/doctor.py b/thumbor/doctor.py index 58c345d87..b0b9540c6 100644 --- a/thumbor/doctor.py +++ b/thumbor/doctor.py @@ -72,7 +72,7 @@ def newline(): def check_extensibility_modules(cfg): if cfg is None: - return None + return [] newline() errors = [] @@ -318,6 +318,9 @@ def check_security(cfg): errors = [] warnings = [] + if cfg is None: + return errors, warnings + if cfg.SECURITY_KEY == "MY_SECURE_KEY": print(cf.bold_red(f"{CROSS} Using default security key.")) @@ -393,7 +396,6 @@ def check_everything(cfg, check_pyexiv): def print_results(warnings, errors): if not warnings and not errors: print(cf.bold_green("🎉 Congratulations! No errors found! 🎉")) - sys.exit(1) return print(cf.bold_red("😞 Oh no! We found some things that could improve... 😞"))