예제 #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)
예제 #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)
예제 #3
0
 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)
예제 #4
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)
예제 #5
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)
예제 #6
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)
예제 #7
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)