Here are the examples of the python api sqlalchemy.testing.assertions.eq_ taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
69 Examples
3
Example 1
Project: sqlalchemy Source File: test_loading.py
def test_entity_col_mix_plain_tuple(self):
s, (u1, u2, u3, u4) = self._fixture()
User = self.classes.User
q = s.query(User, User.id)
collection = [(u1, 1), (u2, 2), (u3, 7), (u4, 8)]
it = loading.merge_result(
q,
collection
)
it = list(it)
eq_(
[(x.id, y) for x, y in it],
[(1, 1), (2, 2), (7, 7), (8, 8)]
)
eq_(list(it[0].keys()), ['User', 'id'])
3
Example 2
Project: sqlalchemy Source File: test_options.py
def test_gen_path_string_column(self):
User = self.classes.User
l = Load(User)
eq_(
l._generate_path(inspect(User)._path_registry, "name", "column"),
self._make_path_registry([User, "name"])
)
3
Example 3
Project: sqlalchemy Source File: test_reflection.py
def test_get_view_definition(self):
insp = inspect(testing.db)
eq_(
re.sub(
r'[\n\t ]+', ' ',
insp.get_view_definition("test_mview").strip()),
"SELECT testtable.id, testtable.data FROM testtable;"
)
3
Example 4
Project: sqlalchemy Source File: test_reflection.py
@testing.provide_metadata
def test_inspect_enums(self):
enum_type = postgresql.ENUM(
'cat', 'dog', 'rat', name='pet', metadata=self.metadata)
enum_type.create(testing.db)
inspector = reflection.Inspector.from_engine(testing.db)
eq_(inspector.get_enums(), [
{
'visible': True,
'labels': ['cat', 'dog', 'rat'],
'name': 'pet',
'schema': 'public'
}])
3
Example 5
Project: sqlalchemy Source File: test_reflection.py
def test_table_is_reflected_test_schema(self):
metadata = MetaData(testing.db)
table = Table('testtable', metadata, autoload=True,
schema='test_schema')
eq_(set(table.columns.keys()), set(['question', 'answer',
'anything']),
"Columns of reflected table didn't equal expected columns")
assert isinstance(table.c.anything.type, Integer)
3
Example 6
Project: sqlalchemy Source File: test_dialect.py
@testing.requires.psycopg2_compatibility
def test_pg_dialect_use_native_unicode_from_config(self):
config = {
'sqlalchemy.url': testing.db.url,
'sqlalchemy.use_native_unicode': "false"}
e = engine_from_config(config, _initialize=False)
eq_(e.dialect.use_native_unicode, False)
config = {
'sqlalchemy.url': testing.db.url,
'sqlalchemy.use_native_unicode': "true"}
e = engine_from_config(config, _initialize=False)
eq_(e.dialect.use_native_unicode, True)
3
Example 7
Project: sqlalchemy Source File: test_options.py
def test_str(self):
User = self.classes.User
l = Load(User)
l.strategy = (('deferred', False), ('instrument', True))
eq_(
str(l),
"Load(strategy=(('deferred', False), ('instrument', True)))"
)
3
Example 8
Project: sqlalchemy Source File: test_options.py
def test_gen_path_attr_entity(self):
User = self.classes.User
Address = self.classes.Address
l = Load(User)
eq_(
l._generate_path(inspect(User)._path_registry, User.addresses, "relationship"),
self._make_path_registry([User, "addresses", Address])
)
3
Example 9
Project: sqlalchemy Source File: test_options.py
def test_set_strat_col(self):
User = self.classes.User
l1 = Load(User)
l2 = l1.defer("name")
l3 = list(l2.context.values())[0]
eq_(
l1.context,
{
('loader', self._make_path([User, "name"])): l3
}
)
3
Example 10
Project: sqlalchemy Source File: test_reflection.py
def test_table_is_reflected(self):
metadata = MetaData(testing.db)
table = Table('testtable', metadata, autoload=True)
eq_(set(table.columns.keys()), set(['question', 'answer']),
"Columns of reflected table didn't equal expected columns")
assert isinstance(table.c.answer.type, Integer)
3
Example 11
Project: sqlalchemy Source File: test_reflection.py
@testing.provide_metadata
def test_renamed_pk_reflection(self):
metadata = self.metadata
t = Table('t', metadata, Column('id', Integer, primary_key=True))
metadata.create_all()
testing.db.connect().execution_options(autocommit=True).\
execute('alter table t rename id to t_id')
m2 = MetaData(testing.db)
t2 = Table('t', m2, autoload=True)
eq_([c.name for c in t2.primary_key], ['t_id'])
3
Example 12
Project: sqlalchemy Source File: test_reflection.py
def test_crosschema_domain_is_reflected(self):
metadata = MetaData(testing.db)
table = Table('crosschema', metadata, autoload=True)
eq_(str(table.columns.answer.server_default.arg), '0',
"Reflected default value didn't equal expected value")
assert table.columns.answer.nullable, \
'Expected reflected column to be nullable.'
3
Example 13
Project: sqlalchemy Source File: test_options.py
def test_gen_path_string_entity(self):
User = self.classes.User
Address = self.classes.Address
l = Load(User)
eq_(
l._generate_path(inspect(User)._path_registry, "addresses", "relationship"),
self._make_path_registry([User, "addresses", Address])
)
3
Example 14
def test_single_entity(self):
s, (u1, u2, u3, u4) = self._fixture()
User = self.classes.User
q = s.query(User)
collection = [u1, u2, u3, u4]
it = loading.merge_result(
q,
collection
)
eq_(
[x.id for x in it],
[1, 2, 7, 8]
)
3
Example 15
def test_single_column(self):
User = self.classes.User
s = Session()
q = s.query(User.id)
collection = [(1, ), (2, ), (7, ), (8, )]
it = loading.merge_result(
q,
collection
)
eq_(
list(it),
[(1, ), (2, ), (7, ), (8, )]
)
3
Example 16
Project: sqlalchemy Source File: test_loading.py
def test_none_entity(self):
s, (u1, u2, u3, u4) = self._fixture()
User = self.classes.User
ua = aliased(User)
q = s.query(User, ua)
kt = lambda *x: KeyedTuple(x, ['User', 'useralias'])
collection = [kt(u1, u2), kt(u1, None), kt(u2, u3)]
it = loading.merge_result(
q,
collection
)
eq_(
[
(x and x.id or None, y and y.id or None)
for x, y in it
],
[(u1.id, u2.id), (u1.id, None), (u2.id, u3.id)]
)
3
Example 17
Project: sqlalchemy Source File: test_on_conflict.py
def test_on_conflict_do_update_one(self):
users = self.tables.users
with testing.db.connect() as conn:
conn.execute(users.insert(), dict(id=1, name='name1'))
i = insert(users)
i = i.on_conflict_do_update(
index_elements=[users.c.id],
set_=dict(name=i.excluded.name))
result = conn.execute(i, dict(id=1, name='name1'))
eq_(result.inserted_primary_key, [1])
eq_(result.returned_defaults, None)
eq_(
conn.execute(users.select().where(users.c.id == 1)).fetchall(),
[(1, 'name1')]
)
3
Example 18
Project: sqlalchemy Source File: test_options.py
def test_gen_path_attr_column(self):
User = self.classes.User
l = Load(User)
eq_(
l._generate_path(inspect(User)._path_registry, User.name, "column"),
self._make_path_registry([User, "name"])
)
3
Example 19
Project: sqlalchemy Source File: test_reflection.py
def test_mview_select(self):
metadata = MetaData(testing.db)
table = Table('test_mview', metadata, autoload=True)
eq_(
table.select().execute().fetchall(),
[(89, 'd1',)]
)
3
Example 20
Project: sqlalchemy Source File: test_options.py
def test_set_strat_ent(self):
User = self.classes.User
l1 = Load(User)
l2 = l1.joinedload("addresses")
eq_(
l1.context,
{
('loader', self._make_path([User, "addresses"])): l2
}
)
3
Example 21
Project: sqlalchemy Source File: test_reflection.py
def test_domain_is_reflected(self):
metadata = MetaData(testing.db)
table = Table('testtable', metadata, autoload=True)
eq_(str(table.columns.answer.server_default.arg), '42',
"Reflected default value didn't equal expected value")
assert not table.columns.answer.nullable, \
'Expected reflected column to not be nullable.'
3
Example 22
Project: sqlalchemy Source File: test_reflection.py
def test_enum_domain_is_reflected(self):
metadata = MetaData(testing.db)
table = Table('enum_test', metadata, autoload=True)
eq_(
table.c.data.type.enums,
['test']
)
3
Example 23
Project: sqlalchemy Source File: test_options.py
def test_gen_path_attr_entity_invalid_noraiseerr(self):
User = self.classes.User
Order = self.classes.Order
l = Load(User)
eq_(
l._generate_path(
inspect(User)._path_registry, Order.items, "relationship", False
),
None
)
3
Example 24
Project: sqlalchemy Source File: test_reflection.py
def test_schema_domain_is_reflected(self):
metadata = MetaData(testing.db)
table = Table('testtable', metadata, autoload=True,
schema='test_schema')
eq_(str(table.columns.answer.server_default.arg), '0',
"Reflected default value didn't equal expected value")
assert table.columns.answer.nullable, \
'Expected reflected column to be nullable.'
3
Example 25
def assert_compiled(element, assert_string, dialect=None):
dialect = _get_dialect(dialect)
eq_(
text_type(element.compile(dialect=dialect)).
replace("\n", "").replace("\t", ""),
assert_string.replace("\n", "").replace("\t", "")
)
3
Example 26
Project: sqlalchemy Source File: test_reflection.py
@testing.provide_metadata
def test_altered_type_autoincrement_pk_reflection(self):
metadata = self.metadata
t = Table(
't', metadata,
Column('id', Integer, primary_key=True),
Column('x', Integer)
)
metadata.create_all()
testing.db.connect().execution_options(autocommit=True).\
execute('alter table t alter column id type varchar(50)')
m2 = MetaData(testing.db)
t2 = Table('t', m2, autoload=True)
eq_(t2.c.id.autoincrement, False)
eq_(t2.c.x.autoincrement, False)
3
Example 27
Project: sqlalchemy Source File: test_reflection.py
@testing.fails_if("postgresql < 8.4",
"Better int2vector functions not available")
@testing.provide_metadata
def test_reflected_primary_key_order(self):
meta1 = self.metadata
subject = Table('subject', meta1,
Column('p1', Integer, primary_key=True),
Column('p2', Integer, primary_key=True),
PrimaryKeyConstraint('p2', 'p1')
)
meta1.create_all()
meta2 = MetaData(testing.db)
subject = Table('subject', meta2, autoload=True)
eq_(subject.primary_key.columns.keys(), ['p2', 'p1'])
3
Example 28
Project: sqlalchemy Source File: test_loading.py
def test_entity_col_mix_keyed_tuple(self):
s, (u1, u2, u3, u4) = self._fixture()
User = self.classes.User
q = s.query(User, User.id)
kt = lambda *x: KeyedTuple(x, ['User', 'id'])
collection = [kt(u1, 1), kt(u2, 2), kt(u3, 7), kt(u4, 8)]
it = loading.merge_result(
q,
collection
)
it = list(it)
eq_(
[(x.id, y) for x, y in it],
[(1, 1), (2, 2), (7, 7), (8, 8)]
)
eq_(list(it[0].keys()), ['User', 'id'])
3
Example 29
Project: sqlalchemy Source File: test_reflection.py
@testing.provide_metadata
def test_inspect_enums_schema(self):
conn = testing.db.connect()
enum_type = postgresql.ENUM(
'sad', 'ok', 'happy', name='mood',
schema='test_schema',
metadata=self.metadata)
enum_type.create(conn)
inspector = reflection.Inspector.from_engine(conn.engine)
eq_(
inspector.get_enums('test_schema'), [{
'visible': False,
'name': 'mood',
'schema': 'test_schema',
'labels': ['sad', 'ok', 'happy']
}])
3
Example 30
Project: sqlalchemy Source File: test_options.py
def _assert_path_result(self, opt, q, paths):
q._attributes = q._attributes.copy()
attr = {}
for val in opt._to_bind:
val._bind_loader(q, attr, False)
assert_paths = [k[1] for k in attr]
eq_(
set([p for p in assert_paths]),
set([self._make_path(p) for p in paths])
)
3
Example 31
Project: sqlalchemy Source File: test_reflection.py
def _assert_reflected(self, dialect):
for sch, args in [
('my_custom_type', (None, None)),
('my_custom_type()', (None, None)),
('my_custom_type(ARG1)', ('ARG1', None)),
('my_custom_type(ARG1, ARG2)', ('ARG1', 'ARG2')),
]:
column_info = dialect._get_column_info(
'colname', sch, None, False,
{}, {}, 'public')
assert isinstance(column_info['type'], self.CustomType)
eq_(column_info['type'].arg1, args[0])
eq_(column_info['type'].arg2, args[1])
3
Example 32
Project: sqlalchemy Source File: test_dialect.py
@testing.fails_on('+zxjdbc',
"Can't infer the SQL type to use for an instance "
"of org.python.core.PyObjectDerived.")
def test_extract(self):
fivedaysago = datetime.datetime.now() \
- datetime.timedelta(days=5)
for field, exp in ('year', fivedaysago.year), \
('month', fivedaysago.month), ('day', fivedaysago.day):
r = testing.db.execute(
select([
extract(field, func.now() + datetime.timedelta(days=-5))])
).scalar()
eq_(r, exp)
3
Example 33
Project: sqlalchemy Source File: test_on_conflict.py
def test_on_conflict_do_update_three(self):
users = self.tables.users
with testing.db.connect() as conn:
conn.execute(users.insert(), dict(id=1, name='name1'))
i = insert(users)
i = i.on_conflict_do_update(
index_elements=users.primary_key.columns,
set_=dict(name=i.excluded.name)
)
result = conn.execute(i, dict(id=1, name='name3'))
eq_(result.inserted_primary_key, [1])
eq_(result.returned_defaults, None)
eq_(
conn.execute(users.select().where(users.c.id == 1)).fetchall(),
[(1, 'name3')]
)
3
Example 34
Project: sqlalchemy Source File: test_dialect.py
@testing.requires.psycopg2_or_pg8000_compatibility
@engines.close_open_connections
def test_client_encoding(self):
c = testing.db.connect()
current_encoding = c.execute("show client_encoding").fetchone()[0]
c.close()
# attempt to use an encoding that's not
# already set
if current_encoding == 'UTF8':
test_encoding = 'LATIN1'
else:
test_encoding = 'UTF8'
e = engines.testing_engine(options={'client_encoding': test_encoding})
c = e.connect()
new_encoding = c.execute("show client_encoding").fetchone()[0]
eq_(new_encoding, test_encoding)
3
Example 35
Project: sqlalchemy Source File: test_reflection.py
@testing.provide_metadata
def test_reflect_default_over_128_chars(self):
Table('t', self.metadata,
Column('x', String(200), server_default="abcd" * 40)
).create(testing.db)
m = MetaData()
t = Table('t', m, autoload=True, autoload_with=testing.db)
eq_(
t.c.x.server_default.arg.text, "'%s'::character varying" % (
"abcd" * 40)
)
0
Example 36
Project: sqlalchemy Source File: test_on_conflict.py
def _exotic_targets_fixture(self, conn):
users = self.tables.users_xtra
conn.execute(
insert(users),
dict(
id=1, name='name1',
login_email='[email protected]', lets_index_this='not'
)
)
conn.execute(
users.insert(),
dict(
id=2, name='name2',
login_email='[email protected]', lets_index_this='not'
)
)
eq_(
conn.execute(users.select().where(users.c.id == 1)).fetchall(),
[(1, 'name1', '[email protected]', 'not')]
)
0
Example 37
Project: sqlalchemy Source File: test_on_conflict.py
def test_on_conflict_do_nothing(self):
users = self.tables.users
with testing.db.connect() as conn:
result = conn.execute(
insert(users).on_conflict_do_nothing(),
dict(id=1, name='name1')
)
eq_(result.inserted_primary_key, [1])
eq_(result.returned_defaults, None)
result = conn.execute(
insert(users).on_conflict_do_nothing(),
dict(id=1, name='name2')
)
eq_(result.inserted_primary_key, [1])
eq_(result.returned_defaults, None)
eq_(
conn.execute(users.select().where(users.c.id == 1)).fetchall(),
[(1, 'name1')]
)
0
Example 38
Project: sqlalchemy Source File: test_on_conflict.py
def test_on_conflict_do_update_exotic_targets_two(self):
users = self.tables.users_xtra
with testing.db.connect() as conn:
self._exotic_targets_fixture(conn)
# try primary key constraint: cause an upsert on unique id column
i = insert(users)
i = i.on_conflict_do_update(
index_elements=users.primary_key.columns,
set_=dict(
name=i.excluded.name,
login_email=i.excluded.login_email)
)
result = conn.execute(i, dict(
id=1, name='name2', login_email='[email protected]',
lets_index_this='not')
)
eq_(result.inserted_primary_key, [1])
eq_(result.returned_defaults, None)
eq_(
conn.execute(users.select().where(users.c.id == 1)).fetchall(),
[(1, 'name2', '[email protected]', 'not')]
)
0
Example 39
Project: sqlalchemy Source File: test_on_conflict.py
def test_on_conflict_do_update_exotic_targets_three(self):
users = self.tables.users_xtra
with testing.db.connect() as conn:
self._exotic_targets_fixture(conn)
# try unique constraint: cause an upsert on target
# login_email, not id
i = insert(users)
i = i.on_conflict_do_update(
constraint=self.unique_constraint,
set_=dict(id=i.excluded.id, name=i.excluded.name,
login_email=i.excluded.login_email)
)
# note: lets_index_this value totally ignored in SET clause.
result = conn.execute(i, dict(
id=42, name='nameunique',
login_email='[email protected]', lets_index_this='unique')
)
eq_(result.inserted_primary_key, [42])
eq_(result.returned_defaults, None)
eq_(
conn.execute(
users.select().
where(users.c.login_email == '[email protected]')
).fetchall(),
[(42, 'nameunique', '[email protected]', 'not')]
)
0
Example 40
Project: sqlalchemy Source File: test_on_conflict.py
@testing.provide_metadata
def test_on_conflict_do_nothing_target(self):
users = self.tables.users
with testing.db.connect() as conn:
result = conn.execute(
insert(users)
.on_conflict_do_nothing(
index_elements=users.primary_key.columns),
dict(id=1, name='name1')
)
eq_(result.inserted_primary_key, [1])
eq_(result.returned_defaults, None)
result = conn.execute(
insert(users)
.on_conflict_do_nothing(
index_elements=users.primary_key.columns),
dict(id=1, name='name2')
)
eq_(result.inserted_primary_key, [1])
eq_(result.returned_defaults, None)
eq_(
conn.execute(users.select().where(users.c.id == 1)).fetchall(),
[(1, 'name1')]
)
0
Example 41
Project: sqlalchemy Source File: test_on_conflict.py
def test_on_conflict_do_update_exotic_targets_four(self):
users = self.tables.users_xtra
with testing.db.connect() as conn:
self._exotic_targets_fixture(conn)
# try unique constraint by name: cause an
# upsert on target login_email, not id
i = insert(users)
i = i.on_conflict_do_update(
constraint=self.unique_constraint.name,
set_=dict(
id=i.excluded.id, name=i.excluded.name,
login_email=i.excluded.login_email)
)
# note: lets_index_this value totally ignored in SET clause.
result = conn.execute(i, dict(
id=43, name='nameunique2',
login_email='[email protected]', lets_index_this='unique')
)
eq_(result.inserted_primary_key, [43])
eq_(result.returned_defaults, None)
eq_(
conn.execute(
users.select().
where(users.c.login_email == '[email protected]')
).fetchall(),
[(43, 'nameunique2', '[email protected]', 'not')]
)
0
Example 42
Project: sqlalchemy Source File: test_dialect.py
@testing.fails_on('+zxjdbc',
'The JDBC driver handles the version parsing')
def test_version_parsing(self):
def mock_conn(res):
return Mock(
execute=Mock(return_value=Mock(scalar=Mock(return_value=res))))
for string, version in [
(
'PostgreSQL 8.3.8 on i686-redhat-linux-gnu, compiled by '
'GCC gcc (GCC) 4.1.2 20070925 (Red Hat 4.1.2-33)',
(8, 3, 8)),
(
'PostgreSQL 8.5devel on x86_64-unknown-linux-gnu, '
'compiled by GCC gcc (GCC) 4.4.2, 64-bit', (8, 5)),
(
'EnterpriseDB 9.1.2.2 on x86_64-unknown-linux-gnu, '
'compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-50), '
'64-bit', (9, 1, 2)),
(
'[PostgreSQL 9.2.4 ] VMware vFabric Postgres 9.2.4.0 '
'release build 1080137', (9, 2, 4))]:
eq_(testing.db.dialect._get_server_version_info(mock_conn(string)),
version)
0
Example 43
Project: sqlalchemy Source File: test_on_conflict.py
def test_on_conflict_do_update_exotic_targets_four_no_pk(self):
users = self.tables.users_xtra
with testing.db.connect() as conn:
self._exotic_targets_fixture(conn)
# try unique constraint by name: cause an
# upsert on target login_email, not id
i = insert(users)
i = i.on_conflict_do_update(
index_elements=[users.c.login_email],
set_=dict(
id=i.excluded.id, name=i.excluded.name,
login_email=i.excluded.login_email)
)
result = conn.execute(i, dict(
name='name3',
login_email='[email protected]')
)
eq_(result.inserted_primary_key, [1])
eq_(result.returned_defaults, (1, ))
eq_(
conn.execute(users.select().order_by(users.c.id)).fetchall(),
[
(1, 'name3', '[email protected]', 'not'),
(2, 'name2', '[email protected]', 'not')
]
)
0
Example 44
Project: sqlalchemy Source File: test_on_conflict.py
def test_on_conflict_do_update_exotic_targets_six(self):
users = self.tables.users_xtra
with testing.db.connect() as conn:
conn.execute(
insert(users),
dict(
id=1, name='name1',
login_email='[email protected]',
lets_index_this='unique_name'
)
)
i = insert(users)
i = i.on_conflict_do_update(
index_elements=self.unique_partial_index.columns,
index_where=self.unique_partial_index.dialect_options
['postgresql']['where'],
set_=dict(
name=i.excluded.name,
login_email=i.excluded.login_email),
)
conn.execute(
i,
[
dict(name='name1', login_email='[email protected]',
lets_index_this='unique_name'),
]
)
eq_(
conn.execute(users.select()).fetchall(),
[
(1, 'name1', '[email protected]', 'unique_name'),
]
)
0
Example 45
Project: sqlalchemy Source File: test_on_conflict.py
def test_on_conflict_do_update_two(self):
users = self.tables.users
with testing.db.connect() as conn:
conn.execute(users.insert(), dict(id=1, name='name1'))
i = insert(users)
i = i.on_conflict_do_update(
index_elements=[users.c.id],
set_=dict(id=i.excluded.id, name=i.excluded.name)
)
result = conn.execute(i, dict(id=1, name='name2'))
eq_(result.inserted_primary_key, [1])
eq_(result.returned_defaults, None)
eq_(
conn.execute(users.select().where(users.c.id == 1)).fetchall(),
[(1, 'name2')]
)
0
Example 46
Project: sqlalchemy Source File: test_dialect.py
def test_schema_roundtrips(self):
meta = MetaData(testing.db)
users = Table(
'users', meta, Column(
'id', Integer, primary_key=True), Column(
'name', String(50)), schema='test_schema')
users.create()
try:
users.insert().execute(id=1, name='name1')
users.insert().execute(id=2, name='name2')
users.insert().execute(id=3, name='name3')
users.insert().execute(id=4, name='name4')
eq_(users.select().where(users.c.name == 'name2')
.execute().fetchall(), [(2, 'name2')])
eq_(users.select(use_labels=True).where(
users.c.name == 'name2').execute().fetchall(), [(2, 'name2')])
users.delete().where(users.c.id == 3).execute()
eq_(users.select().where(users.c.name == 'name3')
.execute().fetchall(), [])
users.update().where(users.c.name == 'name4'
).execute(name='newname')
eq_(users.select(use_labels=True).where(
users.c.id == 4).execute().fetchall(), [(4, 'newname')])
finally:
users.drop()
0
Example 47
Project: sqlalchemy Source File: test_on_conflict.py
def test_on_conflict_do_update_four(self):
users = self.tables.users
with testing.db.connect() as conn:
conn.execute(users.insert(), dict(id=1, name='name1'))
i = insert(users)
i = i.on_conflict_do_update(
index_elements=users.primary_key.columns,
set_=dict(id=i.excluded.id, name=i.excluded.name)
).values(id=1, name='name4')
result = conn.execute(i)
eq_(result.inserted_primary_key, [1])
eq_(result.returned_defaults, None)
eq_(
conn.execute(users.select().where(users.c.id == 1)).fetchall(),
[(1, 'name4')]
)
0
Example 48
Project: sqlalchemy Source File: test_on_conflict.py
def test_on_conflict_do_update_five(self):
users = self.tables.users
with testing.db.connect() as conn:
conn.execute(users.insert(), dict(id=1, name='name1'))
i = insert(users)
i = i.on_conflict_do_update(
index_elements=users.primary_key.columns,
set_=dict(id=10, name="I'm a name")
).values(id=1, name='name4')
result = conn.execute(i)
eq_(result.inserted_primary_key, [1])
eq_(result.returned_defaults, None)
eq_(
conn.execute(
users.select().where(users.c.id == 10)).fetchall(),
[(10, "I'm a name")]
)
0
Example 49
Project: sqlalchemy Source File: test_dialect.py
@testing.only_if(
"postgresql >= 8.2", "requires standard_conforming_strings")
def test_serial_integer(self):
class BITD(TypeDecorator):
impl = Integer
def load_dialect_impl(self, dialect):
if dialect.name == 'postgresql':
return BigInteger()
else:
return Integer()
for version, type_, expected in [
(None, Integer, 'SERIAL'),
(None, BigInteger, 'BIGSERIAL'),
((9, 1), SmallInteger, 'SMALLINT'),
((9, 2), SmallInteger, 'SMALLSERIAL'),
(None, postgresql.INTEGER, 'SERIAL'),
(None, postgresql.BIGINT, 'BIGSERIAL'),
(
None, Integer().with_variant(BigInteger(), 'postgresql'),
'BIGSERIAL'),
(
None, Integer().with_variant(postgresql.BIGINT, 'postgresql'),
'BIGSERIAL'),
(
(9, 2), Integer().with_variant(SmallInteger, 'postgresql'),
'SMALLSERIAL'),
(None, BITD(), 'BIGSERIAL')
]:
m = MetaData()
t = Table('t', m, Column('c', type_, primary_key=True))
if version:
dialect = postgresql.dialect()
dialect._get_server_version_info = Mock(return_value=version)
dialect.initialize(testing.db.connect())
else:
dialect = testing.db.dialect
ddl_compiler = dialect.ddl_compiler(dialect, schema.CreateTable(t))
eq_(
ddl_compiler.get_column_specification(t.c.c),
"c %s NOT NULL" % expected
)
0
Example 50
Project: sqlalchemy Source File: test_on_conflict.py
def test_on_conflict_do_update_multivalues(self):
users = self.tables.users
with testing.db.connect() as conn:
conn.execute(users.insert(), dict(id=1, name='name1'))
conn.execute(users.insert(), dict(id=2, name='name2'))
i = insert(users)
i = i.on_conflict_do_update(
index_elements=users.primary_key.columns,
set_=dict(name="updated"),
where=(i.excluded.name != 'name12')
).values([
dict(id=1, name='name11'),
dict(id=2, name='name12'),
dict(id=3, name='name13'),
dict(id=4, name='name14'),
])
result = conn.execute(i)
eq_(result.inserted_primary_key, [None])
eq_(result.returned_defaults, None)
eq_(
conn.execute(
users.select().order_by(users.c.id)).fetchall(),
[
(1, "updated"),
(2, "name2"),
(3, "name13"),
(4, "name14")
]
)