~romaia/stoqlib/storm-old

« back to all changes in this revision

Viewing changes to external/sqlobject/tests/test_distinct.py

  • Committer: jdahlin
  • Date: 2006-09-18 16:01:22 UTC
  • Revision ID: vcs-imports@canonical.com-20060918160122-umda7g8dx7bdc53m
Add an external directory with formencode and SQLObject forks, remove SQLObject dependency from documentation and setup.py. Install externals and set sys.path in stoqlib/__init__.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from sqlobject import *
 
2
from sqlobject.tests.dbtest import *
 
3
 
 
4
########################################
 
5
## Distinct
 
6
########################################
 
7
 
 
8
class Distinct1(SQLObject):
 
9
    n = IntCol()
 
10
 
 
11
class Distinct2(SQLObject):
 
12
    other = ForeignKey('Distinct1')
 
13
 
 
14
def count(select):
 
15
    result = {}
 
16
    for ob in select:
 
17
        result[int(ob.n)] = result.get(int(ob.n), 0)+1
 
18
    return result
 
19
 
 
20
def test_distinct():
 
21
    setupClass([Distinct1, Distinct2])
 
22
    obs = [Distinct1(n=i) for i in range(3)]
 
23
    Distinct2(other=obs[0])
 
24
    Distinct2(other=obs[0])
 
25
    Distinct2(other=obs[1])
 
26
 
 
27
    query = (Distinct2.q.otherID==Distinct1.q.id)
 
28
    sel = Distinct1.select(query)
 
29
    assert count(sel) == {0: 2, 1: 1}
 
30
    sel = Distinct1.select(query, distinct=True)
 
31
    assert count(sel) == {0: 1, 1:1}