Skip to content

Commit

Permalink
Merge branch 'kyheo-feature/module-as-class-name'
Browse files Browse the repository at this point in the history
  • Loading branch information
kvesteri committed Jan 10, 2016
2 parents 51e45f1 + 112f00b commit 7031d82
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion sqlalchemy_continuum/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def __init__(
'transaction_column_name': 'transaction_id',
'end_transaction_column_name': 'end_transaction_id',
'operation_type_column_name': 'operation_type',
'strategy': 'validity'
'strategy': 'validity',
'use_module_name': False
}
if plugins is None:
self.plugins = []
Expand Down
12 changes: 7 additions & 5 deletions sqlalchemy_continuum/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,13 @@ def mapper_args(cls):

args.update(self.get_inherited_denormalized_columns(table))

return type(
'%sVersion' % self.model.__name__,
self.base_classes(),
args
)
if self.manager.options.get('use_module_name', True):
name = '%s%sVersion' % (
self.model.__module__.title().replace('.', ''),
self.model.__name__)
else:
name = '%sVersion' % (self.model.__name__,)
return type(name, self.base_classes(), args)

def __call__(self, table, tx_class):
"""
Expand Down
9 changes: 9 additions & 0 deletions tests/utils/test_version_class.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from pytest import raises
from sqlalchemy_continuum import ClassNotVersioned, version_class
from sqlalchemy_continuum.manager import VersioningManager
from sqlalchemy_continuum.model_builder import ModelBuilder

from tests import TestCase

Expand All @@ -12,3 +14,10 @@ def test_version_class_for_versioned_class(self):
def test_throws_error_for_non_versioned_class(self):
with raises(ClassNotVersioned):
version_class('invalid')

def test_module_name_in_class_name(self):
options = {'use_module_name': True}
vm = VersioningManager(options=options)
mb = ModelBuilder(vm, self.Article)
ArticleVersion = mb.build_model(self.Article.__table__)
assert ArticleVersion.__name__ == 'TestsArticleVersion'

0 comments on commit 7031d82

Please sign in to comment.