diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-08-28 00:37:32 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-08-28 00:38:24 +0200 |
commit | 7fc3e4cbdae050dcde49ea3101636ddf57d6c96d (patch) | |
tree | 119a7a3effecc95ef657a0c3fe673466e830d365 /factory | |
parent | ac1322cf12fc79e5d11abf1aa95b01413b312258 (diff) | |
download | factory-boy-7fc3e4cbdae050dcde49ea3101636ddf57d6c96d.tar factory-boy-7fc3e4cbdae050dcde49ea3101636ddf57d6c96d.tar.gz |
Remove duplicate SQLAlchemyModelFactory (Closes #83).
Diffstat (limited to 'factory')
-rw-r--r-- | factory/alchemy.py | 1 | ||||
-rw-r--r-- | factory/base.py | 33 |
2 files changed, 1 insertions, 33 deletions
diff --git a/factory/alchemy.py b/factory/alchemy.py index ca7aefa..cec15c9 100644 --- a/factory/alchemy.py +++ b/factory/alchemy.py @@ -28,6 +28,7 @@ class SQLAlchemyModelFactory(base.Factory): """Factory for SQLAlchemy models. """ ABSTRACT_FACTORY = True + FACTORY_SESSION = None @classmethod def _setup_next_sequence(cls, *args, **kwargs): diff --git a/factory/base.py b/factory/base.py index 0db8249..ac906de 100644 --- a/factory/base.py +++ b/factory/base.py @@ -640,36 +640,3 @@ def use_strategy(new_strategy): klass.FACTORY_STRATEGY = new_strategy return klass return wrapped_class - - -class SQLAlchemyModelFactory(Factory): - """Factory for SQLAlchemy models. """ - - ABSTRACT_FACTORY = True - FACTORY_HIDDEN_ARGS=('SESSION',) - - def __init__(self, session): - self.session = session - - @classmethod - def _get_function(cls, function_name): - session = cls._declarations['SESSION'] - sqlalchemy = __import__(session.__module__) - max = getattr(sqlalchemy.sql.functions, function_name) - - @classmethod - def _setup_next_sequence(cls, *args, **kwargs): - """Compute the next available PK, based on the 'pk' database field.""" - max = cls._get_function('max') - session = cls._declarations['SESSION'] - pk = cls.FACTORY_FOR.__table__.primary_key.columns.values()[0].key - max_pk = session.query(max(getattr(cls.FACTORY_FOR, pk))).one() - return max_pk[0] + 1 if max_pk[0] else 1 - - @classmethod - def _create(cls, target_class, *args, **kwargs): - """Create an instance of the model, and save it to the database.""" - session = cls._declarations['SESSION'] - obj = target_class(*args, **kwargs) - session.add(obj) - return obj |