Skip to content

Commit

Permalink
Fixed test_default_ssl_context for the case when certifi points to sy…
Browse files Browse the repository at this point in the history
…stem certificates
  • Loading branch information
vmagamedov committed Apr 2, 2023
1 parent 04dcab3 commit 90eb869
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions tests/test_client_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest.mock import patch, ANY

import pytest
import certifi

from grpclib.client import Channel
from grpclib.testing import ChannelFor
Expand Down Expand Up @@ -35,14 +36,13 @@ async def create_connection(*args, **kwargs):
po.assert_awaited_once_with(ANY, '127.0.0.1', 50051, ssl=None)


@pytest.mark.asyncio
async def test_default_ssl_context():
certifi_channel = Channel(ssl=True)
with patch.dict('sys.modules', {'certifi': None}):
system_channel = Channel(ssl=True)

certifi_certs = certifi_channel._ssl.get_ca_certs(binary_form=True)
system_certs = system_channel._ssl.get_ca_certs(binary_form=True)
def test_default_ssl_context():
with patch.object(certifi, "where", return_value=certifi.where()) as po:
certifi_channel = Channel(ssl=True)
assert certifi_channel._ssl
po.assert_called_once()

assert certifi_certs
assert certifi_certs != system_certs
with patch.object(certifi, "where", side_effect=AssertionError):
with patch.dict("sys.modules", {"certifi": None}):
system_channel = Channel(ssl=True)
assert system_channel._ssl

0 comments on commit 90eb869

Please sign in to comment.