elixir3 / tests / test_perform_ddl.py

from elixir import *
from elixir.ext.perform_ddl import perform_ddl, preload_data


def setup():
    metadata.bind = "sqlite://"


class TestPerformDDL(object):
    def teardown(self):
        cleanup_all(True)

    def test_one(self):
        class Movie(Entity):
            title = Field(Unicode(30), primary_key=True)
            year = Field(Integer)

            perform_ddl('after-create',
                        "insert into %(fullname)s values ('Alien', 1979)")

        setup_all(True)
        assert Movie.query.count() == 1

    def test_several(self):
        class Movie(Entity):
            title = Field(Unicode(30), primary_key=True)
            year = Field(Integer)

            perform_ddl('after-create',
                        ["insert into %(fullname)s values ('Alien', 1979)",
                         "insert into %(fullname)s " +
                            "values ('Star Wars', 1977)"])
            perform_ddl('after-create',
                        "insert into %(fullname)s (year, title) " +
                        "values (1982, 'Blade Runner')")

        setup_all(True)
        assert Movie.query.count() == 3

class TestPreloadData(object):
    def teardown(self):
        cleanup_all(True)

    def test_several(self):
        class Movie(Entity):
            title = Field(Unicode(30), primary_key=True)
            year = Field(Integer)

            preload_data(('title', 'year'),
                         [(u'Alien', 1979), (u'Star Wars', 1977)])
            preload_data(('year', 'title'),
                         [(1982, u'Blade Runner')])
            preload_data(data=[(u'Batman', 1966)])

        setup_all(True)
        assert Movie.query.count() == 4
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.