Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jiezhen-chen committed Aug 4, 2023
1 parent bf12a24 commit 4c98a0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Empty file added test/config.ini
Empty file.
9 changes: 9 additions & 0 deletions test/unit/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from collections import deque
from decimal import Decimal
from unittest.mock import patch
from unittest import mock
import socket

import pytest # type: ignore

Expand All @@ -12,6 +14,7 @@
IntegrityError,
InterfaceError,
ProgrammingError,
OperationalError
)
from redshift_connector.config import (
ClientProtocolVersion,
Expand Down Expand Up @@ -328,3 +331,9 @@ def test_client_os_version_is_not_present():

with patch("platform.platform", side_effect=Exception("not for you")):
assert mock_connection.client_os_version == "unknown"

def test_socket_timeout_operational_error():
with mock.patch('socket.socket.bind') as mock_socket:
mock_socket.side_effect = socket.timeout
with pytest.raises(OperationalError):
Connection(user='mock_user', password='mock_password', host='localhost', port=8080, database='mocked')

0 comments on commit 4c98a0c

Please sign in to comment.