def test_log_to_log_win_remove_entries_no_log_file(self, join_mock): """Test transition from log display window to message window when user clicks 'delete log' while no log file exists.""" log_win = interface.LogWin() with patch.object(interface, 'MessageWin') as message_win_mock: QTest.mouseClick(log_win.remove_entries_btn, Qt.LeftButton) message_win_mock.assert_called()
def setUp(self): """Set up a table with four entries, two of which are checked. Provide amount information for each entry.""" log_win = interface.LogWin() edit_geo = log_win.geometry() edit_date = interface.datetime.date(2020, 4, 12) self.edit_log_win = interface.EditLogWin(edit_date, TEST_LOG_PATH, edit_geo, edit_entry_names=None, edit=False) self.edit_log_win.edit_table.item(0, 0).setCheckState(2) self.edit_log_win.edit_table.item(1, 0).setCheckState(2) self.edit_log_win.edit_table.cellWidget( 0, 1).layout().itemAt(0).widget().setText('60') self.edit_log_win.edit_table.cellWidget( 0, 2).layout().itemAt(0).widget().setCurrentText('g') self.edit_log_win.edit_table.cellWidget( 1, 1).layout().itemAt(0).widget().setText('2') self.edit_log_win.edit_table.cellWidget( 1, 2).layout().itemAt(0).widget().setCurrentText('item(s)') self.edit_log_win.edit_table.cellWidget( 2, 1).layout().itemAt(0).widget().setText('0.5') self.edit_log_win.edit_table.cellWidget( 2, 2).layout().itemAt(0).widget().setCurrentText('cup') self.edit_log_win.edit_table.cellWidget( 3, 1).layout().itemAt(0).widget().setText('4') self.edit_log_win.edit_table.cellWidget( 3, 2).layout().itemAt(0).widget().setCurrentText('tbsp')
def test_log_win_to_edit_log_win_with_selected_entry(self, join_mock): """Test transition from log display window to edit log window to edit existing log entries.""" log_win = interface.LogWin() # Select the first log entry, then attempt to edit it. log_win.log_table.item(0, 0).setCheckState(2) with patch.object(interface, 'EditLogWin') as edit_log_win_mock: QTest.mouseClick(log_win.edit_entries_btn, Qt.LeftButton) edit_log_win_mock.assert_called()
def test_log_to_log_win_remove_entries_with_log_file(self, join_mock): """Test transition from log display window to log display window when removing entries from a log.""" log_win = interface.LogWin() # Select the first entry in the table. log_win.log_table.item(0, 0).setCheckState(2) with patch.object(interface, 'LogWin') as log_win_mock: QTest.mouseClick(log_win.remove_entries_btn, Qt.LeftButton) log_win_mock.assert_called()
def test_log_table(self, join_mock): log_win = interface.LogWin() # Select the first two entries log_win.log_table.item(0, 0).setCheckState(2) log_win.log_table.item(1, 0).setCheckState(2) result = data.get_table_entry_names(log_win.log_table) self.assertEqual(result[0], ['cereal', 'chocolate', 'peanut butter']) self.assertEqual(result[1], ['cereal', 'chocolate']) self.assertEqual(result[2], ['peanut butter'])
def test_delete_log(self, join_mock): """Test transition from log display window to message window when user clicks 'delete log' using the test log file.""" log_win = interface.LogWin() with patch.object(interface, 'QDialog') as dialog_mock: QTest.mouseClick(log_win.delete_log_btn, Qt.LeftButton) dialog_mock.assert_called() # Test that the log is deleted, and that LogWin is called. with patch('os.remove') as remove_mock, \ patch.object(interface, 'LogWin') as log_win_mock: QTest.mouseClick(log_win.yes_btn, Qt.LeftButton) remove_mock.assert_called() log_win_mock.assert_called()
def test_log_win_table(self, os_mock): """Check that all entries in the table are checked or unchecked after clicking the 'select all' and 'unselect all' buttons.""" log_win = interface.LogWin() QTest.mouseClick(log_win.select_all_btn, Qt.LeftButton) for entry_index in range(log_win.log_table.rowCount()): # Checked entries have a checkState() equal to 2. self.assertEqual( log_win.log_table.item(entry_index, 0).checkState(), 2) QTest.mouseClick(log_win.unselect_all_btn, Qt.LeftButton) for entry_index in range(log_win.log_table.rowCount()): # Unchecked entries have a checkState() equal to 0. self.assertEqual( log_win.log_table.item(entry_index, 0).checkState(), 0)
def test_edit_log_win_table(self): """Check that all entries in the table are checked or unchecked after clicking the 'select all' and 'unselect_all' buttons.""" log_win = interface.LogWin() edit_geo = log_win.geometry() edit_date = interface.datetime.date(2020, 4, 12) edit_log_win = interface.EditLogWin(edit_date, TEST_LOG_PATH, edit_geo) QTest.mouseClick(edit_log_win.select_all_btn, Qt.LeftButton) for entry_index in range(edit_log_win.edit_table.rowCount()): self.assertEqual( edit_log_win.edit_table.item(entry_index, 0).checkState(), 2) QTest.mouseClick(edit_log_win.unselect_all_btn, Qt.LeftButton) for entry_index in range(edit_log_win.edit_table.rowCount()): self.assertEqual( edit_log_win.edit_table.item(entry_index, 0).checkState(), 0)
def test_log_edit_table(self): log_win = interface.LogWin() edit_geo = log_win.geometry() edit_date = interface.datetime.date(2020, 4, 12) edit_log_win = interface.EditLogWin(edit_date, TEST_LOG_PATH, edit_geo, edit_entry_names=None, edit=False) edit_log_win.edit_table.item(0, 0).setCheckState(2) edit_log_win.edit_table.item(1, 0).setCheckState(2) result = data.get_table_entry_names(edit_log_win.edit_table) self.assertEqual(result[0], ['cereal', 'chocolate', 'oats', 'peanut butter']) self.assertEqual(result[1], ['cereal', 'chocolate']) self.assertEqual(result[2], ['oats', 'peanut butter'])
def setUp(self): """Set up args to be passed to EditLogWin.""" self.log_win = interface.LogWin() self.edit_geo = self.log_win.geometry() self.edit_date = interface.datetime.date(2020, 4, 12)
def test_log_to_fd_win(self): """Test transition from log display window to food dictionary display window.""" log_win = interface.LogWin() with patch.object(interface, 'FoodDictWin') as fd_win_mock: QTest.mouseClick(log_win.goto_fd_btn, Qt.LeftButton) fd_win_mock.assert_called()
def test_help_win(self): """QDialog should be called when the user clicks the help button.""" log_win = interface.LogWin() with patch.object(interface, 'QDialog') as dialog_mock: QTest.mouseClick(log_win.help_btn, Qt.LeftButton) dialog_mock.assert_called()
def test_log_win_to_edit_log_win_with_no_selected_entries(self, join_mock): """Test transition from log display window to edit log window without selecting any entries to edit.""" log_win = interface.LogWin() with patch.object(interface, 'MessageWin') as message_win_mock: QTest.mouseClick(log_win.edit_entries_btn, Qt.LeftButton) message_win_mock.assert_called()
def test_log_to_log_add_win_no_fd_file(self, exists_mock): """Test transition from log window to add-to-log window while no FD file exists.""" log_win = interface.LogWin() with patch.object(interface, 'MessageWin') as message_win_mock: QTest.mouseClick(log_win.add_entries_btn, Qt.LeftButton) message_win_mock.assert_called()
def test_log_to_log_add_win_with_test_fd_file(self): """Test transition from log display window to add-to-log window using the test FD file.""" log_win = interface.LogWin() with patch.object(interface, 'EditLogWin') as edit_log_win_mock: QTest.mouseClick(log_win.add_entries_btn, Qt.LeftButton) edit_log_win_mock.assert_called()