Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 def test_execute_transaction_2(self):
     """Verify list of one valid statement can be inserted into domain table."""
     domain_data = test_data_utils.get_trixie_domain_data()
     statement = get_domain_insert_statement(domain_data)
     statements = [statement]
     result = find_domains.execute_transaction(self.connection, statements)
     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)
Ejemplo n.º 6
0
    def test_execute_transaction_7(self):
        """Verify list of three valid statements and one invalid statement
        (containing '% w') are inserted (since '% w' replaced with '%% w')."""
        # 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 '% w'
        domain_data2 = test_data_utils.get_trixie_domain_data()
        # "Description": "ParB-like nuclease domain"
        description = domain_data2["Description"]
        description = description.replace("nuclease domain",
                                          "nuclease % wdomain")
        domain_data2["Description"] = description
        domain_data2["HitID"] = "unique_id"
        statement3 = get_domain_insert_statement(domain_data2)
        # Valid
        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), 2)
        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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
 def test_execute_statement_2(self):
     """Verify valid data can be inserted into domain table."""
     domain_data = test_data_utils.get_trixie_domain_data()
     statement = get_domain_insert_statement(domain_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()
     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)
Ejemplo n.º 10
0
    def test_execute_transaction_8(self, es_mock):
        """Verify error inside try/except block is executed."""
        stmt_result1 = 0
        type_error1 = False
        # TODO make sure this is set correctly
        value_error1 = False

        msg1 = "empty"
        mock_result1 = (stmt_result1, type_error1, value_error1, msg1)

        stmt_result2 = 0
        type_error2 = False
        # TODO make sure this is set correctly
        value_error2 = False

        msg2 = 2  # the function expects this to be a string, so this should
        # break the code and trigger the except block.
        mock_result2 = (stmt_result2, type_error2, value_error2, msg2)
        es_mock.side_effect = [mock_result1, mock_result2]
        # 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)

        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), 0)
        with self.subTest():
            self.assertEqual(len(gene_domain_table_results), 0)
        with self.subTest():
            self.assertEqual(result, 1)
        with self.subTest():
            self.assertEqual(es_mock.call_count, 2)
Ejemplo n.º 11
0
 def test_execute_statement_3(self):
     """Verify valid data 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)
     results_tup1 = find_domains.execute_statement(self.connection,
                                                   statement1)
     result1 = results_tup1[0]
     type_error1 = results_tup1[1]
     value_error1 = results_tup1[2]
     msg1 = results_tup1[3]
     gene_domain_data = test_data_utils.get_trixie_gene_domain_data()
     statement2 = get_gene_domain_insert_statement(gene_domain_data)
     results_tup2 = find_domains.execute_statement(self.connection,
                                                   statement2)
     result2 = results_tup2[0]
     type_error2 = results_tup2[1]
     value_error2 = results_tup2[2]
     msg2 = results_tup2[3]
     self.trans.commit()
     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(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)