1. from unittest import mock
    
  2. 
    
  3. from django.core.management import call_command
    
  4. from django.core.management.base import CommandError
    
  5. from django.db import connection
    
  6. from django.test import SimpleTestCase
    
  7. 
    
  8. 
    
  9. class DbshellCommandTestCase(SimpleTestCase):
    
  10.     def test_command_missing(self):
    
  11.         msg = (
    
  12.             "You appear not to have the %r program installed or on your path."
    
  13.             % connection.client.executable_name
    
  14.         )
    
  15.         with self.assertRaisesMessage(CommandError, msg):
    
  16.             with mock.patch("subprocess.run", side_effect=FileNotFoundError):
    
  17.                 call_command("dbshell")