mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-08-03 12:44:25 -07:00
fix warning baseexception class error
This commit is contained in:
parent
4b14ac1b50
commit
12a95c4446
3 changed files with 17 additions and 13 deletions
|
@ -72,10 +72,11 @@ def test_stop_group_replication():
|
||||||
def test_start_group_replication_fail():
|
def test_start_group_replication_fail():
|
||||||
"""Test startgroupreplication function with failure."""
|
"""Test startgroupreplication function with failure."""
|
||||||
from ansible_collections.community.mysql.plugins.modules.mysql_replication import startgroupreplication
|
from ansible_collections.community.mysql.plugins.modules.mysql_replication import startgroupreplication
|
||||||
|
from ..utils import MockWarning
|
||||||
|
|
||||||
# Create a mock mysql_driver with a Warning attribute
|
# Create a mock mysql_driver with a Warning attribute
|
||||||
class MockDriver:
|
class MockDriver:
|
||||||
Warning = MockCursor.Warning
|
Warning = MockWarning
|
||||||
|
|
||||||
# Save the original mysql_driver
|
# Save the original mysql_driver
|
||||||
from ansible_collections.community.mysql.plugins.modules import mysql_replication
|
from ansible_collections.community.mysql.plugins.modules import mysql_replication
|
||||||
|
@ -101,10 +102,11 @@ def test_start_group_replication_fail():
|
||||||
def test_stop_group_replication_fail():
|
def test_stop_group_replication_fail():
|
||||||
"""Test stopgroupreplication function with failure."""
|
"""Test stopgroupreplication function with failure."""
|
||||||
from ansible_collections.community.mysql.plugins.modules.mysql_replication import stopgroupreplication
|
from ansible_collections.community.mysql.plugins.modules.mysql_replication import stopgroupreplication
|
||||||
|
from ..utils import MockWarning
|
||||||
|
|
||||||
# Create a mock mysql_driver with a Warning attribute
|
# Create a mock mysql_driver with a Warning attribute
|
||||||
class MockDriver:
|
class MockDriver:
|
||||||
Warning = MockCursor.Warning
|
Warning = MockWarning
|
||||||
|
|
||||||
# Save the original mysql_driver
|
# Save the original mysql_driver
|
||||||
from ansible_collections.community.mysql.plugins.modules import mysql_replication
|
from ansible_collections.community.mysql.plugins.modules import mysql_replication
|
||||||
|
|
|
@ -76,10 +76,11 @@ def test_stop_group_replication():
|
||||||
def test_start_group_replication_fail():
|
def test_start_group_replication_fail():
|
||||||
"""Test startgroupreplication function with failure."""
|
"""Test startgroupreplication function with failure."""
|
||||||
from ansible_collections.community.mysql.plugins.modules.mysql_replication import startgroupreplication
|
from ansible_collections.community.mysql.plugins.modules.mysql_replication import startgroupreplication
|
||||||
|
from ..utils import MockWarning
|
||||||
|
|
||||||
# Create a mock mysql_driver with a Warning attribute
|
# Create a mock mysql_driver with a Warning attribute
|
||||||
class MockDriver:
|
class MockDriver:
|
||||||
Warning = MockCursor.Warning
|
Warning = MockWarning
|
||||||
|
|
||||||
# Save the original mysql_driver
|
# Save the original mysql_driver
|
||||||
from ansible_collections.community.mysql.plugins.modules import mysql_replication
|
from ansible_collections.community.mysql.plugins.modules import mysql_replication
|
||||||
|
@ -105,10 +106,11 @@ def test_start_group_replication_fail():
|
||||||
def test_stop_group_replication_fail():
|
def test_stop_group_replication_fail():
|
||||||
"""Test stopgroupreplication function with failure."""
|
"""Test stopgroupreplication function with failure."""
|
||||||
from ansible_collections.community.mysql.plugins.modules.mysql_replication import stopgroupreplication
|
from ansible_collections.community.mysql.plugins.modules.mysql_replication import stopgroupreplication
|
||||||
|
from ..utils import MockWarning
|
||||||
|
|
||||||
# Create a mock mysql_driver with a Warning attribute
|
# Create a mock mysql_driver with a Warning attribute
|
||||||
class MockDriver:
|
class MockDriver:
|
||||||
Warning = MockCursor.Warning
|
Warning = MockWarning
|
||||||
|
|
||||||
# Save the original mysql_driver
|
# Save the original mysql_driver
|
||||||
from ansible_collections.community.mysql.plugins.modules import mysql_replication
|
from ansible_collections.community.mysql.plugins.modules import mysql_replication
|
||||||
|
|
|
@ -19,22 +19,22 @@ class dummy_cursor_class():
|
||||||
return [self.output]
|
return [self.output]
|
||||||
|
|
||||||
|
|
||||||
class MockCursor:
|
# Define MockWarning at module level to ensure it's a proper exception class
|
||||||
Warning = None
|
class MockWarning(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
def __init__(self, status="ONLINE", warning=None):
|
|
||||||
|
class MockCursor:
|
||||||
|
# Set the Warning class at the class level
|
||||||
|
Warning = MockWarning
|
||||||
|
|
||||||
|
def __init__(self, status="ONLINE"):
|
||||||
self.status = status
|
self.status = status
|
||||||
self.executed_queries = []
|
self.executed_queries = []
|
||||||
self.Warning = warning
|
|
||||||
|
|
||||||
def execute(self, query):
|
def execute(self, query):
|
||||||
self.executed_queries.append(query)
|
self.executed_queries.append(query)
|
||||||
if self.status == "ERROR":
|
if self.status == "ERROR":
|
||||||
# Create a custom exception that mimics mysql_driver.Warning
|
|
||||||
class MockWarning(Exception):
|
|
||||||
pass
|
|
||||||
# Make it available as a class attribute for tests to use
|
|
||||||
MockCursor.Warning = MockWarning
|
|
||||||
raise MockWarning("Mocked execution error")
|
raise MockWarning("Mocked execution error")
|
||||||
|
|
||||||
def fetchone(self):
|
def fetchone(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue