Mock SSLContext in the unit tests

This commit is contained in:
Vladan Popovic 2020-09-06 10:51:10 +02:00
parent f9bfc8a2d1
commit 8239cf11da
3 changed files with 14 additions and 2 deletions

View File

@ -10,6 +10,10 @@ def config():
'kafka': { 'kafka': {
'servers': ["localhost:9992"], 'servers': ["localhost:9992"],
'topic': "sample", 'topic': "sample",
'cafile': "/dev/null",
'cert': "/dev/null",
'key': "/dev/null",
'passwd': "",
}, },
'postgres': { 'postgres': {
'dbhost': "localhost", 'dbhost': "localhost",
@ -34,6 +38,10 @@ def config_invalid():
'kafka': { 'kafka': {
'servers': ["localhost:9992"], 'servers': ["localhost:9992"],
'topic': "sample", 'topic': "sample",
'cafile': "",
'cert': "",
'key': "",
'passwd': "",
}, },
'postgres': { 'postgres': {
'dbhost': "localhost", 'dbhost': "localhost",
@ -41,6 +49,7 @@ def config_invalid():
'dbname': "chweb", 'dbname': "chweb",
'dbuser': "vladan", 'dbuser': "vladan",
'dbpass': "", 'dbpass': "",
'dbcert': "",
}, },
'sites': [{ 'sites': [{
'url': "https://dsadakjhkjsahkjh.com", 'url': "https://dsadakjhkjsahkjh.com",

View File

@ -1,13 +1,14 @@
import asyncio import asyncio
import aiokafka import aiokafka
from mock import Mock, AsyncMock from mock import AsyncMock, Mock, patch
import pytest import pytest
from chweb.consumer import Consumer from chweb.consumer import Consumer
@pytest.mark.asyncio @pytest.mark.asyncio
@patch('ssl.SSLContext')
async def test_consumer_called(check, config, event_loop): async def test_consumer_called(check, config, event_loop):
consumer = Consumer(config, Mock(), event_loop, Mock()) consumer = Consumer(config, Mock(), event_loop, Mock())

View File

@ -1,13 +1,14 @@
import asyncio import asyncio
import aiokafka import aiokafka
from mock import Mock, AsyncMock from mock import AsyncMock, Mock, patch
import pytest import pytest
from chweb.collector import Producer from chweb.collector import Producer
@pytest.mark.asyncio @pytest.mark.asyncio
@patch('ssl.SSLContext')
async def test_producer_called(check, config, event_loop): async def test_producer_called(check, config, event_loop):
queue = asyncio.Queue() queue = asyncio.Queue()
producer = Producer(config, Mock(), event_loop, queue) producer = Producer(config, Mock(), event_loop, queue)
@ -23,6 +24,7 @@ async def test_producer_called(check, config, event_loop):
@pytest.mark.asyncio @pytest.mark.asyncio
@patch('ssl.SSLContext')
async def test_producer_called_invalid(config, event_loop): async def test_producer_called_invalid(config, event_loop):
queue = asyncio.Queue() queue = asyncio.Queue()
producer = Producer(config, Mock(), event_loop, queue) producer = Producer(config, Mock(), event_loop, queue)