<s> import mock <EOL> from unittest import skipIf <EOL> import django <EOL> import pytest <EOL> from django . core . management import CommandError , call_command <EOL> from django . db . utils import ConnectionHandler <EOL> from django . test import SimpleTestCase <EOL> from django . utils . six . moves import StringIO <EOL> command_connections = '<STR_LIT>' <EOL> sqlite = ConnectionHandler ( { <EOL> '<STR_LIT:default>' : { '<STR_LIT>' : '<STR_LIT>' } <EOL> } ) <EOL> full_db = ConnectionHandler ( { '<STR_LIT:default>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } <EOL> } <EOL> } } ) <EOL> socket_db = ConnectionHandler ( { '<STR_LIT:default>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } } ) <EOL> class DBParamsTests ( SimpleTestCase ) : <EOL> @ skipIf ( django . VERSION [ : <NUM_LIT:2> ] >= ( <NUM_LIT:1> , <NUM_LIT:10> ) , <EOL> '<STR_LIT>' ) <EOL> def test_invalid_number_of_databases ( self ) : <EOL> with pytest . raises ( CommandError ) as excinfo : <EOL> call_command ( '<STR_LIT>' , '<STR_LIT:default>' , '<STR_LIT:default>' , skip_checks = True ) <EOL> assert "<STR_LIT>" in str ( excinfo . value ) <EOL> def test_invalid_database ( self ) : <EOL> with pytest . raises ( CommandError ) as excinfo : <EOL> call_command ( '<STR_LIT>' , '<STR_LIT>' , skip_checks = True ) <EOL> assert "<STR_LIT>" in str ( excinfo . value ) <EOL> def test_invalid_both ( self ) : <EOL> with pytest . raises ( CommandError ) : <EOL> call_command ( '<STR_LIT>' , dsn = True , mysql = True , skip_checks = True ) <EOL> @ mock . patch ( command_connections , sqlite ) <EOL> def test_invalid_not_mysql ( self ) : <EOL> with pytest . raises ( CommandError ) as excinfo : <EOL> call_command ( '<STR_LIT>' , skip_checks = True ) <EOL> assert "<STR_LIT>" in str ( excinfo . value ) <EOL> @ mock . patch ( command_connections , full_db ) <EOL> def test_mysql_full ( self ) : <EOL> out = StringIO ( ) <EOL> call_command ( '<STR_LIT>' , stdout = out , skip_checks = True ) <EOL> output = out . getvalue ( ) <EOL> assert ( <EOL> output == <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> @ mock . patch ( command_connections , socket_db ) <EOL> def test_mysql_socket ( self ) : <EOL> out = StringIO ( ) <EOL> call_command ( '<STR_LIT>' , stdout = out , skip_checks = True ) <EOL> output = out . getvalue ( ) <EOL> assert output == "<STR_LIT>" <EOL> @ mock . patch ( command_connections , full_db ) <EOL> def test_dsn_full ( self ) : <EOL> out = StringIO ( ) <EOL> err = StringIO ( ) <EOL> call_command ( '<STR_LIT>' , '<STR_LIT:default>' , dsn = True , <EOL> stdout = out , stderr = err , skip_checks = True ) <EOL> output = out . getvalue ( ) <EOL> assert ( <EOL> output == <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> errors = err . getvalue ( ) <EOL> assert "<STR_LIT>" in errors <EOL> @ mock . patch ( command_connections , socket_db ) <EOL> def test_dsn_socket ( self ) : <EOL> out = StringIO ( ) <EOL> err = StringIO ( ) <EOL> call_command ( '<STR_LIT>' , dsn = True , <EOL> stdout = out , stderr = err , skip_checks = True ) <EOL> output = out . getvalue ( ) <EOL> assert output == '<STR_LIT>' <EOL> errors = err . getvalue ( ) <EOL> assert errors == "<STR_LIT>" </s>
