def test_command_if(self):
        
        #
        # COMMAND NODE
        #
 
        se = rQ.ServiceRepositoryHolder.get("Test.Command.if")
        self.assertIsNotNone(se)
        snActual = rQ.prepareCommandBlock(se)
 
        snExpected = StatementNode("serviceRoot").append(StatementNode("parameters"),
                        StatementNode("if").append(
                            StatementNode("sql"), StatementNode("sql"), StatementNode("else"), StatementNode("sql"),
                            StatementNode("end")
                        ))
 
        rQ.assertStatementNodeEquals(snExpected, snActual)
 
        #
        # REQUEST RUN
        #
 
        request = rQ.Request().setServiceId("Test.Command.if").put("name", "hello") 
        r = request.run()
        self.assertTrue(len(r) > 0)
        m = r.toList()
        self.assertEqual("true", m[0]["value"])
        request.put("name", "blabla")
        r = request.run()
        self.assertTrue(len(r) > 0)
        self.assertEqual("false", r.toList()[0]["value"]);
 def test_command_if_else_only(self):
     
     serviceId = "Test.Command.if_elseOnly"
 
     #
     # COMMAND NODE
     #
 
     se = rQ.ServiceRepositoryHolder.get(serviceId)
     self.assertIsNotNone(se)
     cb = rQ.prepareCommandBlock(se)
 
     cbExpected = StatementNode("serviceRoot").append(
         #
              StatementNode("put"),
               StatementNode("if").append(
                 #
                      StatementNode("else"),
                 #
                      StatementNode("put"),
                 #
                      StatementNode("end")
         #
         ))
 
     rQ.assertStatementNodeEquals(cbExpected, cb)
 
     #
     # REQUEST RUN
     #
 
     request = rQ.Request().setServiceId(serviceId)
 
     request.run()
     self.assertEqual("true", request.get("elseValue"))
 
     request.put("condition1", "hello")  
 
     request.run()   
 
     self.assertEqual("not reached else", request.get("elseValue"))
Ejemplo n.º 3
0
    def test_command_while(self):
        
        serviceId = "Test.Command.while"
        
        #
        # COMMAND NODE
        #
        
        se = rQ.ServiceRepositoryHolder.get(serviceId)
        self.assertIsNotNone(se)
        cb = rQ.prepareCommandBlock(se)
 
        cbExpected = StatementNode("serviceRoot").append(
                #
                StatementNode("sql"),
                #
                StatementNode("sql"),
                #
                StatementNode("sql"),
                #
                StatementNode("set"),
                #
                StatementNode("while").append(
                        #
                        StatementNode("sql"),
                        #
                        StatementNode("parameters"),
                        #
                        StatementNode("end")),
                #
                StatementNode("sql"));

        rQ.assertStatementNodeEquals(cbExpected, cb)
 
        #
        # REQUEST RUN
        #
 
        request = rQ.Request().setServiceId(serviceId) 
        r = request.run()
        self.assertTrue(len(r) == 0)
    def test_command_foreach(self):
        
        serviceId = "Test.Command.foreach"
        
        #
        # COMMAND NODE
        #
        
        se = rQ.ServiceRepositoryHolder.get(serviceId)
        self.assertIsNotNone(se)
        cb = rQ.prepareCommandBlock(se)

        cbExpected = StatementNode("serviceRoot").append(
                #
                StatementNode("parameters"),
                #
                StatementNode("foreach").append(
                        #
                        StatementNode("sql"),
                        #
                        StatementNode("end")),
                #
                StatementNode("sql"),
                #
                StatementNode("parameters"));
 
        rQ.assertStatementNodeEquals(cbExpected, cb)

        #
        # REQUEST RUN
        #
        
        request = rQ.Request().setServiceId(serviceId)
        request.run()
        total1 = request.get("total1")
        total2 = request.get("total2")
        self.assertIsNotNone(total1)
        self.assertIsNotNone(total2)
Ejemplo n.º 5
0
    def test_assert_statement_node(self):
        a1 = StatementNode("serviceRoot").append(
            StatementNode("parameters"),
            StatementNode("if").append(StatementNode("sql"),
                                       StatementNode("sql"),
                                       StatementNode("else"),
                                       StatementNode("sql"),
                                       StatementNode("end")))

        a2 = StatementNode("serviceRoot").append(
            StatementNode("parameters"),
            StatementNode("if").append(StatementNode("sql"),
                                       StatementNode("sql"),
                                       StatementNode("else"),
                                       StatementNode("sql"),
                                       StatementNode("end")))
        self.assertTrue(rQ.assertStatementNodeEquals(a1, a2))