diff --git a/tests/controller/test_mainFrameController.py b/tests/controller/test_mainFrameController.py index 1e8c5c2..686b999 100644 --- a/tests/controller/test_mainFrameController.py +++ b/tests/controller/test_mainFrameController.py @@ -3,7 +3,6 @@ import os import pytest from unittest.mock import MagicMock, patch -# Add the src directory to the Python path src_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'src')) sys.path.insert(0, src_dir) @@ -34,7 +33,6 @@ def test_init(controller): assert isinstance(controller.db, MagicMock) assert isinstance(controller.rater, MagicMock) - def test_get_text_data(controller): controller.frame.entry_url.get.return_value = "https://example.com" controller.frame.input_textbox.get.return_value = "Sample text" @@ -65,13 +63,19 @@ def test_press_check_button(controller, result, expected_result_color, confidenc controller._predict = MagicMock(return_value=text_data) controller._add_to_db = MagicMock() controller.update_provider_list = MagicMock() - controller.rater.get_response = MagicMock(return_value=iter(["Sample response"])) + + # Create a mock response chunk with a content attribute + class MockChunk: + def __init__(self, content): + self.content = content + + # Mocking get_response to return a list of MockChunk instances + mock_response = [MockChunk("Sample response")] + controller.rater.get_response = MagicMock(return_value=mock_response) # Mock frame and its subcomponents controller.frame = MagicMock() - controller.frame.result_label = MagicMock() controller.frame.result_label.configure = MagicMock() - controller.frame.confidence_label = MagicMock() controller.frame.confidence_label.configure = MagicMock() controller.frame.output_textbox = MagicMock() controller.frame.output_textbox.insert = MagicMock() @@ -84,9 +88,10 @@ def test_press_check_button(controller, result, expected_result_color, confidenc controller.frame.confidence_label.configure.assert_any_call(text=f"{confidence * 100:.2f}%") controller.frame.confidence_label.configure.assert_any_call(fg_color=expected_confidence_color) - # Additional assertion to verify that the output textbox is updated - controller.frame.output_textbox.insert.assert_called_with("end", "Sample response") - + # Additional assertion to verify that the output textbox is updated with the response content + controller.frame.output_textbox.insert.assert_called_with("end", mock_response[0].content) + + def test_predict(controller): text_data = TextData(text="Sample text") controller.model_inference.predict.return_value = { @@ -102,15 +107,13 @@ def test_predict(controller): assert result.is_fake_news == False def test_add_to_db(controller): - # Adjust the fields to match the actual insert_data arguments text_data = TextData(url="https://example.com", provider="Example Provider", is_fake_news=False) controller._add_to_db(text_data) controller.db.insert_data.assert_called_with( url="https://example.com", - anbieter="example.com", # Adjusted to match actual expected field name + anbieter="example.com", is_fake_news=False ) - if __name__ == "__main__": pytest.main([__file__])