-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""PyTest configuration and fixtures.""" | ||
from typing import Any | ||
from unittest.mock import MagicMock | ||
import jaydebeapi | ||
import pytest | ||
from py_graphql_sql import Connection, Cursor, connect | ||
|
||
@pytest.fixture | ||
def mock_jdbc_connection() -> MagicMock: | ||
"""Create a mock JDBC connection.""" | ||
conn = MagicMock() | ||
conn.cursor.return_value = MagicMock() | ||
return conn | ||
|
||
@pytest.fixture | ||
def mock_connection(monkeypatch: pytest.MonkeyPatch, mock_jdbc_connection: MagicMock) -> Connection: | ||
"""Create a mock connection.""" | ||
def mock_connect(*args: Any, **kwargs: Any) -> MagicMock: | ||
return mock_jdbc_connection | ||
|
||
monkeypatch.setattr(jaydebeapi, 'connect', mock_connect) | ||
return connect('driver', 'url') | ||
|
||
@pytest.fixture | ||
def mock_cursor(mock_connection: Connection) -> Cursor: | ||
"""Create a mock cursor.""" | ||
return mock_connection.cursor() |