File: test_is_loaded.py

package info (click to toggle)
python-sqlalchemy-utils 0.30.12-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 1,056 kB
  • sloc: python: 10,350; makefile: 160
file content (24 lines) | stat: -rw-r--r-- 689 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
import sqlalchemy as sa
from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy_utils import is_loaded


class TestIsLoaded(object):
    def setup_method(self, method):
        Base = declarative_base()

        class Article(Base):
            __tablename__ = 'article_translation'
            id = sa.Column(sa.Integer, primary_key=True)
            title = sa.orm.deferred(sa.Column(sa.String(100)))

        self.Article = Article

    def test_loaded_property(self):
        article = self.Article(id=1)
        assert is_loaded(article, 'id')

    def test_unloaded_property(self):
        article = self.Article(id=4)
        assert not is_loaded(article, 'title')