
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.
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
import pytest
|
|
import sqlalchemy as sa
|
|
|
|
from sqlalchemy_utils import has_changes
|
|
|
|
|
|
@pytest.fixture
|
|
def Article(Base):
|
|
class Article(Base):
|
|
__tablename__ = 'article_translation'
|
|
id = sa.Column(sa.Integer, primary_key=True)
|
|
title = sa.Column(sa.String(100))
|
|
return Article
|
|
|
|
|
|
class TestHasChangesWithStringAttr(object):
|
|
def test_without_changed_attr(self, Article):
|
|
article = Article()
|
|
assert not has_changes(article, 'title')
|
|
|
|
def test_with_changed_attr(self, Article):
|
|
article = Article(title='Some title')
|
|
assert has_changes(article, 'title')
|
|
|
|
|
|
class TestHasChangesWithMultipleAttrs(object):
|
|
def test_without_changed_attr(self, Article):
|
|
article = Article()
|
|
assert not has_changes(article, ['title'])
|
|
|
|
def test_with_changed_attr(self, Article):
|
|
article = Article(title='Some title')
|
|
assert has_changes(article, ['title', 'id'])
|
|
|
|
|
|
class TestHasChangesWithExclude(object):
|
|
def test_without_changed_attr(self, Article):
|
|
article = Article()
|
|
assert not has_changes(article, exclude=['id'])
|
|
|
|
def test_with_changed_attr(self, Article):
|
|
article = Article(title='Some title')
|
|
assert has_changes(article, exclude=['id'])
|
|
assert not has_changes(article, exclude=['title'])
|