Skip to content

Commit

Permalink
add test for excluded relationship
Browse files Browse the repository at this point in the history
  • Loading branch information
fuhrysteve committed Nov 8, 2017
1 parent 4e222f2 commit d540483
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/test_column_inclusion_and_exclusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,52 @@ class TextItem(self.Model):
content = sa.Column('_content', sa.UnicodeText)

self.TextItem = TextItem


class TestColumnExclusionWithRelationship(TestCase):
def create_models(self):

class Word(self.Model):
__tablename__ = 'word'
id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
word = sa.Column(sa.Unicode(255))

class TextItemWord(self.Model):
__tablename__ = 'text_item_word'
id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
text_item_id = sa.Column(sa.Integer, sa.ForeignKey('text_item.id'), nullable=False)
word_id = sa.Column(sa.Integer, sa.ForeignKey('word.id'), nullable=False)

class TextItem(self.Model):
__tablename__ = 'text_item'
__versioned__ = {
'exclude': ['content']
}

id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
name = sa.Column(sa.Unicode(255))
content = sa.orm.relationship(Word, secondary='text_item_word')

self.TextItem = TextItem
self.Word = Word

def test_excluded_columns_not_included_in_version_class(self):
cls = version_class(self.TextItem)
manager = cls._sa_class_manager
assert 'content' not in manager.keys()

def test_versioning_with_column_exclusion(self):
item = self.TextItem(name=u'Some textitem',
content=[self.Word(word=u'bird')])
self.session.add(item)
self.session.commit()

assert item.versions[0].name == u'Some textitem'

def test_does_not_create_record_if_only_excluded_column_updated(self):
item = self.TextItem(name=u'Some textitem')
self.session.add(item)
self.session.commit()
item.content.append(self.Word(word=u'Some content'))
self.session.commit()
assert item.versions.count() == 1

0 comments on commit d540483

Please sign in to comment.