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)
def test_execute_transaction_4(self): """Verify list of three statements (including one with duplicated HitID) are inserted.""" domain_data1 = test_data_utils.get_trixie_domain_data() test_db_utils.insert_domain_data(domain_data1) domain_table_results1 = test_db_utils.get_data( test_db_utils.domain_table_query) # Duplicate HitID statement1 = get_domain_insert_statement(domain_data1) # Valid gene_domain_data = test_data_utils.get_trixie_gene_domain_data() statement2 = get_gene_domain_insert_statement(gene_domain_data) # Valid update_data = get_trixie_gene_table_domain_status_update_data_1() statement3 = get_gene_update_statement(update_data) statements = [statement1, statement2, statement3] result = find_domains.execute_transaction(self.connection, statements) gene_table_results = test_db_utils.get_data( test_db_utils.gene_table_query) gene_domain_table_results = test_db_utils.get_data( test_db_utils.gene_domain_table_query) domain_table_results2 = test_db_utils.get_data( test_db_utils.domain_table_query) domain_status = gene_table_results[0]["DomainStatus"] with self.subTest(): self.assertEqual(len(domain_table_results1), 1) with self.subTest(): self.assertEqual(len(domain_table_results2), 1) with self.subTest(): self.assertEqual(len(gene_domain_table_results), 1) with self.subTest(): self.assertEqual(result, 0) with self.subTest(): self.assertEqual(domain_status, 1)
def test_execute_transaction_5(self): """Verify list of three valid statements and one invalid statement are NOT inserted. All statements rolled back.""" # Valid domain_data1 = test_data_utils.get_trixie_domain_data() statement1 = get_domain_insert_statement(domain_data1) # Valid gene_domain_data = test_data_utils.get_trixie_gene_domain_data() statement2 = get_gene_domain_insert_statement(gene_domain_data) # Invalid domain_data2 = test_data_utils.get_trixie_domain_data() statement3 = get_domain_insert_statement(domain_data2) statement3 = statement3.replace("HitID", "unique_id") statement3 = statement3.replace("Name", "Name_invalid") # Valid - function should exit before executing this though. update_data = get_trixie_gene_table_domain_status_update_data_1() statement4 = get_gene_update_statement(update_data) statements = [statement1, statement2, statement3, statement4] result = find_domains.execute_transaction(self.connection, statements) gene_table_results = test_db_utils.get_data( test_db_utils.gene_table_query) gene_domain_table_results = test_db_utils.get_data( test_db_utils.gene_domain_table_query) domain_table_results = test_db_utils.get_data( test_db_utils.domain_table_query) domain_status = gene_table_results[0]["DomainStatus"] with self.subTest(): self.assertEqual(len(domain_table_results), 0) with self.subTest(): self.assertEqual(len(gene_domain_table_results), 0) with self.subTest(): self.assertEqual(result, 1) with self.subTest(): self.assertEqual(domain_status, 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)
def test_verify_db_setup(self): """Confirm that the database was setup correctly for the tests.""" phage_data = test_db_utils.get_data(test_db_utils.phage_table_query) gene_data = test_db_utils.get_data(test_db_utils.gene_table_query) with self.subTest(): self.assertEqual(len(phage_data), 3) with self.subTest(): self.assertEqual(len(gene_data), 4)
def test_copy_db_2(self): """Verify no data is copied since databases are the same.""" before_v1 = test_db_utils.get_data(test_db_utils.version_table_query) result = mysqldb_basic.copy_db(self.engine, DB) after_v1 = test_db_utils.get_data(test_db_utils.version_table_query) with self.subTest(): self.assertEqual(before_v1[0]["Version"], after_v1[0]["Version"]) with self.subTest(): self.assertEqual(result, 0)
def test_main_1(self, getpass_mock): """Verify frozen database is created from database with no change in genome count when no filters are provided.""" getpass_mock.side_effect = [USER, PWD] run.main(self.unparsed_args) count1 = test_db_utils.get_data(COUNT_PHAGE, db=DB) count2 = test_db_utils.get_data(COUNT_PHAGE, db=DB2) version = test_db_utils.get_data(test_db_utils.version_table_query, db=DB2) with self.subTest(): self.assertEqual(count1[0]["count"], count2[0]["count"]) with self.subTest(): self.assertEqual(version[0]["Version"], 1)
def test_main_13(self, getpass_mock): """Verify data is changed when there is NO data in the database and reset = True.""" getpass_mock.side_effect = [USER, PWD] self.unparsed_args.extend(["-f", "phage.Status != draft", "-r"]) run.main(self.unparsed_args) count = test_db_utils.get_data(COUNT_PHAGE, db=DB2) version = test_db_utils.get_data(test_db_utils.version_table_query, db=DB2) with self.subTest(): self.assertEqual(count[0]["count"], 0) with self.subTest(): self.assertEqual(version[0]["Version"], 0)
def test_copy_db_1(self): """Verify data from database1 is copied to database2.""" before_v1 = test_db_utils.get_data(test_db_utils.version_table_query) before_v2 = test_db_utils.get_data(test_db_utils.version_table_query, db=DB2) result = mysqldb_basic.copy_db(self.engine, DB2) after_v1 = test_db_utils.get_data(test_db_utils.version_table_query) after_v2 = test_db_utils.get_data(test_db_utils.version_table_query, db=DB2) with self.subTest(): self.assertNotEqual(before_v1[0]["Version"], before_v2[0]["Version"]) with self.subTest(): self.assertEqual(result, 0) with self.subTest(): self.assertEqual(after_v1[0]["Version"], after_v2[0]["Version"])
def test_install_db_1(self): """Verify new database is installed.""" stmt1 = "UPDATE version SET Version = 0" test_db_utils.execute(stmt1) before = test_db_utils.get_data(test_db_utils.version_table_query) result = mysqldb_basic.install_db(self.engine, test_db_utils.TEST_DB_FILEPATH) after = test_db_utils.get_data(test_db_utils.version_table_query) with self.subTest(): self.assertNotEqual(before[0]["Version"], after[0]["Version"]) with self.subTest(): self.assertTrue(after[0]["Version"] > 0) with self.subTest(): self.assertEqual(result, 0)
def test_main_3(self, alchemy_mock): """Verify version data is updated.""" alchemy_mock.return_value = self.alchemist unparsed_args = get_unparsed_args(version=True) run.main(unparsed_args) version_table = test_db_utils.get_data(test_db_utils.version_table_query) phage_table = test_db_utils.get_data(test_db_utils.phage_table_query) data_dict = phage_id_dict(phage_table) alice = data_dict["Alice"] with self.subTest(): self.assertEqual(version_table[0]["Version"], 1) # Just confirm that only version data was changed. with self.subTest(): self.assertEqual(alice["HostGenus"], "unknown")
def test_execute_statement_10(self): """Verify invalid data can be inserted after '% w' is replaced with '%% w'.""" domain_data = test_data_utils.get_trixie_domain_data() # "Description": "ParB-like nuclease domain" description = domain_data["Description"] description = description.replace("nuclease domain", "nuclease % wdomain") domain_data["Description"] = description statement = get_domain_insert_statement(domain_data) statement = statement.replace("%", "%%") results_tup = find_domains.execute_statement(self.connection, statement) result = results_tup[0] type_error = results_tup[1] value_error = results_tup[2] msg = results_tup[3] self.trans.commit() domain_table_results = test_db_utils.get_data( test_db_utils.domain_table_query) with self.subTest(): self.assertEqual(len(domain_table_results), 1) with self.subTest(): self.assertEqual(result, 0) with self.subTest(): self.assertFalse(type_error) with self.subTest(): self.assertFalse(value_error)
def test_create_trna_table_insert_1(self): """Verify trna table INSERT statement is created correctly when locus_tag, note, and structure, and use are not empty.""" # Note: even though this function returns a string and doesn't # actually utilize a MySQL database, this test ensures # that the returned statement will function properly in MySQL. trna1 = trna.Trna() trna1.id = "Trixie_1" trna1.genome_id = "Trixie" trna1.name = "1" trna1.locus_tag = "TAG1" trna1.start = 5 trna1.stop = 10 trna1.length = 200 trna1.orientation = "F" trna1.note = "misc" trna1.amino_acid = "Ala" trna1.anticodon = "AAA" trna1.structure = "random" trna1.use = "aragorn" statement = mysqldb.create_trna_table_insert(trna1) test_db_utils.execute(statement) result = test_db_utils.get_data(TRNA_QUERY2) results = result[0] exp = ("""INSERT INTO trna """ """(GeneID, PhageID, Start, Stop, Length, """ """Name, Orientation, Note, LocusTag, AminoAcid, Anticodon, """ """Structure, Source) """ """VALUES """ """("Trixie_1", "Trixie", 5, 10, 200, "1", "F", "misc", """ """"TAG1", "Ala", "AAA", "random", "aragorn");""") with self.subTest(): self.assertEqual(statement, exp) with self.subTest(): self.assertEqual(results["GeneID"], "Trixie_1") with self.subTest(): self.assertEqual(results["PhageID"], "Trixie") with self.subTest(): self.assertEqual(results["Start"], 5) with self.subTest(): self.assertEqual(results["Stop"], 10) with self.subTest(): self.assertEqual(results["Length"], 200) with self.subTest(): self.assertEqual(results["Name"], "1") with self.subTest(): self.assertEqual(results["Orientation"], "F") with self.subTest(): self.assertEqual(results["Note"].decode("utf-8"), "misc") with self.subTest(): self.assertEqual(results["LocusTag"], "TAG1") with self.subTest(): self.assertEqual(results["Structure"].decode("utf-8"), "random") with self.subTest(): self.assertEqual(results["AminoAcid"], "Ala") with self.subTest(): self.assertEqual(results["Anticodon"], "AAA") with self.subTest(): self.assertEqual(results["Source"], "aragorn")
def test_main_4(self, alchemy_mock): """Verify version data and phage table data are updated.""" alchemy_mock.return_value = self.alchemist host_genus = "Mycobacterium" tkt = get_alice_ticket("HostGenus", host_genus) create_update_table([tkt], update_table) unparsed_args = get_unparsed_args(file=update_table, version=True) run.main(unparsed_args) version_table = test_db_utils.get_data(test_db_utils.version_table_query) phage_table = test_db_utils.get_data(test_db_utils.phage_table_query) data_dict = phage_id_dict(phage_table) alice = data_dict["Alice"] with self.subTest(): self.assertEqual(alice["HostGenus"], host_genus) with self.subTest(): self.assertEqual(version_table[0]["Version"], 1)
def test_create_gene_table_insert_2(self): """Verify gene table INSERT statement is created correctly when locus_tag is empty.""" # Note: even though this function returns a string and doesn't # actually utilize a MySQL database, this test ensures # that the returned statement will function properly in MySQL. cds1 = cds.Cds() cds1.id = "SEA_TRIXIE_123" cds1.genome_id = "Trixie" cds1.start = 5 cds1.stop = 10 cds1.parts = 1 cds1.translation_length = 20 cds1.name = "Int" cds1.type = "CDS" cds1.translation = Seq("ACKLG", IUPAC.protein) cds1.orientation = "F" cds1.description = "integrase" cds1.locus_tag = "" statement = mysqldb.create_gene_table_insert(cds1) test_db_utils.execute(statement) result = test_db_utils.get_data(self.gene_query) results = result[0] exp = ("""INSERT INTO gene """ """(GeneID, PhageID, Start, Stop, Length, Name, """ """Translation, Orientation, Notes, LocusTag, Parts) """ """VALUES """ """("SEA_TRIXIE_123", "Trixie", 5, 10, 20, "Int", """ """"ACKLG", "F", "integrase", NULL, 1);""") with self.subTest(): self.assertEqual(statement, exp) with self.subTest(): self.assertEqual(results["GeneID"], "SEA_TRIXIE_123") with self.subTest(): self.assertEqual(results["LocusTag"], None)
def test_install_db_2(self, cc_mock): """Verify new database is not installed.""" # Raise an error instead of calling check_call() so that # the exception block is entered. cc_mock.side_effect = ValueError("Error raised") stmt1 = "UPDATE version SET Version = 0" test_db_utils.execute(stmt1) before = test_db_utils.get_data(test_db_utils.version_table_query) result = mysqldb_basic.install_db(self.engine, test_db_utils.TEST_DB_FILEPATH) after = test_db_utils.get_data(test_db_utils.version_table_query) with self.subTest(): self.assertEqual(before[0]["Version"], after[0]["Version"]) with self.subTest(): self.assertTrue(after[0]["Version"] == 0) with self.subTest(): self.assertEqual(result, 1)
def test_execute_statement_6(self): """Verify invalid data can NOT be inserted into domain table when there is an invalid column name.""" domain_data = test_data_utils.get_trixie_domain_data() statement = get_domain_insert_statement(domain_data) statement = statement.replace("Name", "Name_invalid") results_tup = find_domains.execute_statement(self.connection, statement) result = results_tup[0] type_error = results_tup[1] value_error = results_tup[2] msg = results_tup[3] self.trans.commit() domain_table_results = test_db_utils.get_data( test_db_utils.domain_table_query) with self.subTest(): self.assertEqual(len(domain_table_results), 0) with self.subTest(): self.assertEqual(result, 1) with self.subTest(): self.assertTrue(error_msg in msg) with self.subTest(): self.assertFalse(type_error) with self.subTest(): self.assertFalse(value_error)
def test_create_phage_table_insert_1(self): """Verify phage table INSERT statement is created correctly.""" # Note: even though this function returns a string and doesn't # actually utilize a MySQL database, this test ensures # that the returned statement will function properly in MySQL. gnm = genome.Genome() gnm.id = "L5" gnm.name = "L5_Draft" gnm.host_genus = "Mycobacterium" gnm.annotation_status = "final" gnm.accession = "ABC123" gnm.seq = Seq("ATCG", IUPAC.ambiguous_dna) gnm.length = 4 gnm.gc = 0.5001 gnm.date = constants.EMPTY_DATE gnm.retrieve_record = 1 gnm.annotation_author = 1 gnm.cluster = "Singleton" gnm.subcluster = "A2" statement = mysqldb.create_phage_table_insert(gnm) test_db_utils.execute(statement) phage_data = test_db_utils.get_data(test_db_utils.phage_table_query) results = phage_data[0] exp = ("INSERT INTO phage " "(PhageID, Accession, Name, HostGenus, Sequence, " "Length, GC, Status, DateLastModified, RetrieveRecord, " "AnnotationAuthor, Cluster, Subcluster) " "VALUES " "('L5', 'ABC123', 'L5_Draft', 'Mycobacterium', 'ATCG', " f"4, 0.5001, 'final', '{constants.EMPTY_DATE}', 1, " "1, NULL, 'A2');") with self.subTest(): self.assertEqual(statement, exp) with self.subTest(): self.assertEqual(results["PhageID"], "L5") with self.subTest(): self.assertEqual(results["Accession"], "ABC123") with self.subTest(): self.assertEqual(results["Name"], "L5_Draft") with self.subTest(): self.assertEqual(results["HostGenus"], "Mycobacterium") with self.subTest(): self.assertEqual(results["Sequence"].decode("utf-8"), "ATCG") with self.subTest(): self.assertEqual(results["Length"], 4) with self.subTest(): self.assertEqual(results["GC"], 0.5001) with self.subTest(): self.assertEqual(results["Status"], "final") with self.subTest(): self.assertEqual(results["DateLastModified"], constants.EMPTY_DATE) with self.subTest(): self.assertEqual(results["RetrieveRecord"], 1) with self.subTest(): self.assertEqual(results["AnnotationAuthor"], 1) with self.subTest(): self.assertIsNone(results["Cluster"]) with self.subTest(): self.assertEqual(results["Subcluster"], "A2")
def test_main_2(self, getpass_mock): """Verify frozen database is created from database with all genomes removed.""" getpass_mock.side_effect = [USER, PWD] self.unparsed_args.extend(["-f", "phage.Status != draft"]) run.main(self.unparsed_args) count2 = test_db_utils.get_data(COUNT_PHAGE, db=DB2) self.assertEqual(count2[0]["count"], 0)
def test_change_version_3(self): """Verify the version is decremented by 5.""" data = {"Version": 10, "SchemaVersion": 1} test_db_utils.insert_version_data(data) mysqldb.change_version(self.engine, amount=-5) result = test_db_utils.get_data(test_db_utils.version_table_query) output_value = result[0]["Version"] self.assertEqual(output_value, 5)
def test_queries_1(self): """Verify hard-coded SQL queries are structured correctly.""" version_data = test_db_utils.get_data(compare_db.VERSION_QUERY) phage_data = test_db_utils.get_data(compare_db.PHAGE_QUERY) gene_data = test_db_utils.get_data(compare_db.GENE_QUERY) ref_phage_data = test_db_utils.get_data( test_db_utils.phage_table_query) ref_gene_data = test_db_utils.get_data(test_db_utils.gene_table_query) with self.subTest(): self.assertEqual(len(version_data), 1) with self.subTest(): self.assertEqual(len(phage_data), len(ref_phage_data)) with self.subTest(): self.assertEqual(len(gene_data), len(ref_gene_data))
def test_change_version_1(self): """Verify the version is incremented by 1.""" data = {"Version": 10, "SchemaVersion": 1} test_db_utils.insert_data(VERSION, data) mysqldb.change_version(self.engine) result = test_db_utils.get_data(test_db_utils.version_table_query) output_value = result[0]["Version"] self.assertEqual(output_value, 11)
def test_execute_transaction_1(self): """Verify function runs with list of zero statements.""" result = find_domains.execute_transaction(self.connection) domain_table_results = test_db_utils.get_data( test_db_utils.domain_table_query) with self.subTest(): self.assertEqual(len(domain_table_results), 0) with self.subTest(): self.assertEqual(result, 0)
def test_main_1(self, alchemy_mock): """Verify update runs with empty ticket table.""" alchemy_mock.return_value = self.alchemist create_update_table([], update_table) unparsed_args = get_unparsed_args(file=update_table) run.main(unparsed_args) version_table = test_db_utils.get_data(test_db_utils.version_table_query) phage_table = test_db_utils.get_data(test_db_utils.phage_table_query) data_dict = phage_id_dict(phage_table) alice = data_dict["Alice"] trixie = data_dict["Trixie"] # Nothing should be different. with self.subTest(): self.assertEqual(alice["HostGenus"], "unknown") with self.subTest(): self.assertEqual(trixie["HostGenus"], "unknown") with self.subTest(): self.assertEqual(version_table[0]["Version"], 0)
def test_execute_statement_5(self): """Verify invalid data can NOT be inserted into domain table when there is a duplicated HitID.""" domain_data = test_data_utils.get_trixie_domain_data() statement = get_domain_insert_statement(domain_data) results_tup1 = find_domains.execute_statement(self.connection, statement) result1 = results_tup1[0] type_error1 = results_tup1[1] value_error1 = results_tup1[2] msg1 = results_tup1[3] self.trans.commit() domain_table_results1 = test_db_utils.get_data( test_db_utils.domain_table_query) new_trans = self.connection.begin() results_tup2 = find_domains.execute_statement(self.connection, statement) result2 = results_tup2[0] type_error2 = results_tup2[1] value_error2 = results_tup2[2] msg2 = results_tup2[3] new_trans.commit() domain_table_results2 = test_db_utils.get_data( test_db_utils.domain_table_query) with self.subTest(): self.assertEqual(len(domain_table_results1), 1) with self.subTest(): self.assertEqual(len(domain_table_results2), 1) with self.subTest(): self.assertEqual(result1, 0) with self.subTest(): self.assertEqual(result2, 0) with self.subTest(): self.assertFalse(type_error1) with self.subTest(): self.assertFalse(type_error2) with self.subTest(): self.assertFalse(value_error1) with self.subTest(): self.assertFalse(value_error2) with self.subTest(): self.assertFalse(error_msg in msg1) with self.subTest(): self.assertTrue(error_msg in msg2)
def test_execute_statement_1(self): """Verify valid DomainStatus update data can be inserted into gene table.""" gene_table_results1 = test_db_utils.get_data( test_db_utils.gene_table_query) update_data = get_trixie_gene_table_domain_status_update_data_1() statement = get_gene_update_statement(update_data) results_tup = find_domains.execute_statement(self.connection, statement) result = results_tup[0] type_error = results_tup[1] value_error = results_tup[2] msg = results_tup[3] self.trans.commit() phage_table_results = test_db_utils.get_data( test_db_utils.phage_table_query) gene_table_results2 = test_db_utils.get_data( test_db_utils.gene_table_query) gene_domain_table_results = test_db_utils.get_data( test_db_utils.gene_domain_table_query) domain_table_results = test_db_utils.get_data( test_db_utils.domain_table_query) domain_status1 = gene_table_results1[0]["DomainStatus"] domain_status2 = gene_table_results2[0]["DomainStatus"] with self.subTest(): self.assertEqual(len(phage_table_results), 1) with self.subTest(): self.assertEqual(len(gene_table_results2), 1) with self.subTest(): self.assertEqual(len(domain_table_results), 0) with self.subTest(): self.assertEqual(len(gene_domain_table_results), 0) with self.subTest(): self.assertEqual(domain_status1, 0) with self.subTest(): self.assertEqual(domain_status2, 1) with self.subTest(): self.assertEqual(result, 0) with self.subTest(): self.assertFalse(type_error) with self.subTest(): self.assertFalse(value_error) with self.subTest(): self.assertIsInstance(msg, str)
def test_execute_transaction_3(self): """Verify list of two valid statements can be inserted into domain and gene_domain tables""" domain_data = test_data_utils.get_trixie_domain_data() statement1 = get_domain_insert_statement(domain_data) gene_domain_data = test_data_utils.get_trixie_gene_domain_data() statement2 = get_gene_domain_insert_statement(gene_domain_data) statements = [statement1, statement2] result = find_domains.execute_transaction(self.connection, statements) gene_domain_table_results = test_db_utils.get_data( test_db_utils.gene_domain_table_query) domain_table_results = test_db_utils.get_data( test_db_utils.domain_table_query) with self.subTest(): self.assertEqual(len(domain_table_results), 1) with self.subTest(): self.assertEqual(len(gene_domain_table_results), 1) with self.subTest(): self.assertEqual(result, 0)
def test_main_11(self, getpass_mock): """Verify frozen database is created from database using quoted filter value.""" getpass_mock.side_effect = [USER, PWD] stmt = create_update("phage", "Status", "final", "Trixie") test_db_utils.execute(stmt) self.unparsed_args.extend(["-f", "phage.Status != 'draft'"]) run.main(self.unparsed_args) count2 = test_db_utils.get_data(COUNT_PHAGE, db=DB2) self.assertEqual(count2[0]["count"], 1)
def test_main_1(self, getpass_mock): """Verify database is installed from file.""" getpass_mock.side_effect = [USER, PWD] unparsed_args = get_unparsed_args(option="file") run.main(unparsed_args) # Query for version data. This verifies that the databases exists # and that it contains a pdm_utils schema with data. version_data = test_db_utils.get_data( test_db_utils.version_table_query) self.assertEqual(len(version_data), 1)
def test_create_gene_table_insert_1(self): """Verify gene table INSERT statement is created correctly when locus_tag is not empty and description contains a "'".""" # Note: even though this function returns a string and doesn't # actually utilize a MySQL database, this test ensures # that the returned statement will function properly in MySQL. cds1 = cds.Cds() cds1.id = "SEA_TRIXIE_123" cds1.genome_id = "Trixie" cds1.start = 5 cds1.stop = 10 cds1.parts = 1 cds1.translation_length = 20 cds1.length = 200 cds1.name = "Int" cds1.type = "CDS" cds1.translation = Seq("ACKLG", IUPAC.protein) cds1.orientation = "F" cds1.description = "5' nucleotide phosphatase" cds1.locus_tag = "TAG1" statement = mysqldb.create_gene_table_insert(cds1) test_db_utils.execute(statement) result = test_db_utils.get_data(GENE_QUERY2) results = result[0] exp = ("""INSERT INTO gene """ """(GeneID, PhageID, Start, Stop, Length, Name, """ """Translation, Orientation, Notes, LocusTag, Parts) """ """VALUES """ """("SEA_TRIXIE_123", "Trixie", 5, 10, 200, "Int", """ """"ACKLG", "F", "5' nucleotide phosphatase", "TAG1", 1);""") with self.subTest(): self.assertEqual(statement, exp) with self.subTest(): self.assertEqual(results["GeneID"], "SEA_TRIXIE_123") with self.subTest(): self.assertEqual(results["PhageID"], "Trixie") with self.subTest(): self.assertEqual(results["Start"], 5) with self.subTest(): self.assertEqual(results["Stop"], 10) with self.subTest(): self.assertEqual(results["Parts"], 1) with self.subTest(): self.assertEqual(results["Length"], 200) with self.subTest(): self.assertEqual(results["Name"], "Int") with self.subTest(): self.assertEqual(results["Translation"].decode("utf-8"), "ACKLG") with self.subTest(): self.assertEqual(results["Orientation"], "F") with self.subTest(): self.assertEqual(results["Notes"].decode("utf-8"), "5' nucleotide phosphatase") with self.subTest(): self.assertEqual(results["LocusTag"], "TAG1")