diff options
| author | Jason Pellerin <jpellerin@gmail.com> | 2006-02-05 14:43:10 +0000 |
|---|---|---|
| committer | Jason Pellerin <jpellerin@gmail.com> | 2006-02-05 14:43:10 +0000 |
| commit | 6f11c56230784d523c8eb04632080c037ed0e5c1 (patch) | |
| tree | dd05fcea9fe2bd51c12095fc1dcf9421744bf0b1 /test/proxy_engine.py | |
| parent | 1d20ecbb6d0f0f8cfbb0a54e2a3aaf6cead23ecb (diff) | |
| download | sqlalchemy-6f11c56230784d523c8eb04632080c037ed0e5c1.tar.gz | |
Provisional fix for #51, very slightly adapted from the patch posted in the ticket. Tests added to verify fix.
Diffstat (limited to 'test/proxy_engine.py')
| -rw-r--r-- | test/proxy_engine.py | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/test/proxy_engine.py b/test/proxy_engine.py index 7d508481e..150752f65 100644 --- a/test/proxy_engine.py +++ b/test/proxy_engine.py @@ -27,7 +27,6 @@ class ProxyEngineTest(PersistTest): objectstore.clear() def test_engine_connect(self): - # connect to a real engine module_engine.connect(testbase.db_uri) users.create() @@ -110,7 +109,6 @@ class ProxyEngineTest(PersistTest): def test_table_singleton_a(self): """set up for table singleton check """ - # # For this 'test', create a proxy engine instance, connect it # to a real engine, and make it do some work @@ -131,7 +129,6 @@ class ProxyEngineTest(PersistTest): """check that a table on a 2nd proxy engine instance gets 2nd table instance """ - # # Now create a new proxy engine instance and attach the same # table as the first test. This should result in 2 table instances, @@ -163,7 +160,7 @@ class ProxyEngineTest(PersistTest): return 'a' def type_descriptor(self, typeobj): - if typeobj == type(1): + if typeobj == types.Integer: return TypeEngineX2() else: return TypeEngineSTR() @@ -193,19 +190,65 @@ class ProxyEngineTest(PersistTest): engine = ProxyEngine() engine.storage.engine = EngineA() - a = engine.type_descriptor(type(1)) + a = engine.type_descriptor(sqltypes.Integer) assert a.convert_bind_param(12, engine) == 24 assert a.convert_bind_param([1,2,3], engine) == [1, 2, 3, 1, 2, 3] - a2 = engine.type_descriptor(type('hi')) + a2 = engine.type_descriptor(sqltypes.String) assert a2.convert_bind_param(12, engine) == "'12'" assert a2.convert_bind_param([1,2,3], engine) == "'[1, 2, 3]'" engine.storage.engine = EngineB() - b = engine.type_descriptor(type(1)) + b = engine.type_descriptor(sqltypes.Integer) assert b.convert_bind_param(12, engine) == 'monkey' assert b.convert_bind_param([1,2,3], engine) == 'monkey' + + def test_type_engine_autoincrement(self): + engine = ProxyEngine() + dogs = Table('dogs', engine, + Column('dog_id', Integer, primary_key=True), + Column('breed', String), + Column('name', String)) + + class Dog(object): + pass + + assign_mapper(Dog, dogs) + + engine.connect(testbase.db_uri) + dogs.create() + + spot = Dog() + spot.breed = 'beagle' + spot.name = 'Spot' + + rover = Dog() + rover.breed = 'spaniel' + rover.name = 'Rover' + + objectstore.commit() + + assert spot.dog_id > 0, "Spot did not get an id" + assert rover.dog_id != spot.dog_id + + def test_type_proxy_schema_gen(self): + from sqlalchemy.databases.postgres import PGSchemaGenerator + + engine = ProxyEngine() + lizards = Table('lizards', engine, + Column('id', Integer, primary_key=True), + Column('name', String)) + + # this doesn't really CONNECT to pg, just establishes pg as the + # actual engine so that we can determine that it gets the right + # answer + engine.connect('postgres://database=test&port=5432&host=127.0.0.1&user=scott&password=tiger') + + sg = PGSchemaGenerator(engine.proxy()) + id_spec = sg.get_column_specification(lizards.c.id) + assert id_spec == 'id SERIAL NOT NULL PRIMARY KEY' + if __name__ == "__main__": testbase.main() |
