sqlalchemy_continuum.version_class

Here are the examples of the python api sqlalchemy_continuum.version_class taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

53 Examples 7

Example 1

View license
    def test_assigns_foreign_keys_for_versions(self):
        article = self.Article()
        article.name = u'Some article'
        article.content = u'Some content'
        article.tags.append(self.Tag(name=u'some tag'))
        self.session.add(article)
        self.session.commit()
        cls = version_class(self.Tag)
        version = self.session.query(cls).first()
        assert version.name == u'some tag'
        assert version.id == 1
        assert version.article_id == 1

Example 2

View license
    def test_assigns_foreign_keys_for_versions(self):
        article = self.Article()
        article.name = u'Some article'
        article.content = u'Some content'
        article.tags.append(self.Tag(name=u'some tag'))
        self.session.add(article)
        self.session.commit()
        cls = version_class(self.Tag)
        version = self.session.query(cls).first()
        assert version.name == u'some tag'
        assert version.id == 1
        assert version.article_id == 1

Example 3

View license
    def test_each_column_generates_additional_mod_column(self):
        UserVersion = version_class(self.User)
        assert 'name_mod' in UserVersion.__table__.c
        column = UserVersion.__table__.c['name_mod']
        assert not column.nullable
        assert isinstance(column.type, sa.Boolean)

Example 4

View license
    def test_mod_properties_with_delete(self):
        user = self.User(name=u'John')
        self.session.add(user)
        self.session.commit()
        self.session.delete(user)
        self.session.commit()
        UserVersion = version_class(self.User)
        version = (
            self.session
            .query(UserVersion)
            .order_by(sa.desc(UserVersion.transaction_id))
        ).first()
        assert version.age_mod
        assert version.name_mod

Example 5

View license
    def test_each_column_generates_additional_mod_column(self):
        ArticleVersion = version_class(self.Article)
        assert 'name_mod' in ArticleVersion.__table__.c
        column = ArticleVersion.__table__.c['name_mod']
        assert not column.nullable
        assert isinstance(column.type, sa.Boolean)

Example 6

View license
    def test_change_single_entity(self):
        self.article = self.Article()
        self.article.name = u'Some article'
        self.article.content = u'Some content'
        self.session.add(self.article)
        self.session.commit()
        tx = self.article.versions[0].transaction

        assert tx.changed_entities == {
            version_class(self.article.__class__):
            [self.article.versions[0]]
        }

Example 7

View license
    def test_each_column_generates_additional_mod_column(self):
        UserVersion = version_class(self.User)
        assert 'name_mod' in UserVersion.__table__.c
        column = UserVersion.__table__.c['name_mod']
        assert not column.nullable
        assert isinstance(column.type, sa.Boolean)

Example 8

View license
    def test_mod_properties_with_delete(self):
        user = self.User(name=u'John')
        self.session.add(user)
        self.session.commit()
        self.session.delete(user)
        self.session.commit()
        UserVersion = version_class(self.User)
        version = (
            self.session
            .query(UserVersion)
            .order_by(sa.desc(UserVersion.transaction_id))
        ).first()
        assert version.age_mod
        assert version.name_mod

Example 9

View license
    def test_each_column_generates_additional_mod_column(self):
        ArticleVersion = version_class(self.Article)
        assert 'name_mod' in ArticleVersion.__table__.c
        column = ArticleVersion.__table__.c['name_mod']
        assert not column.nullable
        assert isinstance(column.type, sa.Boolean)

Example 10

View license
    def test_change_single_entity(self):
        self.article = self.Article()
        self.article.name = u'Some article'
        self.article.content = u'Some content'
        self.session.add(self.article)
        self.session.commit()
        tx = self.article.versions[0].transaction

        assert tx.changed_entities == {
            version_class(self.article.__class__):
            [self.article.versions[0]]
        }

Example 11

View license
    def test_each_class_has_distinct_translation_class(self):
        class_ = version_class(self.TextItem)
        assert class_.__name__ == 'TextItemVersion'
        class_ = version_class(self.Article)
        assert class_.__name__ == 'ArticleVersion'
        assert issubclass(class_, self.ArticleVersionBase)

Example 12

View license
    def test_each_class_has_distinct_translation_class(self):
        class_ = version_class(self.TextItem)
        assert class_.__name__ == 'TextItemVersion'
        class_ = version_class(self.Article)
        assert class_.__name__ == 'ArticleVersion'
        assert issubclass(class_, self.ArticleVersionBase)

Example 13

Project: open-event-orga-server
Source File: __init__.py
View license
@app.context_processor
def versioning_manager():
    def count_versions(model_object):
        from sqlalchemy_continuum.utils import count_versions
        return count_versions(model_object)

    def changeset(model_object):
        from sqlalchemy_continuum import changeset
        return changeset(model_object)

    def transaction_class(version_object):
        from sqlalchemy_continuum import transaction_class
        transaction = transaction_class(version_object)
        return transaction.query.get(version_object.transaction_id)

    def version_class(model_object):
        from sqlalchemy_continuum import version_class
        return version_class(model_object)

    def get_user_name(transaction_object):
        if transaction_object and transaction_object.user_id:
            user = DataGetter.get_user(transaction_object.user_id)
            return user.email
        return '[email protected]'

    def side_by_side_diff(changeset_entry):
        from app.helpers.versioning import side_by_side_diff
        for side_by_side_diff_entry in side_by_side_diff(changeset_entry[0],
                                                         changeset_entry[1]):
            yield side_by_side_diff_entry

    return dict(count_versions=count_versions,
                changeset=changeset,
                transaction_class=transaction_class,
                version_class=version_class,
                side_by_side_diff=side_by_side_diff,
                get_user_name=get_user_name)

Example 14

View license
    def test_each_class_has_distinct_translation_class(self):
        class_ = version_class(self.TextItem)
        assert class_.__name__ == 'TextItemVersion'
        class_ = version_class(self.Article)
        assert class_.__name__ == 'ArticleVersion'

Example 15

View license
    def setup_method(self, method):
        TestCase.setup_method(self, method)
        self.TextItemVersion = version_class(self.TextItem)
        self.ArticleVersion = version_class(self.Article)
        self.BlogPostVersion = version_class(self.BlogPost)

Example 16

View license
    def setup_method(self, method):
        TestCase.setup_method(self, method)
        self.TextItemVersion = version_class(self.TextItem)
        self.ArticleVersion = version_class(self.Article)
        self.BlogPostVersion = version_class(self.BlogPost)

Example 17

View license
    def test_each_class_has_distinct_translation_class(self):
        class_ = version_class(self.TextItem)
        assert class_.__name__ == 'TextItemVersion'
        class_ = version_class(self.Article)
        assert class_.__name__ == 'ArticleVersion'

Example 18

View license
    def setup_method(self, method):
        TestCase.setup_method(self, method)
        self.TextItemVersion = version_class(self.TextItem)
        self.ArticleVersion = version_class(self.Article)
        self.BlogPostVersion = version_class(self.BlogPost)

Example 19

View license
    def setup_method(self, method):
        TestCase.setup_method(self, method)
        self.TextItemVersion = version_class(self.TextItem)
        self.ArticleVersion = version_class(self.Article)
        self.BlogPostVersion = version_class(self.BlogPost)

Example 20

View license
    def setup_method(self, method):
        TestCase.setup_method(self, method)
        self.TextItemVersion = version_class(self.TextItem)
        self.ArticleVersion = version_class(self.Article)
        self.BlogPostVersion = version_class(self.BlogPost)

Example 21

View license
    def setup_method(self, method):
        TestCase.setup_method(self, method)
        self.TextItemVersion = version_class(self.TextItem)
        self.ArticleVersion = version_class(self.Article)
        self.BlogPostVersion = version_class(self.BlogPost)

Example 22

View license
    def test_primary_keys_not_included(self):
        UserVersion = version_class(self.User)
        assert 'id_mod' not in UserVersion.__table__.c

Example 23

View license
    def test_primary_keys_not_included(self):
        UserVersion = version_class(self.User)
        assert 'id_mod' not in UserVersion.__table__.c

Example 24

View license
    def test_previous_for_deleted_parent(self):
        item = self.TextItem()
        item.name = u'Some item'
        item.content = u'Some content'
        self.session.add(item)
        self.session.commit()
        self.session.delete(item)
        self.session.commit()
        TextItemVersion = version_class(self.TextItem)

        versions = (
            self.session.query(TextItemVersion)
            .order_by(
                getattr(
                    TextItemVersion,
                    self.options['transaction_column_name']
                )
            )
        ).all()
        assert versions[1].previous.name == u'Some item'

Example 25

View license
    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()

Example 26

View license
    def test_composite_primary_key_on_version_tables(self):
        TeamMemberVersion = version_class(self.TeamMember)
        assert len(TeamMemberVersion.__table__.primary_key.columns) == 3

Example 27

View license
    def test_does_not_make_composite_primary_keys_not_nullable(self):
        TeamMemberVersion = version_class(self.TeamMember)

        assert not TeamMemberVersion.__table__.c.user_id.nullable

Example 28

View license
    def test_previous_for_deleted_parent(self):
        item = self.TextItem()
        item.name = u'Some item'
        item.content = u'Some content'
        self.session.add(item)
        self.session.commit()
        self.session.delete(item)
        self.session.commit()
        TextItemVersion = version_class(self.TextItem)

        versions = (
            self.session.query(TextItemVersion)
            .order_by(
                getattr(
                    TextItemVersion,
                    self.options['transaction_column_name']
                )
            )
        ).all()
        assert versions[1].previous.name == u'Some item'

Example 29

View license
    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()

Example 30

View license
    def test_does_not_make_composite_primary_keys_not_nullable(self):
        TeamMemberVersion = version_class(self.TeamMember)

        assert not TeamMemberVersion.__table__.c.user_id.nullable

Example 31

View license
    def test_composite_primary_key_on_version_tables(self):
        TeamMemberVersion = version_class(self.TeamMember)
        assert len(TeamMemberVersion.__table__.primary_key.columns) == 3

Example 32

View license
    def test_does_not_make_composite_primary_keys_not_nullable(self):
        TeamMemberVersion = version_class(self.TeamMember)

        assert not TeamMemberVersion.__table__.c.user_id.nullable

Example 33

View license
    def test_does_not_make_composite_primary_keys_not_nullable(self):
        TeamMemberVersion = version_class(self.TeamMember)

        assert not TeamMemberVersion.__table__.c.user_id.nullable

Example 34

View license
    def setup_method(self, method):
        TestCase.setup_method(self, method)
        self.TextItemVersion = version_class(self.TextItem)

Example 35

View license
    def setup_method(self, method):
        TestCase.setup_method(self, method)
        self.TextItemVersion = version_class(self.TextItem)

Example 36

View license
    def setup_method(self, method):
        TestCase.setup_method(self, method)
        self.TextItemVersion = version_class(self.TextItem)

Example 37

View license
    def setup_method(self, method):
        TestCase.setup_method(self, method)
        self.TextItemVersion = version_class(self.TextItem)

Example 38

View license
    def setup_method(self, method):
        TestCase.setup_method(self, method)
        self.TextItemVersion = version_class(self.TextItem)

Example 39

View license
    def setup_method(self, method):
        TestCase.setup_method(self, method)
        self.TextItemVersion = version_class(self.TextItem)

Example 40

View license
    def setup_method(self, method):
        TestCase.setup_method(self, method)
        self.TextItemVersion = version_class(self.TextItem)
        self.ArticleVersion = version_class(self.Article)
        self.BlogPostVersion = version_class(self.BlogPost)

Example 41

View license
    def setup_method(self, method):
        TestCase.setup_method(self, method)
        self.TextItemVersion = version_class(self.TextItem)
        self.ArticleVersion = version_class(self.Article)
        self.BlogPostVersion = version_class(self.BlogPost)

Example 42

View license
    def test_parent_class_for_version_class(self):
        ArticleVersion = version_class(self.Article)
        assert parent_class(ArticleVersion) == self.Article

Example 43

View license
    def test_with_version_class(self):
        assert tx_column_name(version_class(self.Article)) == self.options[
            'transaction_column_name'
        ]

Example 44

View license
    def test_with_version_obj(self):
        history_obj = version_class(self.Article)()
        assert tx_column_name(history_obj) == self.options[
            'transaction_column_name'
        ]

Example 45

View license
    def test_version_class_for_versioned_class(self):
        ArticleVersion = version_class(self.Article)
        assert ArticleVersion.__name__ == 'ArticleVersion'

Example 46

View license
    def test_throws_error_for_non_versioned_class(self):
        with raises(ClassNotVersioned):
            version_class('invalid')

Example 47

View license
    def test_parent_class_for_version_class(self):
        ArticleVersion = version_class(self.Article)
        assert parent_class(ArticleVersion) == self.Article

Example 48

Project: sqlalchemy-continuum
Source File: __init__.py
View license
    def setup_method(self, method):
        self.Model = declarative_base()
        make_versioned(options=self.options)

        driver = os.environ.get('DB', 'sqlite')
        self.driver = get_driver_name(driver)
        versioning_manager.plugins = self.plugins
        versioning_manager.transaction_cls = self.transaction_cls
        versioning_manager.user_cls = self.user_cls

        self.engine = create_engine(get_dns_from_driver(self.driver))
        # self.engine.echo = True
        self.create_models()

        sa.orm.configure_mappers()

        self.connection = self.engine.connect()

        if hasattr(self, 'Article'):
            try:
                self.ArticleVersion = version_class(self.Article)
            except ClassNotVersioned:
                pass
        if hasattr(self, 'Tag'):
            try:
                self.TagVersion = version_class(self.Tag)
            except ClassNotVersioned:
                pass
        self.create_tables()

        Session = sessionmaker(bind=self.connection)
        self.session = Session(autoflush=False)
        if driver == 'postgres-native':
            self.session.execute('CREATE EXTENSION IF NOT EXISTS hstore')

Example 49

View license
    def test_with_version_class(self):
        assert tx_column_name(version_class(self.Article)) == self.options[
            'transaction_column_name'
        ]

Example 50

View license
    def test_with_version_obj(self):
        history_obj = version_class(self.Article)()
        assert tx_column_name(history_obj) == self.options[
            'transaction_column_name'
        ]