"""Tests for MySQL connector.""" from unittest import mock from pymysql import cursors from pymysql import err import pytest from accounting.connectors import mysql @mock.patch('accounting.connectors.mysql.pymysql.connect') def test_get_connection(connect_mock): """Test get MySQL connection succeeds.""" connection = mysql.get_connection() assert connection connect_mock.assert_called_with( host='test_mysql_host', port=3306, user='test_mysql_user', password='test_mysql_password', db='test_mysql_db', charset='utf8', cursorclass=cursors.DictCursor ) @mock.patch( 'accounting.connectors.mysql.pymysql.connect', side_effect=err.MySQLError) def test_get_connection_failed(connect_mock): """Test get MySQL connection succeeds.""" with pytest.raises(err.MySQLError): mysql.get_connection()