@@ -53,6 +53,25 @@ def test_run_inserts(self):
53
53
assert actual == 1
54
54
55
55
56
+ # db.all
57
+ # ======
58
+
59
+ class TestRows (WithData ):
60
+
61
+ def test_rows_fetches_all_rows (self ):
62
+ actual = self .db .all ("SELECT * FROM foo ORDER BY bar" )
63
+ assert actual == [{"bar" : "baz" }, {"bar" : "buz" }]
64
+
65
+ def test_bind_parameters_as_dict_work (self ):
66
+ params = {"bar" : "baz" }
67
+ actual = self .db .all ("SELECT * FROM foo WHERE bar=%(bar)s" , params )
68
+ assert actual == [{"bar" : "baz" }]
69
+
70
+ def test_bind_parameters_as_tuple_work (self ):
71
+ actual = self .db .all ("SELECT * FROM foo WHERE bar=%s" , ("baz" ,))
72
+ assert actual == [{"bar" : "baz" }]
73
+
74
+
56
75
# db.one
57
76
# ======
58
77
# With all the combinations of strict_one and strict, we end up with a number
@@ -168,23 +187,27 @@ def test_one_raises_TooMany(self):
168
187
self .assertRaises (TooMany , self .db .one , "SELECT * FROM foo" )
169
188
170
189
171
- # db.all
172
- # ======
190
+ # db.one_or_zero
191
+ # ==============
173
192
174
- class TestRows (WithData ):
193
+ class TestOneOrZero (WithData ):
175
194
176
- def test_rows_fetches_all_rows (self ):
177
- actual = self .db .all ("SELECT * FROM foo ORDER BY bar" )
178
- assert actual == [{"bar" : "baz" }, {"bar" : "buz" }]
195
+ def test_one_or_zero_raises_TooFew (self ):
196
+ self .assertRaises ( TooFew
197
+ , self .db .one_or_zero
198
+ , "CREATE TABLE foux (baar text)"
199
+ )
179
200
180
- def test_bind_parameters_as_dict_work (self ):
181
- params = {"bar" : "baz" }
182
- actual = self .db .all ("SELECT * FROM foo WHERE bar=%(bar)s" , params )
183
- assert actual == [{"bar" : "baz" }]
201
+ def test_one_or_zero_returns_None (self ):
202
+ actual = self .db .one_or_zero ("SELECT * FROM foo WHERE bar='blam'" )
203
+ assert actual is None
184
204
185
- def test_bind_parameters_as_tuple_work (self ):
186
- actual = self .db .all ("SELECT * FROM foo WHERE bar=%s" , ("baz" ,))
187
- assert actual == [{"bar" : "baz" }]
205
+ def test_one_or_zero_returns_one (self ):
206
+ actual = self .db .one_or_zero ("SELECT * FROM foo WHERE bar='baz'" )
207
+ assert actual == {"bar" : "baz" }
208
+
209
+ def test_with_strict_True_one_raises_TooMany (self ):
210
+ self .assertRaises (TooMany , self .db .one_or_zero , "SELECT * FROM foo" )
188
211
189
212
190
213
# db.get_cursor
0 commit comments