~ubuntu-branches/debian/sid/sqlalchemy/sid

« back to all changes in this revision

Viewing changes to test/orm/test_query.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2014-06-27 20:17:13 UTC
  • mfrom: (1.4.28)
  • Revision ID: package-import@ubuntu.com-20140627201713-g6p1kq8q1qenztrv
Tags: 0.9.6-1
* New upstream release
* Remove Python 3.X build tag files, thanks to Matthias Urlichs for the
  patch (closes: #747852)
* python-fdb isn't in the Debian archive yet so default dialect for firebird://
  URLs is changed to obsolete kinterbasdb, thanks to Russell Stuart for the
  patch (closes: #752145)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from sqlalchemy.sql import operators
2
2
from sqlalchemy import MetaData, null, exists, text, union, literal, \
3
3
    literal_column, func, between, Unicode, desc, and_, bindparam, \
4
 
    select, distinct, or_, collate, insert, Integer, String
 
4
    select, distinct, or_, collate, insert, Integer, String, Boolean
5
5
from sqlalchemy import inspect
6
6
from sqlalchemy import exc as sa_exc, util
7
7
from sqlalchemy.sql import compiler, table, column
550
550
 
551
551
        u.addresses[0].email_address = 'lala'
552
552
        u.orders[1].items[2].description = 'item 12'
553
 
        # test that lazy load doesnt change child items
 
553
        # test that lazy load doesn't change child items
554
554
        s.query(User).populate_existing().all()
555
555
        assert u.addresses[0].email_address == 'lala'
556
556
        assert u.orders[1].items[2].description == 'item 12'
1383
1383
        assert [Address(id=2), Address(id=3), Address(id=4)] == \
1384
1384
            sess.query(Address).join("user").filter(Address.user.has(User.name.like('%ed%'), id=8)).order_by(Address.id).all()
1385
1385
 
1386
 
        # test has() doesnt' get subquery contents adapted by aliased join
 
1386
        # test has() doesn't get subquery contents adapted by aliased join
1387
1387
        assert [Address(id=2), Address(id=3), Address(id=4)] == \
1388
1388
            sess.query(Address).join("user", aliased=True).filter(Address.user.has(User.name.like('%ed%'), id=8)).order_by(Address.id).all()
1389
1389
 
2550
2550
        q1.all()
2551
2551
 
2552
2552
 
 
2553
class BooleanEvalTest(fixtures.TestBase, testing.AssertsCompiledSQL):
 
2554
    """test standalone booleans being wrapped in an AsBoolean, as well
 
2555
    as true/false compilation."""
 
2556
 
 
2557
    def _dialect(self, native_boolean):
 
2558
        d = default.DefaultDialect()
 
2559
        d.supports_native_boolean = native_boolean
 
2560
        return d
 
2561
 
 
2562
    def test_one(self):
 
2563
        s = Session()
 
2564
        c = column('x', Boolean)
 
2565
        self.assert_compile(
 
2566
            s.query(c).filter(c),
 
2567
            "SELECT x AS x WHERE x",
 
2568
            dialect=self._dialect(True)
 
2569
        )
 
2570
 
 
2571
    def test_two(self):
 
2572
        s = Session()
 
2573
        c = column('x', Boolean)
 
2574
        self.assert_compile(
 
2575
            s.query(c).filter(c),
 
2576
            "SELECT x AS x WHERE x = 1",
 
2577
            dialect=self._dialect(False)
 
2578
        )
 
2579
 
 
2580
    def test_three(self):
 
2581
        s = Session()
 
2582
        c = column('x', Boolean)
 
2583
        self.assert_compile(
 
2584
            s.query(c).filter(~c),
 
2585
            "SELECT x AS x WHERE x = 0",
 
2586
            dialect=self._dialect(False)
 
2587
        )
 
2588
 
 
2589
    def test_four(self):
 
2590
        s = Session()
 
2591
        c = column('x', Boolean)
 
2592
        self.assert_compile(
 
2593
            s.query(c).filter(~c),
 
2594
            "SELECT x AS x WHERE NOT x",
 
2595
            dialect=self._dialect(True)
 
2596
        )
 
2597
 
 
2598
    def test_five(self):
 
2599
        s = Session()
 
2600
        c = column('x', Boolean)
 
2601
        self.assert_compile(
 
2602
            s.query(c).having(c),
 
2603
            "SELECT x AS x HAVING x = 1",
 
2604
            dialect=self._dialect(False)
 
2605
        )
 
2606