File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -216,6 +216,41 @@ def test_get_connection_gets_a_connection(self):
216
216
assert actual == [{"bar" : "baz" }, {"bar" : "buz" }]
217
217
218
218
219
+ # orm
220
+ # ===
221
+
222
+ class TestORM (WithData ):
223
+
224
+ from postgres .orm import Model
225
+
226
+ class MyModel (Model ):
227
+
228
+ typname = "foo"
229
+
230
+ def update_bar (self , bar ):
231
+ self .db .run ( "UPDATE foo SET bar=%s WHERE bar=%s"
232
+ , (bar , self .bar )
233
+ )
234
+ self .update_attributes (bar = bar )
235
+
236
+ def setUp (self ):
237
+ WithData .setUp (self )
238
+ self .db .register_model (self .MyModel )
239
+
240
+ def tearDown (self ):
241
+ self .db .model_registry = {}
242
+
243
+ def test_orm_basically_works (self ):
244
+ one = self .db .one ("SELECT foo.*::foo FROM foo WHERE bar='baz'" )
245
+ assert one .__class__ == self .MyModel
246
+
247
+ def test_updating_attributes_works (self ):
248
+ one = self .db .one ("SELECT foo.*::foo FROM foo WHERE bar='baz'" )
249
+ one .update_bar ("blah" )
250
+ bar = self .db .one ("SELECT bar FROM foo WHERE bar='blah'" )
251
+ assert bar == one .bar
252
+
253
+
219
254
# cursor_factory
220
255
# ==============
221
256
You can’t perform that action at this time.
0 commit comments