コード例 #1
0
ファイル: test_mysql.py プロジェクト: nicholasmhughes/salt
def test__connect_mysqldb():
    """
    Test the _connect function in the MySQL module
    """
    mysqldb_connect_mock = MagicMock(autospec=True,
                                     return_value=MockMySQLConnect())
    with patch.dict(mysql.__salt__, {"config.option": MagicMock()}):
        with patch("MySQLdb.connect", mysqldb_connect_mock):
            mysql._connect()
            assert "mysql.error" not in mysql.__context__
コード例 #2
0
 def test__connect_mysqldb(self):
     """
     Test the _connect function in the MySQL module
     """
     with patch.dict(mysql.__salt__, {"config.option": MagicMock()}):
         with patch("MySQLdb.connect", return_value=MockMySQLConnect()):
             ret = mysql._connect()
             self.assertNotIn("mysql.error", mysql.__context__)
コード例 #3
0
ファイル: test_mysql.py プロジェクト: nicholasmhughes/salt
def test__connect_mysqldb_exception():
    """
    Test the _connect function in the MySQL module
    """
    with patch.dict(mysql.__salt__, {"config.option": MagicMock()}):
        with patch(
                "MySQLdb.connect",
                side_effect=mysql.OperationalError(
                    1698, "Access denied for user 'root'@'localhost'"),
        ):
            ret = mysql._connect()
            assert "mysql.error" in mysql.__context__
            assert (
                mysql.__context__["mysql.error"] ==
                "MySQL Error 1698: Access denied for user 'root'@'localhost'")
コード例 #4
0
ファイル: test_mysql.py プロジェクト: noelmcloughlin/salt
def test__connect_mysqldb():
    """
    Test the _connect function in the MySQL module
    """
    mysqldb_connect_mock = MagicMock(autospec=True,
                                     return_value=MockMySQLConnect())
    with patch.dict(mysql.__salt__, {"config.option": MagicMock()}):
        with patch("MySQLdb.connect", mysqldb_connect_mock):
            ret = mysql._connect()
            assert "mysql.error" not in mysql.__context__
            # If 'use_unicode' is activated here, it would retrieve utf8 strings
            # as unicode() objects in salt and we do not want that. So it needs
            # to be False
            _, connargs = mysqldb_connect_mock.call_args
            assert connargs["use_unicode"] is False
コード例 #5
0
 def test__connect_pymysql_exception(self):
     """
     Test the _connect function in the MySQL module
     """
     with patch.dict(mysql.__salt__, {"config.option": MagicMock()}):
         with patch(
                 "MySQLdb.connect",
                 side_effect=pymysql.err.InternalError(
                     1698, "Access denied for user 'root'@'localhost'"),
         ):
             ret = mysql._connect()
             self.assertIn("mysql.error", mysql.__context__)
             self.assertEqual(
                 mysql.__context__["mysql.error"],
                 "MySQL Error 1698: Access denied for user 'root'@'localhost'",
             )