Skip to content

Commit

Permalink
mock mysql connection
Browse files Browse the repository at this point in the history
  • Loading branch information
adev4a committed Mar 1, 2024
1 parent cbafd77 commit 49dd949
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

from nats.aio.client import Client
import mock
import mysql

pytest_plugins = ('pytest_asyncio')

Expand Down Expand Up @@ -140,13 +141,16 @@ def test_update_mysql_entry(self):
async def test_new(self):

def args_based_return(*args, **kwargs):
# In progress returns successfully, the next call to update returns an exception. Required to break out of infinite loop while testing
if args == ("test_rosbag.mcap", str(ProcessingStatus.IN_PROGRESS.value)):
return True
return
else:
return Exception ("exception occurred")

config = Config()
mysql.connector.connect = MagicMock(return_value=MagicMock())
service_manager = ServiceManager(config)

service_manager.update_mysql_entry = MagicMock(side_effect=args_based_return)

with pytest.raises(Exception):
Expand Down

0 comments on commit 49dd949

Please sign in to comment.