Esempio n. 1
0
def test_drop_cmd(conn):
    """Test drop command of VQL language

    The following tables are tested:
    - selections
    - wordsets
    """
    # Create a selection named "subset"
    conn.execute("INSERT INTO selections (name) VALUES ('subset')")
    assert "subset" in [
        i["name"]
        for i in conn.execute("SELECT name FROM selections").fetchall()
    ]
    ret = command.drop_cmd(conn, feature="selections", name="subset")
    assert "subset" not in [
        i["name"]
        for i in conn.execute("SELECT name FROM selections").fetchall()
    ]
    assert ret["success"]

    # Create wordset
    test_file = "examples/gene.txt"
    wordset_name = "bouzniouf"
    command.import_cmd(conn, "wordsets", wordset_name, test_file)
    command.drop_cmd(conn, feature="wordsets", name=wordset_name)

    assert wordset_name not in [
        i["name"]
        for i in conn.execute("SELECT name FROM wordsets").fetchall()
    ]
Esempio n. 2
0
    def remove_wordset(self):
        """Delete word set from database"""
        if len(self.view.selectedItems()) == 0:
            # if selection is empty
            return

        reply = QMessageBox.question(
            self,
            self.tr("Drop word set"),
            self.tr("Are you sure you want to remove the selected set(s)?"),
            QMessageBox.Yes | QMessageBox.No,
        )
        if reply != QMessageBox.Yes:
            return

        # Delete all selected sets
        for i in self.view.selectedItems():
            result = drop_cmd(self.conn, "wordsets", i.text())

            if not result["success"]:
                LOGGER.error(result)
                QMessageBox.critical(
                    self,
                    self.tr("Error while deleting set"),
                    self.tr("Error while deleting set '%s'") % i.text(),
                )

        self.populate()
Esempio n. 3
0
    def open_wordset(self):
        """Display a window to allow to edit the selected word set

        The previous set is dropped and the new is then imported in database.
        """
        wordset_name = self.view.currentItem().text()
        dialog = WordListDialog()

        # populate dialog
        dialog.model.setStringList(
            list(get_words_in_set(self.conn, wordset_name)))

        if dialog.exec_() == QDialog.Accepted:
            # Drop previous
            drop_cmd(self.conn, "wordsets", wordset_name)
            # Import new
            self.import_wordset(dialog.model.stringList(), wordset_name)
            self.populate()