~divmod-dev/divmod.org/dangling-1091

« back to all changes in this revision

Viewing changes to Axiom/axiom/test/test_query.py

  • Committer: glyph
  • Date: 2005-07-28 22:09:16 UTC
  • Revision ID: svn-v4:866e43f7-fbfc-0310-8f2a-ec88d1da2979:trunk:2
move this repository to a more official-looking URL

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
from twisted.trial.unittest import TestCase
 
3
 
 
4
from axiom.store import Store
 
5
from axiom.item import Item
 
6
from axiom.attributes import reference, text, bytes, AND
 
7
 
 
8
class A(Item):
 
9
    schemaVersion = 1
 
10
    typeName = 'a'
 
11
 
 
12
    reftoc = reference()
 
13
    type = text(indexed=True)
 
14
 
 
15
 
 
16
class B(Item):
 
17
    schemaVersion = 1
 
18
    typeName = 'b'
 
19
 
 
20
    cref = reference()
 
21
    name = text(indexed=True)
 
22
 
 
23
class C(Item):
 
24
    schemaVersion = 1
 
25
    typeName = 'c'
 
26
 
 
27
    name = text(indexed=True)
 
28
 
 
29
class ThingWithCharacterAndByteStrings(Item):
 
30
    schemaVersion = 1
 
31
 
 
32
    typeName = 'ThingWithCharacterAndByteStrings'
 
33
 
 
34
    characterString = text(caseSensitive=True)
 
35
    caseInsensitiveCharString = text(caseSensitive=False)
 
36
 
 
37
    byteString = bytes()
 
38
 
 
39
 
 
40
class BasicQuery(TestCase):
 
41
 
 
42
    def testBasicQuery(self):
 
43
        s = Store()
 
44
 
 
45
        def entesten():
 
46
            c1 = C(store=s,
 
47
                   name=u'yes')
 
48
 
 
49
            c2 = C(store=s,
 
50
                   name=u'no')
 
51
 
 
52
            A(store=s,
 
53
              reftoc=c1,
 
54
              type=u'testc')
 
55
 
 
56
            A(store=s,
 
57
              reftoc=c2,
 
58
              type=u'testc')
 
59
 
 
60
            A(store=s,
 
61
              reftoc=c1,
 
62
              type=u'testx')
 
63
 
 
64
            yesb = B(store=s,
 
65
                     cref=c1,
 
66
                     name=u'correct')
 
67
 
 
68
            B(store=s,
 
69
              cref=c2,
 
70
              name=u'not correct')
 
71
 
 
72
            s.checkpoint()
 
73
 
 
74
            q = list(s.query(B,
 
75
                             AND(AND(C.name == u'yes',
 
76
                                     A.type == u'testc'),
 
77
                                 AND(C.storeID == B.cref,
 
78
                                     A.reftoc == C.storeID)),
 
79
                             ))
 
80
 
 
81
            self.assertEquals(q, [yesb])
 
82
 
 
83
        s.transact(entesten)
 
84
        s.close()
 
85
 
 
86
 
 
87
    def testStringQueries(self):
 
88
        s = Store()
 
89
 
 
90
        def createAndStuff():
 
91
            text1 = u'Hello, \u1234 world.'
 
92
            text2 = u'ThIs sTrInG iS nOt cAsE sEnSiTIvE.  \u4567'
 
93
            bytes1 = '\x00, punk'
 
94
 
 
95
            x = ThingWithCharacterAndByteStrings(
 
96
                store=s,
 
97
                characterString=text1,
 
98
                caseInsensitiveCharString=text2,
 
99
                byteString=bytes1)
 
100
 
 
101
            x.checkpoint()
 
102
 
 
103
            q = list(
 
104
                s.query(ThingWithCharacterAndByteStrings,
 
105
                        ThingWithCharacterAndByteStrings.characterString == text1.lower(),
 
106
                        ))
 
107
            self.failIf(q, q)
 
108
 
 
109
            q = list(
 
110
                s.query(ThingWithCharacterAndByteStrings,
 
111
                        ThingWithCharacterAndByteStrings.characterString == text1.upper(),
 
112
                        ))
 
113
            self.failIf(q, q)
 
114
 
 
115
            q = list(
 
116
                s.query(ThingWithCharacterAndByteStrings,
 
117
                        ThingWithCharacterAndByteStrings.characterString == text1,
 
118
                        ))
 
119
 
 
120
            self.assertEquals(q, [x])
 
121
 
 
122
            q = list(
 
123
                s.query(ThingWithCharacterAndByteStrings,
 
124
                        ThingWithCharacterAndByteStrings.caseInsensitiveCharString == text2,
 
125
                        ))
 
126
 
 
127
            self.assertEquals(q, [x])
 
128
 
 
129
            q = list(
 
130
                s.query(ThingWithCharacterAndByteStrings,
 
131
                        ThingWithCharacterAndByteStrings.caseInsensitiveCharString == text2.lower(),
 
132
                        ))
 
133
 
 
134
            self.assertEquals(q, [x])
 
135
 
 
136
            q = list(
 
137
                s.query(ThingWithCharacterAndByteStrings,
 
138
                        ThingWithCharacterAndByteStrings.caseInsensitiveCharString == text2.upper(),
 
139
                        ))
 
140
 
 
141
            self.assertEquals(q, [x])
 
142
 
 
143
            q = list(
 
144
                s.query(ThingWithCharacterAndByteStrings,
 
145
                        ThingWithCharacterAndByteStrings.byteString == bytes1,
 
146
                        ))
 
147
 
 
148
            self.assertEquals(q, [x])
 
149
 
 
150
            q = list(
 
151
                s.query(ThingWithCharacterAndByteStrings,
 
152
                        ThingWithCharacterAndByteStrings.byteString == bytes1.upper(),
 
153
                        ))
 
154
 
 
155
            self.failIf(q, q)
 
156
 
 
157
        s.transact(createAndStuff)
 
158
        s.close()
 
159