From cdff84c943101e211c7513ba6f77f0ccb59aec19 Mon Sep 17 00:00:00 2001 From: Josh Voyles Date: Wed, 26 Jun 2024 07:20:52 -0400 Subject: [PATCH 1/2] Resolved: #83, QMessageBox warning pop up --- .../tests/test_views/test_main_window.py | 21 ++++++++++++++++--- home-choice-pro/views/main_window.py | 12 ++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/home-choice-pro/tests/test_views/test_main_window.py b/home-choice-pro/tests/test_views/test_main_window.py index 222c673..d616751 100644 --- a/home-choice-pro/tests/test_views/test_main_window.py +++ b/home-choice-pro/tests/test_views/test_main_window.py @@ -16,7 +16,9 @@ import pytest import os +from PyQt5.QtWidgets import QMessageBox, QApplication from PyQt5 import QtCore +from PyQt5.QtTest import QTest from views.main_window import MainWindow PATH_TO_GUIDE = os.path.join( @@ -33,6 +35,21 @@ def main_window(qtbot): yield main_window +@pytest.fixture +def mock_qmessagebox(qtbot): + """This fixture sinks the QMessageBox to prevent the pop up""" + + def mock_messagebox(*args, **kwargs): + msgbox = QMessageBox() + msgbox.setText("Mock Message Box") + msgbox.setStandardButtons(QMessageBox.Ok) + return msgbox + + QMessageBox.warning = mock_messagebox + QMessageBox.information = mock_messagebox + QMessageBox.critical = mock_messagebox + + def test_main_window(main_window): assert isinstance(main_window, MainWindow) @@ -97,8 +114,6 @@ def test_verify_digits(main_window): assert main_window.verify_digits() is False -# I had trouble closing the error box. Since it's small, I've ommited it. - def test_monthly_payment_edit(main_window, qtbot): main_window.ui.monthlyPaymentEdit.clear() qtbot.keyClicks(main_window.ui.monthlyPaymentEdit, "12345") @@ -152,7 +167,7 @@ def test_PMI_edit(main_window, qtbot): assert main_window.ui.PMIEdit.text() == "0.34" -def test_calculate_house(main_window, qtbot): +def test_calculate_house(main_window, mock_qmessagebox, qtbot): """Tests known values and validates the result""" # enter values in gui main_window.ui.monthlyPaymentEdit.clear() diff --git a/home-choice-pro/views/main_window.py b/home-choice-pro/views/main_window.py index 3dec269..8fdd488 100644 --- a/home-choice-pro/views/main_window.py +++ b/home-choice-pro/views/main_window.py @@ -16,7 +16,7 @@ import re import os -from PyQt5.QtWidgets import QMainWindow, QMessageBox +from PyQt5.QtWidgets import QMainWindow, QMessageBox, QCheckBox from models.affordability_calculator import AffordabilityCalculator as af from views.main_window_ui import Ui_MainWindow @@ -42,6 +42,7 @@ def __init__(self): self.setWindowTitle("Home Choice Pro") self.guide = self.open_guide() self.ui.guideLabel.setText(self.guide) + self.pmi_warned = False self.edit_boxes = [ self.ui.monthlyPaymentEdit, @@ -102,6 +103,9 @@ def display_results(self): f"Down Payment: {str(self.downpayment)}%" ) + if int(self.downpayment) < 20: + self.display_PMI_warning() + def reset(self): """Resets all edit boxes to 0.""" for edit in self.edit_boxes: @@ -140,3 +144,9 @@ def display_calculator_page(self): def display_user_guide(self): """Set stacked widgeted index to show user guide""" self.ui.stackedWidget.setCurrentIndex(3) + + def display_PMI_warning(self): + if not self.pmi_warned: + message = "Private Mortage Insurance typically required with down payments less than 20 percent" + QMessageBox.warning(self, "PMI Error", message) + self.pmi_warned = True From c23bda6e8056bf6c43dfa9db9988dbe8a1c48ff5 Mon Sep 17 00:00:00 2001 From: Josh Voyles Date: Wed, 26 Jun 2024 07:26:12 -0400 Subject: [PATCH 2/2] Removed extra code from testing --- home-choice-pro/tests/test_views/test_main_window.py | 7 +++---- home-choice-pro/views/main_window.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/home-choice-pro/tests/test_views/test_main_window.py b/home-choice-pro/tests/test_views/test_main_window.py index d616751..43f6666 100644 --- a/home-choice-pro/tests/test_views/test_main_window.py +++ b/home-choice-pro/tests/test_views/test_main_window.py @@ -16,9 +16,8 @@ import pytest import os -from PyQt5.QtWidgets import QMessageBox, QApplication +from PyQt5.QtWidgets import QMessageBox from PyQt5 import QtCore -from PyQt5.QtTest import QTest from views.main_window import MainWindow PATH_TO_GUIDE = os.path.join( @@ -186,7 +185,7 @@ def test_calculate_house(main_window, mock_qmessagebox, qtbot): assert main_window.ui.downPaymentHeaderLabel.text() == "Down Payment: 0%" -def test_calculate_house_2(main_window, qtbot): +def test_calculate_house_2(main_window, mock_qmessagebox, qtbot): """Tests known values and validates the result""" # enter values in gui main_window.ui.monthlyPaymentEdit.clear() @@ -209,7 +208,7 @@ def test_calculate_house_2(main_window, qtbot): assert main_window.ui.downPaymentHeaderLabel.text() == "Down Payment: 18%" -def test_calculate_house_3(main_window, qtbot): +def test_calculate_house_3(main_window, mock_qmessagebox, qtbot): """Third calculation test adding PMI and insurance""" # enter values in gui main_window.ui.monthlyPaymentEdit.clear() diff --git a/home-choice-pro/views/main_window.py b/home-choice-pro/views/main_window.py index 8fdd488..ff444c4 100644 --- a/home-choice-pro/views/main_window.py +++ b/home-choice-pro/views/main_window.py @@ -16,7 +16,7 @@ import re import os -from PyQt5.QtWidgets import QMainWindow, QMessageBox, QCheckBox +from PyQt5.QtWidgets import QMainWindow, QMessageBox from models.affordability_calculator import AffordabilityCalculator as af from views.main_window_ui import Ui_MainWindow