Skip to content

Commit

Permalink
clean up mock
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrai2 committed Dec 6, 2024
1 parent 80270f4 commit da006db
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions tests/unit/connector/test_http_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from logprep.factory import Factory
from logprep.framework.pipeline_manager import ThrottlingQueue
from logprep.util.defaults import ENV_NAME_LOGPREP_CREDENTIALS_FILE
from logprep.util.http import ThreadingHTTPServer
from tests.unit.connector.base import BaseInputTestCase


Expand Down Expand Up @@ -49,9 +48,7 @@ def create_credentials(tmp_path):
return str(credential_file_path)


original_thread_start = ThreadingHTTPServer.start


@mock.patch("logprep.connector.http.input.http.ThreadingHTTPServer", new=mock.MagicMock())
class TestHttpConnector(BaseInputTestCase):

CONFIG: dict = {
Expand Down Expand Up @@ -80,21 +77,22 @@ class TestHttpConnector(BaseInputTestCase):
]

def setup_method(self):
ThreadingHTTPServer.start = mock.MagicMock()
HttpInput.messages = ThrottlingQueue(
ctx=multiprocessing.get_context(), maxsize=self.CONFIG.get("message_backlog_size")
)
super().setup_method()
self.object.pipeline_index = 1
self.object.setup()
with mock.patch(
"logprep.connector.http.input.http.ThreadingHTTPServer", new=mock.MagicMock()
):
self.object.setup()
self.target = self.object.target
self.client = testing.TestClient(self.object.app)

def teardown_method(self):
while not self.object.messages.empty():
self.object.messages.get(timeout=0.001)
self.object.shut_down()
ThreadingHTTPServer.start = original_thread_start

def test_create_connector(self):
assert isinstance(self.object, HttpInput)
Expand Down Expand Up @@ -247,9 +245,6 @@ def test_get_next_returns_first_in_first_out_for_mixed_endpoints(self):
def test_get_next_returns_none_for_empty_queue(self):
assert self.object.get_next(0.001) is None

def test_http_server_is_of_instance_threading_http_server(self):
assert isinstance(self.object.http_server, ThreadingHTTPServer)

def test_server_starts_threaded_server(self):
message = {"message": "my message"}
for i in range(90):
Expand Down

0 comments on commit da006db

Please sign in to comment.