~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to test/orm/test_composites.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski, Jakub Wilk, Piotr Ożarowski
  • Date: 2013-07-06 20:53:52 UTC
  • mfrom: (1.4.23) (16.1.17 experimental)
  • Revision ID: package-import@ubuntu.com-20130706205352-ryppl1eto3illd79
Tags: 0.8.2-1
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Piotr Ożarowski ]
* New upstream release
* Upload to unstable
* Build depend on python3-all instead of -dev, extensions are not built for
  Python 3.X 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from test.lib.testing import assert_raises, assert_raises_message
 
1
from sqlalchemy.testing import assert_raises, assert_raises_message
2
2
import sqlalchemy as sa
3
 
from test.lib import testing
 
3
from sqlalchemy import testing
4
4
from sqlalchemy import MetaData, Integer, String, ForeignKey, func, \
5
5
    util, select
6
 
from test.lib.schema import Table, Column
 
6
from sqlalchemy.testing.schema import Table, Column
7
7
from sqlalchemy.orm import mapper, relationship, backref, \
8
8
    class_mapper, CompositeProperty, \
9
9
    validates, aliased
10
10
from sqlalchemy.orm import attributes, \
11
11
    composite, relationship, \
12
12
    Session
13
 
from test.lib.testing import eq_
14
 
from test.lib import fixtures
 
13
from sqlalchemy.testing import eq_
 
14
from sqlalchemy.testing import fixtures
15
15
from test.orm import _fixtures
16
16
 
17
17
 
172
172
        g = sess.query(Graph).first()
173
173
 
174
174
        assert sess.query(Edge).\
175
 
                    filter(Edge.start==Point(3, 4)).one() is \
 
175
                    filter(Edge.start == Point(3, 4)).one() is \
176
176
                    g.edges[0]
177
177
 
178
178
        assert sess.query(Edge).\
179
 
                    filter(Edge.start!=Point(3, 4)).first() is \
 
179
                    filter(Edge.start != Point(3, 4)).first() is \
180
180
                    g.edges[1]
181
181
 
182
182
        eq_(
183
 
            sess.query(Edge).filter(Edge.start==None).all(),
 
183
            sess.query(Edge).filter(Edge.start == None).all(),
184
184
            []
185
185
        )
186
186
 
 
187
    def test_comparator_aliased(self):
 
188
        Graph, Edge, Point = (self.classes.Graph,
 
189
                                self.classes.Edge,
 
190
                                self.classes.Point)
 
191
 
 
192
        sess = self._fixture()
 
193
 
 
194
        g = sess.query(Graph).first()
 
195
        ea = aliased(Edge)
 
196
        assert sess.query(ea).\
 
197
                    filter(ea.start != Point(3, 4)).first() is \
 
198
                    g.edges[1]
 
199
 
187
200
    def test_get_history(self):
188
201
        Edge = self.classes.Edge
189
202
        Point = self.classes.Point
587
600
        sess.commit()
588
601
 
589
602
        eq_(
590
 
            sess.query(A).filter(A.c==C('a2b1', b2)).one(),
 
603
            sess.query(A).filter(A.c == C('a2b1', b2)).one(),
 
604
            a2
 
605
        )
 
606
 
 
607
    def test_query_aliased(self):
 
608
        A, C, B = (self.classes.A,
 
609
                                self.classes.C,
 
610
                                self.classes.B)
 
611
 
 
612
        sess = Session()
 
613
        b1, b2 = B(data='b1'), B(data='b2')
 
614
        a1 = A(c=C('a1b1', b1))
 
615
        a2 = A(c=C('a2b1', b2))
 
616
        sess.add_all([a1, a2])
 
617
        sess.commit()
 
618
 
 
619
        ae = aliased(A)
 
620
        eq_(
 
621
            sess.query(ae).filter(ae.c == C('a2b1', b2)).one(),
591
622
            a2
592
623
        )
593
624
 
681
712
        })
682
713
        self._test_roundtrip()
683
714
 
684
 
class ComparatorTest(fixtures.MappedTest):
 
715
class ComparatorTest(fixtures.MappedTest, testing.AssertsCompiledSQL):
 
716
    __dialect__ = 'default'
 
717
 
685
718
    @classmethod
686
719
    def define_tables(cls, metadata):
687
720
        Table('edge', metadata,
805
838
 
806
839
        assert edge_1 in near_edges and edge_2 in near_edges
807
840
 
 
841
    def test_order_by(self):
 
842
        self._fixture(False)
 
843
        Edge = self.classes.Edge
 
844
        s = Session()
 
845
        self.assert_compile(
 
846
            s.query(Edge).order_by(Edge.start, Edge.end),
 
847
            "SELECT edge.id AS edge_id, edge.x1 AS edge_x1, "
 
848
            "edge.y1 AS edge_y1, edge.x2 AS edge_x2, edge.y2 AS edge_y2 "
 
849
            "FROM edge ORDER BY edge.x1, edge.y1, edge.x2, edge.y2"
 
850
        )
 
851
 
 
852
    def test_order_by_aliased(self):
 
853
        self._fixture(False)
 
854
        Edge = self.classes.Edge
 
855
        s = Session()
 
856
        ea = aliased(Edge)
 
857
        self.assert_compile(
 
858
            s.query(ea).order_by(ea.start, ea.end),
 
859
            "SELECT edge_1.id AS edge_1_id, edge_1.x1 AS edge_1_x1, "
 
860
            "edge_1.y1 AS edge_1_y1, edge_1.x2 AS edge_1_x2, "
 
861
            "edge_1.y2 AS edge_1_y2 "
 
862
            "FROM edge AS edge_1 ORDER BY edge_1.x1, edge_1.y1, "
 
863
            "edge_1.x2, edge_1.y2"
 
864
        )
808
865