Exemplo n.º 1
0
 def test_create_update_1(self):
     """Verify correct Cluster statement is created for a non-singleton."""
     statement = mysqldb.create_update("phage", "Cluster", "B", "PhageID",
                                       "Trixie")
     test_db_utils.execute(statement)
     result = test_db_utils.get_data(PHAGE_QUERY2)
     results = result[0]
     exp = "UPDATE phage SET Cluster = 'B' WHERE PhageID = 'Trixie';"
     with self.subTest():
         self.assertEqual(statement, exp)
     with self.subTest():
         self.assertEqual(results["Cluster"], "B")
Exemplo n.º 2
0
 def test_create_update_2(self):
     """Verify correct Cluster statement is created for a singleton."""
     statement = mysqldb.create_update("phage", "Cluster", "Singleton",
                                       "PhageID", "Trixie")
     test_db_utils.execute(statement)
     result = test_db_utils.get_data(self.phage_query)
     results = result[0]
     exp = "UPDATE phage SET Cluster = NULL WHERE PhageID = 'Trixie';"
     with self.subTest():
         self.assertEqual(statement, exp)
     with self.subTest():
         self.assertIsNone(results["Cluster"])
Exemplo n.º 3
0
 def test_create_update_3(self):
     """Verify correct Subcluster statement is created for a
     non-empty value."""
     statement = mysqldb.create_update("phage", "Subcluster", "A2",
                                       "PhageID", "Trixie")
     test_db_utils.execute(statement)
     result = test_db_utils.get_data(self.phage_query)
     results = result[0]
     exp = "UPDATE phage SET Subcluster = 'A2' WHERE PhageID = 'Trixie';"
     with self.subTest():
         self.assertEqual(statement, exp)
     with self.subTest():
         self.assertEqual(results["Subcluster"], "A2")
Exemplo n.º 4
0
    def test_create_update_4(self):
        """Verify Gene table statement is created correctly."""
        # First add gene Trixie_1 to the database.
        gene_data = test_data_utils.get_trixie_gene_data()
        gene_data["PhageID"] = "Trixie"
        gene_data["Notes"] = "none"
        gene_data["GeneID"] = "Trixie_1"
        test_db_utils.insert_gene_data(gene_data)

        # Second run the update statement.
        statement = mysqldb.create_update("gene", "Notes", "Repressor",
                                          "GeneID", "Trixie_1")
        test_db_utils.execute(statement)
        result = test_db_utils.get_data(self.gene_query)
        results = result[0]
        exp = "UPDATE gene SET Notes = 'Repressor' WHERE GeneID = 'Trixie_1';"
        with self.subTest():
            self.assertEqual(statement, exp)
        with self.subTest():
            self.assertEqual(results["Notes"].decode("utf-8"), "Repressor")
Exemplo n.º 5
0
 def execute_ticket(self):
     """
     This function checks whether the ticket is valid.  If it is not
     valid, the function returns with code 0, indicating failure to
     execute the ticket.  If the ticket is valid, request input from
     the user to verify that they actually want to proceed with the
     update they've proposed.  If response is in the affirmative,
     the ticket is executed.  Otherwise, indicate that this ticket
     will be skipped, and return 0 as the ticket was not executed.
     If an error is encountered during execution of the ticket,
     print error message and return 0.  If the ticket is executed
     without issue, return 1 indicating success.
     :return:
     """
     if self.valid_ticket is False:
         return 0
     try:
         command = mysqldb.create_update(self.table, self.field, self.value,
                                         self.key_name, self.key_value)
         # print("\nCommand to execute:")
         # print(command)
         # prompt = "Do you wish to proceed? (y/n) "
         # result = basic.ask_yes_no(prompt=prompt, response_attempt=3)
         result = True
         if result == True:
             cur = self.connection.cursor()
             cur.execute(command)
             cur.execute("COMMIT")
             cur.close()
         else:
             print("Skipping this ticket...")
             return 0
     except pms.err.Error as err:
         print("Error {}: {}".format(err[0], err[1]))
         return 0
     return 1