コード例 #1
0
ファイル: test_fixture.py プロジェクト: Singletoned/wiseguy
def test_SQLAlchemyTester():
    schema.with_empty_db()
    class EmptyFixture(fixture.Fixture):
        pass

    with EmptyFixture(sa_loader) as tester:
        assert tester.Article.count() == 0
コード例 #2
0
ファイル: test_fixture.py プロジェクト: Singletoned/wiseguy
def test_fixture_inheritance():
    schema.with_empty_db()

    class NewFixture(fixture.Fixture):
        CommentData = CommentData

        class ArticleData(fixture.Data):
            class new_article(ArticleData.article1):
                stub = "new_article"

            class new_article2(ArticleData.article2):
                stub = "new_article2"

        class CommentData(CommentData):
            pass

    class NewFixture2(NewFixture):
        class ArticleData(fixture.Data):
            class new_article(ArticleData.article1):
                stub = "new_article3"

    assert NewFixture2.ArticleData.new_article.stub == "new_article3"
    assert len(NewFixture2.ArticleData) == 1
    assert NewFixture2.CommentData.comment1.name == "Mr Smith"
    assert len(NewFixture2.CommentData) == 2

    with NewFixture2(sa_loader) as tester:
        assert tester.Article.one()
        assert tester.Comment.count() == 2

    class NewFixture3(NewFixture):
        CommentData = None

    assert not NewFixture3._data.has_key('CommentData')
コード例 #3
0
ファイル: test_fixture.py プロジェクト: Singletoned/wiseguy
def test_multiple_inheritance():
    schema.with_empty_db()

    class FixtureOne(fixture.Fixture):
        class ArticleData(fixture.Data):
            _entity = schema.Article

            class article_1:
                stub = 'foo'
                name = 'Foo'
                body = 'The Foo article'
                score = 1

    class FixtureTwo(FixtureOne):
        class ArticleData(FixtureOne.ArticleData):
            class article_2:
                stub = 'bar'
                name = 'Bar'
                body = 'The Bar article'
                score = 2

    class FixtureThree(FixtureTwo):
        class CommentData(fixture.Data):
            _entity = schema.Comment

            class comment_1:
                id = 1
                article_stub = 'foo'
                email = '*****@*****.**'
                name = 'Bob'
                body = 'I like this article'

    with FixtureThree(sa_loader) as tester:
        assert tester.Article.count() == 2
コード例 #4
0
def test_multiple_inheritance():
    schema.with_empty_db()

    class FixtureOne(fixture.Fixture):
        class ArticleData(fixture.Data):
            _entity = schema.Article

            class article_1:
                stub = 'foo'
                name = 'Foo'
                body = 'The Foo article'
                score = 1

    class FixtureTwo(FixtureOne):
        class ArticleData(FixtureOne.ArticleData):
            class article_2:
                stub = 'bar'
                name = 'Bar'
                body = 'The Bar article'
                score = 2

    class FixtureThree(FixtureTwo):
        class CommentData(fixture.Data):
            _entity = schema.Comment

            class comment_1:
                id = 1
                article_stub = 'foo'
                email = '*****@*****.**'
                name = 'Bob'
                body = 'I like this article'

    with FixtureThree(sa_loader) as tester:
        assert tester.Article.count() == 2
コード例 #5
0
ファイル: test_fixture.py プロジェクト: Singletoned/wiseguy
def test_data_inheritance():
    schema.with_empty_db()

    class new_article(ArticleData.article1):
        stub = "new_article"

    assert new_article.stub == "new_article"
    assert new_article.body == ArticleData.article1.body

    class NewData(fixture.Data):
        _entity = schema.Article
        class new_article(ArticleData.article1):
            stub = "new_article"

    assert NewData.new_article.stub == "new_article"
    assert NewData.new_article.body == ArticleData.article1.body
    assert NewData._items

    class NewFixture(fixture.Fixture):
        CommentData = CommentData

        class ArticleData(fixture.Data):
            # _entity = schema.Article
            class new_article(ArticleData.article1):
                stub = "new_article"

    article = NewFixture.ArticleData.new_article
    assert article.stub == "new_article"
    assert article.name == "The First Article"

    with NewFixture(sa_loader) as tester:
        article = tester.Article.one()
        assert article.stub == "new_article"
        assert article.name == "The First Article"
        assert tester._data['ArticleData'].new_article.stub == "new_article"
コード例 #6
0
def test_fixture_inheritance():
    schema.with_empty_db()

    class NewFixture(fixture.Fixture):
        CommentData = CommentData

        class ArticleData(fixture.Data):
            class new_article(ArticleData.article1):
                stub = "new_article"

            class new_article2(ArticleData.article2):
                stub = "new_article2"

        class CommentData(CommentData):
            pass

    class NewFixture2(NewFixture):
        class ArticleData(fixture.Data):
            class new_article(ArticleData.article1):
                stub = "new_article3"

    assert NewFixture2.ArticleData.new_article.stub == "new_article3"
    assert len(NewFixture2.ArticleData) == 1
    assert NewFixture2.CommentData.comment1.name == "Mr Smith"
    assert len(NewFixture2.CommentData) == 2

    with NewFixture2(sa_loader) as tester:
        assert tester.Article.one()
        assert tester.Comment.count() == 2

    class NewFixture3(NewFixture):
        CommentData = None

    assert not NewFixture3._data.has_key('CommentData')
コード例 #7
0
def test_SQLAlchemyTester():
    schema.with_empty_db()

    class EmptyFixture(fixture.Fixture):
        pass

    with EmptyFixture(sa_loader) as tester:
        assert tester.Article.count() == 0
コード例 #8
0
ファイル: test_fixture.py プロジェクト: Singletoned/wiseguy
def test_first_fixture():
    schema.with_empty_db()

    with FirstFixture(sa_loader) as tester:
        article1 = tester.session.query(schema.Article).one()
        assert tester.Article.one() == article1
        assert tester.Article.count() == 1
        assert tester.Article.all() == [article1]
        comment1 = tester.session.query(schema.Comment).one()
        assert tester.Comment.one() == comment1
        assert tester.Comment.count() == 1
        assert tester.Comment.all() == [comment1]
コード例 #9
0
def test_first_fixture():
    schema.with_empty_db()

    with FirstFixture(sa_loader) as tester:
        article1 = tester.session.query(schema.Article).one()
        assert tester.Article.one() == article1
        assert tester.Article.count() == 1
        assert tester.Article.all() == [article1]
        comment1 = tester.session.query(schema.Comment).one()
        assert tester.Comment.one() == comment1
        assert tester.Comment.count() == 1
        assert tester.Comment.all() == [comment1]
コード例 #10
0
ファイル: test_fixture.py プロジェクト: Singletoned/wiseguy
def test_override():
    schema.with_empty_db()

    class NewFixture(fixture.Fixture):
        class ArticleData(ArticleData):
            class _override:
                name = "overridden"

    assert NewFixture.ArticleData._items != ArticleData._items
    assert not (NewFixture.ArticleData._items is ArticleData._items)

    with NewFixture(sa_loader) as tester:
        for article in tester.Article.all():
            assert article.name == "overridden"

    for article in ArticleData:
        assert article.name != "overridden"
コード例 #11
0
def test_override():
    schema.with_empty_db()

    class NewFixture(fixture.Fixture):
        class ArticleData(ArticleData):
            class _override:
                name = "overridden"

    assert NewFixture.ArticleData._items != ArticleData._items
    assert not (NewFixture.ArticleData._items is ArticleData._items)

    with NewFixture(sa_loader) as tester:
        for article in tester.Article.all():
            assert article.name == "overridden"

    for article in ArticleData:
        assert article.name != "overridden"
コード例 #12
0
def test_data_inheritance():
    schema.with_empty_db()

    class new_article(ArticleData.article1):
        stub = "new_article"

    assert new_article.stub == "new_article"
    assert new_article.body == ArticleData.article1.body

    class NewData(fixture.Data):
        _entity = schema.Article

        class new_article(ArticleData.article1):
            stub = "new_article"

    assert NewData.new_article.stub == "new_article"
    assert NewData.new_article.body == ArticleData.article1.body
    assert NewData._items

    class NewFixture(fixture.Fixture):
        CommentData = CommentData

        class ArticleData(fixture.Data):
            # _entity = schema.Article
            class new_article(ArticleData.article1):
                stub = "new_article"

    article = NewFixture.ArticleData.new_article
    assert article.stub == "new_article"
    assert article.name == "The First Article"

    with NewFixture(sa_loader) as tester:
        article = tester.Article.one()
        assert article.stub == "new_article"
        assert article.name == "The First Article"
        assert tester._data['ArticleData'].new_article.stub == "new_article"