Refactored tests
This commit is contained in:
@@ -1,9 +1,23 @@
|
|||||||
|
from collections import defaultdict
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy_utils import generates
|
from sqlalchemy_utils import generates, decorators
|
||||||
from tests import TestCase
|
from tests import TestCase
|
||||||
|
|
||||||
|
|
||||||
class TestGeneratesWithBoundMethodAndClassVariableArg(TestCase):
|
class GeneratesTestCase(TestCase):
|
||||||
|
def setup_method(self, method):
|
||||||
|
TestCase.setup_method(self, method)
|
||||||
|
decorators.generator_registry = defaultdict(list)
|
||||||
|
|
||||||
|
def test_generates_value_before_flush(self):
|
||||||
|
article = self.Article()
|
||||||
|
article.name = u'some article name'
|
||||||
|
self.session.add(article)
|
||||||
|
self.session.flush()
|
||||||
|
assert article.slug == u'some-article-name'
|
||||||
|
|
||||||
|
|
||||||
|
class TestGeneratesWithBoundMethodAndClassVariableArg(GeneratesTestCase):
|
||||||
def create_models(self):
|
def create_models(self):
|
||||||
class Article(self.Base):
|
class Article(self.Base):
|
||||||
__tablename__ = 'article'
|
__tablename__ = 'article'
|
||||||
@@ -17,15 +31,8 @@ class TestGeneratesWithBoundMethodAndClassVariableArg(TestCase):
|
|||||||
|
|
||||||
self.Article = Article
|
self.Article = Article
|
||||||
|
|
||||||
def test_generates_value_before_flush(self):
|
|
||||||
article = self.Article()
|
|
||||||
article.name = u'some article name'
|
|
||||||
self.session.add(article)
|
|
||||||
self.session.flush()
|
|
||||||
assert article.slug == u'some-article-name'
|
|
||||||
|
|
||||||
|
class TestGeneratesWithBoundMethodAndStringArg(GeneratesTestCase):
|
||||||
class TestGeneratesWithBoundMethodAndStringArg(TestCase):
|
|
||||||
def create_models(self):
|
def create_models(self):
|
||||||
class Article(self.Base):
|
class Article(self.Base):
|
||||||
__tablename__ = 'article'
|
__tablename__ = 'article'
|
||||||
@@ -39,15 +46,8 @@ class TestGeneratesWithBoundMethodAndStringArg(TestCase):
|
|||||||
|
|
||||||
self.Article = Article
|
self.Article = Article
|
||||||
|
|
||||||
def test_generates_value_before_flush(self):
|
|
||||||
article = self.Article()
|
|
||||||
article.name = u'some article name'
|
|
||||||
self.session.add(article)
|
|
||||||
self.session.flush()
|
|
||||||
assert article.slug == u'some-article-name'
|
|
||||||
|
|
||||||
|
class TestGeneratesWithFunctionAndStringArg(GeneratesTestCase):
|
||||||
class TestGeneratesWithFunctionAndStringArg(TestCase):
|
|
||||||
def create_models(self):
|
def create_models(self):
|
||||||
class Article(self.Base):
|
class Article(self.Base):
|
||||||
__tablename__ = 'article'
|
__tablename__ = 'article'
|
||||||
@@ -61,15 +61,8 @@ class TestGeneratesWithFunctionAndStringArg(TestCase):
|
|||||||
|
|
||||||
self.Article = Article
|
self.Article = Article
|
||||||
|
|
||||||
def test_generates_value_before_flush(self):
|
|
||||||
article = self.Article()
|
|
||||||
article.name = u'some article name'
|
|
||||||
self.session.add(article)
|
|
||||||
self.session.flush()
|
|
||||||
assert article.slug == u'some-article-name'
|
|
||||||
|
|
||||||
|
class TestGeneratesWithFunctionAndClassVariableArg(GeneratesTestCase):
|
||||||
class TestGeneratesWithFunctionAndClassVariableArg(TestCase):
|
|
||||||
def create_models(self):
|
def create_models(self):
|
||||||
class Article(self.Base):
|
class Article(self.Base):
|
||||||
__tablename__ = 'article'
|
__tablename__ = 'article'
|
||||||
@@ -82,10 +75,3 @@ class TestGeneratesWithFunctionAndClassVariableArg(TestCase):
|
|||||||
return self.name.lower().replace(' ', '-')
|
return self.name.lower().replace(' ', '-')
|
||||||
|
|
||||||
self.Article = Article
|
self.Article = Article
|
||||||
|
|
||||||
def test_generates_value_before_flush(self):
|
|
||||||
article = self.Article()
|
|
||||||
article.name = u'some article name'
|
|
||||||
self.session.add(article)
|
|
||||||
self.session.flush()
|
|
||||||
assert article.slug == u'some-article-name'
|
|
||||||
|
Reference in New Issue
Block a user