diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-24 12:21:59 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-24 12:21:59 -0500 |
| commit | c848624f9db325213ddf2fde9819946f9eb235cd (patch) | |
| tree | 7400518449a2749f91a486a662b76bcaa7e6c7d6 /test | |
| parent | 4af7bc6cfc8790bf6ef267c059a47952de7c64fa (diff) | |
| download | sqlalchemy-c848624f9db325213ddf2fde9819946f9eb235cd.tar.gz | |
- SqlSoup overhaul
- Added "map_to()" method to SqlSoup, which is a "master"
method which accepts explicit arguments for each aspect of
the selectable and mapping, including a base class per
mapping. [ticket:1975]
- Mapped selectables used with the map(), with_labels(),
join() methods no longer put the given argument into the
internal "cache" dictionary. Particularly since the
join() and select() objects are created in the method
itself this was pretty much a pure memory leaking behavior.
Diffstat (limited to 'test')
| -rw-r--r-- | test/ext/test_sqlsoup.py | 77 | ||||
| -rw-r--r-- | test/perf/insertspeed.py | 5 |
2 files changed, 76 insertions, 6 deletions
diff --git a/test/ext/test_sqlsoup.py b/test/ext/test_sqlsoup.py index 7fe8ab178..0767d6c7a 100644 --- a/test/ext/test_sqlsoup.py +++ b/test/ext/test_sqlsoup.py @@ -1,7 +1,8 @@ from sqlalchemy.ext import sqlsoup -from sqlalchemy.test.testing import TestBase, eq_, assert_raises +from sqlalchemy.test.testing import TestBase, eq_, assert_raises, \ + assert_raises_message from sqlalchemy import create_engine, or_, desc, select, func, exc, \ - Table, util + Table, util, Column, Integer from sqlalchemy.orm import scoped_session, sessionmaker import datetime @@ -30,6 +31,76 @@ class SQLSoupTest(TestBase): for sql in _teardown: engine.execute(sql) + def test_map_to_attr_present(self): + db = sqlsoup.SqlSoup(engine) + + users = db.users + assert_raises_message( + exc.InvalidRequestError, + "Attribute 'users' is already mapped", + db.map_to, 'users', tablename='users' + ) + + def test_map_to_table_not_string(self): + db = sqlsoup.SqlSoup(engine) + + table = Table('users', db._metadata, Column('id', Integer, primary_key=True)) + assert_raises_message( + exc.ArgumentError, + "'tablename' argument must be a string.", + db.map_to, 'users', tablename=table + ) + + def test_map_to_table_or_selectable(self): + db = sqlsoup.SqlSoup(engine) + + table = Table('users', db._metadata, Column('id', Integer, primary_key=True)) + assert_raises_message( + exc.ArgumentError, + "'tablename' and 'selectable' arguments are mutually exclusive", + db.map_to, 'users', tablename='users', selectable=table + ) + + def test_map_to_no_pk_selectable(self): + db = sqlsoup.SqlSoup(engine) + + table = Table('users', db._metadata, Column('id', Integer)) + assert_raises_message( + sqlsoup.PKNotFoundError, + "table 'users' does not have a primary ", + db.map_to, 'users', selectable=table + ) + def test_map_to_invalid_schema(self): + db = sqlsoup.SqlSoup(engine) + + table = Table('users', db._metadata, Column('id', Integer)) + assert_raises_message( + exc.ArgumentError, + "'tablename' argument is required when " + "using 'schema'.", + db.map_to, 'users', selectable=table, schema='hoho' + ) + def test_map_to_nothing(self): + db = sqlsoup.SqlSoup(engine) + + assert_raises_message( + exc.ArgumentError, + "'tablename' or 'selectable' argument is " + "required.", + db.map_to, 'users', + ) + + def test_map_to_string_not_selectable(self): + db = sqlsoup.SqlSoup(engine) + + assert_raises_message( + exc.ArgumentError, + "'selectable' argument must be a " + "table, select, join, or other " + "selectable construct.", + db.map_to, 'users', selectable='users' + ) + def test_bad_names(self): db = sqlsoup.SqlSoup(engine) @@ -278,7 +349,7 @@ class SQLSoupTest(TestBase): email=u'student@example.edu', password=u'student', classname=None, admin=0)]) - def test_no_pk(self): + def test_no_pk_reflected(self): db = sqlsoup.SqlSoup(engine) assert_raises(sqlsoup.PKNotFoundError, getattr, db, 'nopk') diff --git a/test/perf/insertspeed.py b/test/perf/insertspeed.py index 0491e9f95..7d2712837 100644 --- a/test/perf/insertspeed.py +++ b/test/perf/insertspeed.py @@ -1,4 +1,3 @@ -import testenv; testenv.simple_setup() import sys, time from sqlalchemy import * from sqlalchemy.orm import * @@ -87,7 +86,7 @@ def all(): run_profiled(sa_profiled_insert_many, 'SQLAlchemy bulk insert/select, profiled', - 1000) + 50000) print "\nIndividual INSERTS via execute():\n" @@ -101,7 +100,7 @@ def all(): run_profiled(sa_profiled_insert, 'SQLAlchemy individual insert/select, profiled', - 1000) + 50000) finally: metadata.drop_all() |
