I am testing a class that uses bulk to index some documents.
Here is my code:
import mock
import unittest
import json
from elasticsearch.helpers import bulk
from ingestion.ingestor import Ingestor
class TestIngestor(unittest.TestCase):
def setUp(self):
self.ingestor = Ingestor()
@mock.patch("elasticsearch.helpers.bulk", mock.MagicMock(return_value=True))
def test_ingestor(self):
with open("tests/data/sample_payload.json", "r") as reader:
sample_messages = json.loads(reader.read())["Messages"]
actions = self.ingestor.ingest(sample_messages)
self.assertEqual(len(actions), 10)
However, the mocking does not seem to work... when I run it, I get a long list of connection refused errors.
How do I fix it?