Exemplo n.º 1
0
    def test_key_not_borked(self):
        rw = RecipesWidget()
        previous = rw.currentRow()

        QTest.keyClick(rw, Qt.Key_Down)

        self.assertEqual(rw.currentRow(), previous + 1)
Exemplo n.º 2
0
    def test_key_not_borked(self):
        rw = RecipesWidget()
        previous = rw.currentRow()

        QTest.keyClick(rw, Qt.Key_Down)

        self.assertEqual(rw.currentRow(), previous + 1)
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
    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()
Exemplo n.º 5
0
    def test_stupid_drop_case(self):
        rw = RecipesWidget()
        rw.recipeRemoved = DummySignal()
        self.assertEqual(rw.dropMimeData(None, None, Qt.IgnoreAction), True)

        mimeData = QMimeData()
        self.assertEqual(rw.dropMimeData(0, mimeData, Qt.CopyAction), False)
        self.assertEqual(rw.recipeRemoved.received, [])
Exemplo n.º 6
0
    def test_stupid_drop_case(self):
        rw = RecipesWidget()
        rw.recipeRemoved = DummySignal()
        self.assertEqual(rw.dropMimeData(None, None, Qt.IgnoreAction),
                         True)

        mimeData = QMimeData()
        self.assertEqual(rw.dropMimeData(0, mimeData, Qt.CopyAction),
                         False)
        self.assertEqual(rw.recipeRemoved.received, [])
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    def __init__(self, fro, to):
        super(ReEatWidget, self).__init__(Qt.Horizontal)

        left = QSplitter(Qt.Vertical)
        rw = RecipesWidget()
        tw = TagsWidget()
        tw.tagsChanged.connect(rw.reload)
        rw.recipeChanged.connect(tw.reload)
        left.addWidget(rw)
        left.addWidget(tw)

        self.addWidget(left)

        right = PlanningWidget(fro, to)
        rw.recipeRemoved.connect(right._recipe_removed)
        self.addWidget(right)
Exemplo n.º 11
0
    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)
Exemplo n.º 12
0
    def test_dropping_the_data_emits_the_signal(self):
        rw = RecipesWidget()
        self.assertEqual(rw.supportedDropActions(),
                         Qt.CopyAction | Qt.MoveAction)
        self.assertIn('application/vnd.re-eat.meal_recipe', rw.mimeTypes())
        assert rw.viewport().acceptDrops()

        rw.recipeRemoved = DummySignal()

        mimeData = QMimeData()
        encodedData = QByteArray()
        stream = QDataStream(encodedData, QIODevice.WriteOnly)
        stream.writeInt(1)
        stream.writeQVariant(datetime.date.today())
        stream.writeInt(2)
        mimeData.setData('application/vnd.re-eat.meal_recipe', encodedData)

        rw.dropMimeData(0, mimeData, Qt.CopyAction)
        self.assertListEqual(rw.recipeRemoved.received,
                             [(1, datetime.date.today(), 2)])
Exemplo n.º 13
0
    def test_dropping_the_data_emits_the_signal(self):
        rw = RecipesWidget()
        self.assertEqual(rw.supportedDropActions(),
                         Qt.CopyAction|Qt.MoveAction)
        self.assertIn('application/vnd.re-eat.meal_recipe', rw.mimeTypes())
        assert rw.viewport().acceptDrops()

        rw.recipeRemoved = DummySignal()

        mimeData = QMimeData()
        encodedData = QByteArray()
        stream = QDataStream(encodedData, QIODevice.WriteOnly)
        stream.writeInt(1)
        stream.writeQVariant(datetime.date.today())
        stream.writeInt(2)
        mimeData.setData('application/vnd.re-eat.meal_recipe', encodedData)

        rw.dropMimeData(0, mimeData, Qt.CopyAction)
        self.assertListEqual(rw.recipeRemoved.received,
                             [(1, datetime.date.today(), 2)])
Exemplo n.º 14
0
 def test_drag_is_enabled(self):
     rw = RecipesWidget()
     assert rw.dragEnabled()
     assert rw.item(0).flags() & Qt.ItemIsDragEnabled
Exemplo n.º 15
0
    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)
Exemplo n.º 16
0
    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)
Exemplo n.º 17
0
 def test_drag_is_enabled(self):
     rw = RecipesWidget()
     assert rw.dragEnabled()
     assert rw.item(0).flags() & Qt.ItemIsDragEnabled