Skip to content

Commit

Permalink
Fix patchings
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanpulver committed Jul 2, 2024
1 parent dd1696a commit 49699ca
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from safety import cli
from safety.models import CVE, SafetyRequirement, Severity, Vulnerability
from safety.util import Package, SafetyContext

from safety.auth.models import Auth
from safety_schemas.models.base import AuthenticationType

def get_vulnerability(vuln_kwargs=None, cve_kwargs=None, pkg_kwargs=None):
vuln_kwargs = {} if vuln_kwargs is None else vuln_kwargs
Expand Down Expand Up @@ -520,17 +521,21 @@ def test_license_with_file(self, fetch_database_url):
self.assertEqual(result.exit_code, 0)

@patch('safety.auth.cli.get_auth_info', return_value={'email': '[email protected]'})
@patch('safety.auth.cli.is_email_verified', return_value=True)
@patch.object(Auth, 'is_valid', return_value=True)
@patch('safety.auth.utils.SafetyAuthSession.get_authentication_type', return_value=AuthenticationType.TOKEN)
@patch('builtins.input', lambda *args: '')
def test_debug_flag(self, mock_get_auth_info, mock_is_email_verified):
@patch('safety.safety.fetch_database')
def test_debug_flag(self, mock_get_auth_info, mock_is_valid, mock_get_auth_type, mock_fetch_database):
result = self.runner.invoke(cli.cli, ['--debug', 'scan'])
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': '[email protected]'})
@patch('safety.auth.cli.is_email_verified', return_value=True)
@patch.object(Auth, 'is_valid', return_value=True)
@patch('safety.auth.utils.SafetyAuthSession.get_authentication_type', return_value=AuthenticationType.TOKEN)
@patch('builtins.input', lambda *args: '')
def test_debug_flag_with_value_1(self, mock_get_auth_info, mock_is_email_verified):
@patch('safety.safety.fetch_database')
def test_debug_flag_with_value_1(self, mock_get_auth_info, mock_is_valid, mock_get_auth_type, mock_fetch_database):
# 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
Expand All @@ -542,10 +547,12 @@ def test_debug_flag_with_value_1(self, mock_get_auth_info, mock_is_email_verifie
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': '[email protected]'}) # Patch the auth info retrieval method
@patch('safety.auth.cli.is_email_verified', return_value=True) # Patch the email verification check method
@patch('safety.auth.cli.get_auth_info', return_value={'email': '[email protected]'})
@patch.object(Auth, 'is_valid', return_value=True)
@patch('safety.auth.utils.SafetyAuthSession.get_authentication_type', return_value=AuthenticationType.TOKEN)
@patch('builtins.input', lambda *args: '')
def test_debug_flag_with_value_true(self, mock_get_auth_info, mock_is_email_verified):
@patch('safety.safety.fetch_database')
def test_debug_flag_with_value_true(self, mock_get_auth_info, mock_is_valid, mock_get_auth_type, mock_fetch_database):
# 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
Expand Down

0 comments on commit 49699ca

Please sign in to comment.