Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pmi popup #120

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions home-choice-pro/tests/test_views/test_main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import pytest
import os
from PyQt5.QtWidgets import QMessageBox
from PyQt5 import QtCore
from views.main_window import MainWindow

Expand All @@ -33,6 +34,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)

Expand Down Expand Up @@ -97,8 +113,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")
Expand Down Expand Up @@ -152,7 +166,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()
Expand All @@ -171,7 +185,7 @@ def test_calculate_house(main_window, 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()
Expand All @@ -194,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()
Expand Down
10 changes: 10 additions & 0 deletions home-choice-pro/views/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Loading