From: Mike Bayer Date: Tue, 4 Mar 2008 20:14:28 +0000 (+0000) Subject: unit test for mutable PGArray, thanks to AlexB !!! X-Git-Tag: rel_0_4_4~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41e754222070ef7ee9110458937660ecd993c1b0;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git unit test for mutable PGArray, thanks to AlexB !!! --- diff --git a/test/dialect/postgres.py b/test/dialect/postgres.py index 71fb0c763f..21b11f114b 100644 --- a/test/dialect/postgres.py +++ b/test/dialect/postgres.py @@ -1,6 +1,7 @@ import testenv; testenv.configure_for_tests() import datetime from sqlalchemy import * +from sqlalchemy.orm import * from sqlalchemy import exceptions from sqlalchemy.databases import postgres from sqlalchemy.engine.strategies import MockEngineStrategy @@ -705,6 +706,47 @@ class ArrayTest(TestBase, AssertsExecutionResults): self.assertEquals(results[1]['strarr'], [[u'm\xe4\xe4'], [u'm\xf6\xf6']]) arrtable.delete().execute() + def test_array_mutability(self): + class Foo(object): pass + footable = Table('foo', metadata, + Column('id', Integer, primary_key=True), + Column('intarr', postgres.PGArray(Integer), nullable=True) + ) + mapper(Foo, footable) + metadata.create_all() + sess = create_session() + + foo = Foo() + foo.id = 1 + foo.intarr = [1,2,3] + sess.save(foo) + sess.flush() + sess.clear() + foo = sess.query(Foo).get(1) + self.assertEquals(foo.intarr, [1,2,3]) + + foo.intarr.append(4) + sess.flush() + sess.clear() + foo = sess.query(Foo).get(1) + self.assertEquals(foo.intarr, [1,2,3,4]) + + foo.intarr = [] + sess.flush() + sess.clear() + self.assertEquals(foo.intarr, []) + + foo.intarr = None + sess.flush() + sess.clear() + self.assertEquals(foo.intarr, None) + + # Errors in r4217: + foo = Foo() + foo.id = 2 + sess.save(foo) + sess.flush() + class TimeStampTest(TestBase, AssertsExecutionResults): __only_on__ = 'postgres' def test_timestamp(self):