Ejemplo n.º 1
0
 def test_compile_case(self):
     """The Case expr is compiled in a Postgres' CASE expression."""
     cases = [(Column("foo") > 3, u"big"), (Column("bar") == None, 4)]
     state = State()
     statement = compile(Case(cases), state)
     assert statement == (
         "CASE WHEN (foo > ?) THEN ? WHEN (bar IS NULL) THEN ? END")
     assert [3, "big", 4] == [param.get() for param in state.parameters]
Ejemplo n.º 2
0
 def test_compile_case_with_default(self):
     """
     If a default is provided, the resulting CASE expression includes
     an ELSE clause.
     """
     cases = [(Column("foo") > 3, u"big")]
     state = State()
     statement = compile(Case(cases, default=9), state)
     assert "CASE WHEN (foo > ?) THEN ? ELSE ? END" == statement
     assert [3, "big", 9] == [param.get() for param in state.parameters]
Ejemplo n.º 3
0
 def test_compile_case_with_expression(self):
     """
     If an expression is provided, the resulting CASE expression uses the
     simple syntax.
     """
     cases = [(1, u"one"), (2, u"two")]
     state = State()
     statement = compile(Case(cases, expression=Column("foo")), state)
     self.assertEqual("CASE foo WHEN ? THEN ? WHEN ? THEN ? END", statement)
     self.assertEqual([1, "one", 2, "two"],
                      [param.get() for param in state.parameters])