Esempio n. 1
0
    def test_create_delete_2(self):
        """Verify correct DELETE statement is created
        for a single GeneID in the gene table."""

        # First, retrieve the current state of the gene table.
        results1 = test_db_utils.get_data(self.gene_query)
        results1_phageids = set()
        results1_geneids = set()
        for dict in results1:
            results1_phageids.add(dict["PhageID"])
            results1_geneids.add(dict["GeneID"])

        # Second, execute the DELETE statement.
        statement = mysqldb.create_delete("gene", "GeneID", "Trixie_1")
        test_db_utils.execute(statement)

        # Third, retrieve the current state of the gene table.
        results2 = test_db_utils.get_data(self.gene_query)
        results2_phageids = set()
        results2_geneids = set()
        for dict in results2:
            results2_phageids.add(dict["PhageID"])
            results2_geneids.add(dict["GeneID"])

        exp = "DELETE FROM gene WHERE GeneID = 'Trixie_1';"
        with self.subTest():
            self.assertEqual(statement, exp)
        with self.subTest():
            self.assertEqual(len(results1_phageids), 1)
        with self.subTest():
            self.assertEqual(len(results1_geneids), 2)
        with self.subTest():
            self.assertEqual(len(results2_phageids), 1)
        with self.subTest():
            self.assertEqual(len(results2_geneids), 1)
Esempio n. 2
0
    def test_create_delete_1(self):
        """Verify correct DELETE statement is created
        for a PhageID in the phage table."""
        # First, retrieve the current state of the phage table.
        results1 = test_db_utils.get_data(PHAGE_QUERY2)
        results1_phageids = set()
        for dict in results1:
            results1_phageids.add(dict["PhageID"])

        # Second, execute the DELETE statement.
        statement = mysqldb.create_delete("phage", "PhageID", "Trixie")
        test_db_utils.execute(statement)

        # Third, retrieve the current state of the phage table.
        results2 = test_db_utils.get_data(PHAGE_QUERY2)
        results2_phageids = set()
        for dict in results2:
            results2_phageids.add(dict["PhageID"])

        exp = "DELETE FROM phage WHERE PhageID = 'Trixie';"
        with self.subTest():
            self.assertEqual(statement, exp)
        with self.subTest():
            self.assertEqual(len(results1_phageids), 1)
        with self.subTest():
            self.assertEqual(len(results2_phageids), 0)