diff --git a/tests/test_cli.py b/tests/test_cli.py index 4bd98cf2..f07e89d7 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,6 +1,7 @@ import json import logging import os +import sys import shutil import tempfile import unittest @@ -518,20 +519,40 @@ def test_license_with_file(self, fetch_database_url): print(result.stdout) self.assertEqual(result.exit_code, 0) + @patch('safety.auth.cli.get_auth_info', return_value={'email': 'test@test.com'}) + @patch('safety.auth.cli.is_email_verified', return_value=True) @patch('builtins.input', lambda *args: '') - def test_debug_flag(self): + def test_debug_flag(self, mock_get_auth_info, mock_is_email_verified): result = self.runner.invoke(cli.cli, ['--debug', 'scan']) - print(result.output) + assert result.exit_code == 0, f"CLI exited with code {result.exit_code} and output: {result.output} and error: {result.stderr}" assert "for known security issues using default" in result.output + @patch('safety.auth.cli.get_auth_info', return_value={'email': 'test@test.com'}) + @patch('safety.auth.cli.is_email_verified', return_value=True) @patch('builtins.input', lambda *args: '') - def test_debug_flag_with_value_1(self): - result = self.runner.invoke(cli.cli, ['--debug', '1', 'scan']) - print(result.output) + def test_debug_flag_with_value_1(self, mock_get_auth_info, mock_is_email_verified): + # Simulate the command line arguments including the preprocessing + sys.argv = ['safety', '--debug', '1', 'scan'] + cli.preprocess_args() # Run the preprocess function to adjust the arguments + + # Extract the preprocessed arguments from sys.argv + preprocessed_args = sys.argv[1:] # Exclude the script name 'safety' + + result = self.runner.invoke(cli.cli, preprocessed_args) + assert result.exit_code == 0, f"CLI exited with code {result.exit_code} and output: {result.output} and error: {result.stderr}" assert "for known security issues using default" in result.output + @patch('safety.auth.cli.get_auth_info', return_value={'email': 'test@test.com'}) # Patch the auth info retrieval method + @patch('safety.auth.cli.is_email_verified', return_value=True) # Patch the email verification check method @patch('builtins.input', lambda *args: '') - def test_debug_flag_with_value_true(self): - result = self.runner.invoke(cli.cli, ['--debug', 'true', 'scan']) - print(result.output) + def test_debug_flag_with_value_true(self, mock_get_auth_info, mock_is_email_verified): + # Simulate the command line arguments including the preprocessing + sys.argv = ['safety', '--debug', 'true', 'scan'] + cli.preprocess_args() # Run the preprocess function to adjust the arguments + + # Extract the preprocessed arguments from sys.argv + preprocessed_args = sys.argv[1:] # Exclude the script name 'safety' + + result = self.runner.invoke(cli.cli, preprocessed_args) + assert result.exit_code == 0, f"CLI exited with code {result.exit_code} and output: {result.output} and error: {result.stderr}" assert "for known security issues using default" in result.output