diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-06-10 21:18:24 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-06-10 21:18:24 +0000 |
| commit | 45cec095b4904ba71425d2fe18c143982dd08f43 (patch) | |
| tree | af5e540fdcbf1cb2a3337157d69d4b40be010fa8 /test/sql/case_statement.py | |
| parent | 698a3c1ac665e7cd2ef8d5ad3ebf51b7fe6661f4 (diff) | |
| download | sqlalchemy-45cec095b4904ba71425d2fe18c143982dd08f43.tar.gz | |
- unit tests have been migrated from unittest to nose.
See README.unittests for information on how to run
the tests. [ticket:970]
Diffstat (limited to 'test/sql/case_statement.py')
| -rw-r--r-- | test/sql/case_statement.py | 137 |
1 files changed, 0 insertions, 137 deletions
diff --git a/test/sql/case_statement.py b/test/sql/case_statement.py deleted file mode 100644 index 1d5383749..000000000 --- a/test/sql/case_statement.py +++ /dev/null @@ -1,137 +0,0 @@ -import testenv; testenv.configure_for_tests() -import sys -from sqlalchemy import * -from testlib import * -from sqlalchemy import util, exc -from sqlalchemy.sql import table, column - - -class CaseTest(TestBase, AssertsCompiledSQL): - - def setUpAll(self): - metadata = MetaData(testing.db) - global info_table - info_table = Table('infos', metadata, - Column('pk', Integer, primary_key=True), - Column('info', String(30))) - - info_table.create() - - info_table.insert().execute( - {'pk':1, 'info':'pk_1_data'}, - {'pk':2, 'info':'pk_2_data'}, - {'pk':3, 'info':'pk_3_data'}, - {'pk':4, 'info':'pk_4_data'}, - {'pk':5, 'info':'pk_5_data'}, - {'pk':6, 'info':'pk_6_data'}) - def tearDownAll(self): - info_table.drop() - - @testing.fails_on('firebird', 'FIXME: unknown') - @testing.fails_on('maxdb', 'FIXME: unknown') - @testing.requires.subqueries - def testcase(self): - inner = select([case([ - [info_table.c.pk < 3, - 'lessthan3'], - [and_(info_table.c.pk >= 3, info_table.c.pk < 7), - 'gt3']]).label('x'), - info_table.c.pk, info_table.c.info], - from_obj=[info_table]).alias('q_inner') - - inner_result = inner.execute().fetchall() - - # Outputs: - # lessthan3 1 pk_1_data - # lessthan3 2 pk_2_data - # gt3 3 pk_3_data - # gt3 4 pk_4_data - # gt3 5 pk_5_data - # gt3 6 pk_6_data - assert inner_result == [ - ('lessthan3', 1, 'pk_1_data'), - ('lessthan3', 2, 'pk_2_data'), - ('gt3', 3, 'pk_3_data'), - ('gt3', 4, 'pk_4_data'), - ('gt3', 5, 'pk_5_data'), - ('gt3', 6, 'pk_6_data') - ] - - outer = select([inner]) - - outer_result = outer.execute().fetchall() - - assert outer_result == [ - ('lessthan3', 1, 'pk_1_data'), - ('lessthan3', 2, 'pk_2_data'), - ('gt3', 3, 'pk_3_data'), - ('gt3', 4, 'pk_4_data'), - ('gt3', 5, 'pk_5_data'), - ('gt3', 6, 'pk_6_data') - ] - - w_else = select([case([ - [info_table.c.pk < 3, - 3], - [and_(info_table.c.pk >= 3, info_table.c.pk < 6), - 6]], - else_ = 0).label('x'), - info_table.c.pk, info_table.c.info], - from_obj=[info_table]).alias('q_inner') - - else_result = w_else.execute().fetchall() - - assert else_result == [ - (3, 1, 'pk_1_data'), - (3, 2, 'pk_2_data'), - (6, 3, 'pk_3_data'), - (6, 4, 'pk_4_data'), - (6, 5, 'pk_5_data'), - (0, 6, 'pk_6_data') - ] - - def test_literal_interpretation(self): - t = table('test', column('col1')) - - self.assertRaises(exc.ArgumentError, case, [("x", "y")]) - - self.assert_compile(case([("x", "y")], value=t.c.col1), "CASE test.col1 WHEN :param_1 THEN :param_2 END") - self.assert_compile(case([(t.c.col1==7, "y")], else_="z"), "CASE WHEN (test.col1 = :col1_1) THEN :param_1 ELSE :param_2 END") - - - @testing.fails_on('firebird', 'FIXME: unknown') - @testing.fails_on('maxdb', 'FIXME: unknown') - def testcase_with_dict(self): - query = select([case({ - info_table.c.pk < 3: 'lessthan3', - info_table.c.pk >= 3: 'gt3', - }, else_='other'), - info_table.c.pk, info_table.c.info - ], - from_obj=[info_table]) - assert query.execute().fetchall() == [ - ('lessthan3', 1, 'pk_1_data'), - ('lessthan3', 2, 'pk_2_data'), - ('gt3', 3, 'pk_3_data'), - ('gt3', 4, 'pk_4_data'), - ('gt3', 5, 'pk_5_data'), - ('gt3', 6, 'pk_6_data') - ] - - simple_query = select([case({ - 1: 'one', - 2: 'two', - }, value=info_table.c.pk, else_='other'), - info_table.c.pk - ], - whereclause=info_table.c.pk < 4, - from_obj=[info_table]) - - assert simple_query.execute().fetchall() == [ - ('one', 1), - ('two', 2), - ('other', 3), - ] - -if __name__ == "__main__": - testenv.main() |
