Skip to content

Commit c517f07

Browse files
committed
Start a test suite for the ORM
1 parent 831a95f commit c517f07

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,41 @@ def test_get_connection_gets_a_connection(self):
216216
assert actual == [{"bar": "baz"}, {"bar": "buz"}]
217217

218218

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+
219254
# cursor_factory
220255
# ==============
221256

0 commit comments

Comments
 (0)