def test_fd_file_edit(self): edit_fd_win = interface.EditFoodDictWin(edit_entry_name='cereal') with patch.object(interface, 'FoodDictWin') as fd_win_mock, \ patch('healthhelper.interface.open', mock_open()) as open_mock: QTest.mouseClick(edit_fd_win.done_btn, Qt.LeftButton) open_mock.assert_called() fd_win_mock.assert_called()
def test_no_serving_size_given(self): """MessageWin should be called if the user doesn't provide an amount.""" edit_fd_win = interface.EditFoodDictWin() edit_fd_win.info1_layout.itemAt(1).widget().setText('cereal') edit_fd_win.info1_layout.itemAt(3).itemAt(0).widget().setText('') edit_fd_win.info1_layout.itemAt(3).itemAt(1).widget().setCurrentText( 'oz') with patch.object(interface, 'MessageWin') as message_win_mock: QTest.mouseClick(edit_fd_win.done_btn, Qt.LeftButton) message_win_mock.assert_called()
def test_duplicate_name_given(self): """MessageWin should be called if the user provides an already existing entry name when adding an entry.""" edit_fd_win = interface.EditFoodDictWin() edit_fd_win.info1_layout.itemAt(1).widget().setText('cereal') edit_fd_win.info1_layout.itemAt(3).itemAt(0).widget().setText('2') edit_fd_win.info1_layout.itemAt(3).itemAt(1).widget().setCurrentText( 'oz') with patch.object(interface, 'MessageWin') as message_win_mock: QTest.mouseClick(edit_fd_win.done_btn, Qt.LeftButton) message_win_mock.assert_called()
def test_no_name_given(self): """MessageWin should be called if no name is provided.""" edit_fd_win = interface.EditFoodDictWin() # Blank name field. edit_fd_win.info1_layout.itemAt(1).widget().setText('') edit_fd_win.info1_layout.itemAt(3).itemAt(0).widget().setText('2') edit_fd_win.info1_layout.itemAt(3).itemAt(1).widget().setCurrentText( 'oz') with patch.object(interface, 'MessageWin') as message_win_mock: QTest.mouseClick(edit_fd_win.done_btn, Qt.LeftButton) message_win_mock.assert_called()
def test_edit_entry_name_and_serving_size(self): """Check that the entry's name and serving size info is placed into the correct fields by default.""" edit_fd_win = interface.EditFoodDictWin(edit_entry_name='cereal') name = edit_fd_win.info1_layout.itemAt(1).widget().text() self.assertEqual(name, 'cereal') amount = edit_fd_win.info1_layout.itemAt(3).itemAt(0).widget().text() unit = edit_fd_win.info1_layout.itemAt(3).itemAt( 1).widget().currentText() self.assertEqual(amount, '60') self.assertEqual(unit, 'g')
def test_nonfloat_amount_given(self): """MessageWin should be called if the user gives a non-float amount.""" # There is a validator on the amount input field, but the user can still enter some # non-float values, such as a decimal. edit_fd_win = interface.EditFoodDictWin() edit_fd_win.info1_layout.itemAt(1).widget().setText('cereal') edit_fd_win.info1_layout.itemAt(3).itemAt(0).widget().setText('.') edit_fd_win.info1_layout.itemAt(3).itemAt(1).widget().setCurrentText( 'oz') with patch.object(interface, 'MessageWin') as message_win_mock: QTest.mouseClick(edit_fd_win.done_btn, Qt.LeftButton) message_win_mock.assert_called()
def test_fd_file_creation(self): edit_fd_win = interface.EditFoodDictWin() # Required info: entry name and at least one serving size. edit_fd_win.info1_layout.itemAt(1).widget().setText('new_entry') edit_fd_win.info1_layout.itemAt(3).itemAt(0).widget().setText('2') edit_fd_win.info1_layout.itemAt(3).itemAt(1).widget().setCurrentText( 'oz') with patch.object(interface, 'FoodDictWin') as fd_win_mock, \ patch('healthhelper.interface.open', mock_open()) as open_mock, \ patch('os.makedirs', return_value=None) as makedirs_mock: QTest.mouseClick(edit_fd_win.done_btn, Qt.LeftButton) open_mock.assert_called() fd_win_mock.assert_called()
def test_cancel(self, fd_win_mock): edit_fd_win = interface.EditFoodDictWin() QTest.mouseClick(edit_fd_win.back_to_fd_win_btn, Qt.LeftButton) fd_win_mock.assert_called()