
Also: Allow override of database name and user in tests (important for me as I would have to mess with my PSQL and MySQL database users otherwise) Use dict.items instead of six.iteritems as it sporadically caused RuntimeError: dictionary changed size during iteration in Python 2.6 tests. Fix typo DNS to DSN Adds Python 3.5 to tox.ini Added an .editorconfig Import babel.dates in sqlalchemy_utils.i18n as an exception would be raised when using the latest versions of babel.
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
import pytest
|
|
import sqlalchemy as sa
|
|
|
|
from sqlalchemy_utils import get_primary_keys
|
|
|
|
try:
|
|
from collections import OrderedDict
|
|
except ImportError:
|
|
from ordereddict import OrderedDict
|
|
|
|
|
|
@pytest.fixture
|
|
def Building(Base):
|
|
class Building(Base):
|
|
__tablename__ = 'building'
|
|
id = sa.Column('_id', sa.Integer, primary_key=True)
|
|
name = sa.Column('_name', sa.Unicode(255))
|
|
return Building
|
|
|
|
|
|
class TestGetPrimaryKeys(object):
|
|
|
|
def test_table(self, Building):
|
|
assert get_primary_keys(Building.__table__) == OrderedDict({
|
|
'_id': Building.__table__.c._id
|
|
})
|
|
|
|
def test_declarative_class(self, Building):
|
|
assert get_primary_keys(Building) == OrderedDict({
|
|
'id': Building.__table__.c._id
|
|
})
|
|
|
|
def test_declarative_object(self, Building):
|
|
assert get_primary_keys(Building()) == OrderedDict({
|
|
'id': Building.__table__.c._id
|
|
})
|
|
|
|
def test_class_alias(self, Building):
|
|
alias = sa.orm.aliased(Building)
|
|
assert get_primary_keys(alias) == OrderedDict({
|
|
'id': Building.__table__.c._id
|
|
})
|
|
|
|
def test_table_alias(self, Building):
|
|
alias = sa.orm.aliased(Building.__table__)
|
|
assert get_primary_keys(alias) == OrderedDict({
|
|
'_id': alias.c._id
|
|
})
|