def test_remove_recipe(self): rw = RecipesWidget() self.assertEqual(len(rw.selectedItems()), 0) before = Session.query(Recipe).count() rw.item(0).setSelected(True) rw.item(3).setSelected(True) QTest.keyClick(rw, Qt.Key_Delete) self.assertEqual(Session.query(Recipe).count(), before - 2) self.assertEqual(rw.count(), before - 2)
def test_double_click_open_the_recipe_dialog(self, mock_dialog): r = self.recipes[0] rw = RecipesWidget() rw.doubleClick(rw.item(0)) mock_dialog.assert_called_once_with(r, rw) mock_dialog(r, rw).exec_.assert_called_once_with()
def test_drag_information_are_correct(self): rw = RecipesWidget() self.assertIn('application/vnd.re-eat.recipe', rw.mimeTypes()) items = [rw.item(i) for i in (0, 1)] ids = [item.data(Qt.UserRole) for item in items] data = rw.mimeData(items) stream = QDataStream(data.data('application/vnd.re-eat.recipe')) result = [] while not stream.atEnd(): result.append(stream.readInt()) self.assertListEqual(result, ids)
def test_drag_is_enabled(self): rw = RecipesWidget() assert rw.dragEnabled() assert rw.item(0).flags() & Qt.ItemIsDragEnabled
def test_the_widget_is_correcty_populated(self): rw = RecipesWidget() self.assertEqual(rw.count(), 4) self.assertEqual(rw.item(0).text(), self.recipes[0].name)