예제 #1
0
    def test_des_dml_messages(self):
        """ Check that get_des_messages_solution() returns the correct messages """
        problem = DMLProblem(
            title_md='Test DML',
            text_md='bla bla bla',
            create_sql="CREATE TABLE t(name VARCHAR(20) PRIMARY KEY, age INT)",
            insert_sql=
            "INSERT INTO t VALUES ('pepe', 3); INSERT INTO t VALUES ('ana', 13);",
            solution="INSERT INTO t VALUES ('eva', 18)")

        code = [
            "INSERT INTO t VALUES('pepe', 48)",  # Primary key error
            "INSERT INTO t VALUES ('eva', 18)",  # OK
            "UPDATE t SET age = 0 WHERE age = -9",  # No tuple met the condition
            "DELETE FROM t WHERE age = 10"
        ]  # No tuple met the condition
        msgs = problem.get_des_messages_solution(";\n".join(code))
        self.assertEqual(len(msgs), 3)

        # Message for INSERT (pepe, 48)
        self.assertEqual(msgs[0][0], DesMessageType.ERROR)
        self.assertIn('Primary key violation', msgs[0][1])
        self.assertEqual(code[0], msgs[0][2])  # The statement is the snippet

        # Message for UPDATE
        self.assertEqual(msgs[1][0], DesMessageType.WARNING)
        self.assertIn("No tuple met the 'where' condition for updating",
                      msgs[1][1])
        self.assertEqual(code[2], msgs[1][2])  # The statement is the snippet

        # Message for DELETE
        self.assertEqual(msgs[2][0], DesMessageType.WARNING)
        self.assertIn("No tuple met the 'where' condition for deleting",
                      msgs[2][1])
        self.assertEqual(code[3], msgs[2][2])  # The statement is the snippet
예제 #2
0
 def test_des_dml_timeout(self):
     """ When DES timeouts DMLProblem.get_des_messages_solution returns [] """
     problem = DMLProblem(
         title_md='Test DML',
         text_md='bla bla bla',
         create_sql=self.__CREATE_TIMEOUT,
         insert_sql='',
         solution=f"INSERT INTO t ({self.__QUERY_TIMEOUT})")
     code = f"INSERT INTO t ({self.__QUERY_TIMEOUT})"
     messages = problem.get_des_messages_solution(code)
     self.assertEqual(messages, [])