Files
deb-python-sqlalchemy-utils/tests/functions/test_identity.py
Jacob Magnusson 815f07d6c1 Use pytest fixtures to reduce complexity and repetition
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.
2016-01-19 10:52:30 +01:00

47 lines
1.2 KiB
Python

import pytest
import sqlalchemy as sa
from sqlalchemy_utils.functions import identity
class IdentityTestCase(object):
@pytest.fixture
def init_models(self, Building):
pass
def test_for_transient_class_without_id(self, Building):
assert identity(Building()) == (None, )
def test_for_transient_class_with_id(self, session, Building):
building = Building(name=u'Some building')
session.add(building)
session.flush()
assert identity(building) == (building.id, )
def test_identity_for_class(self, Building):
assert identity(Building) == (Building.id, )
class TestIdentity(IdentityTestCase):
@pytest.fixture
def Building(self, Base):
class Building(Base):
__tablename__ = 'building'
id = sa.Column(sa.Integer, primary_key=True)
name = sa.Column(sa.Unicode(255))
return Building
class TestIdentityWithColumnAlias(IdentityTestCase):
@pytest.fixture
def Building(self, Base):
class Building(Base):
__tablename__ = 'building'
id = sa.Column('_id', sa.Integer, primary_key=True)
name = sa.Column(sa.Unicode(255))
return Building