From 41e754222070ef7ee9110458937660ecd993c1b0 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 4 Mar 2008 20:14:28 +0000 Subject: [PATCH] unit test for mutable PGArray, thanks to AlexB !!! --- test/dialect/postgres.py | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) 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): -- 2.47.3