File: test_has_changes.py

package info (click to toggle)
python-sqlalchemy-utils 0.41.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,252 kB
  • sloc: python: 13,566; makefile: 141
file content (44 lines) | stat: -rw-r--r-- 1,297 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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:
    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:
    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:
    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'])