def setup_command_data(): import os if os.path.exists('/tmp/fixture_example.db'): os.unlink('/tmp/fixture_example.db') if os.path.exists('/tmp/fixture_generate.db'): os.unlink('/tmp/fixture_generate.db') import sqlalchemy as sa from sqlalchemy import orm from fixture.examples.db.sqlalchemy_examples import (Author, authors, Book, books, metadata) metadata.bind = sa.create_engine('sqlite:////tmp/fixture_example.db') metadata.create_all() orm.mapper(Book, books) orm.mapper(Author, authors, properties={'books': orm.relation(Book, backref='author')}) Session = orm.sessionmaker(bind=metadata.bind, autoflush=True, transactional=True) session = Session() frank = Author() frank.first_name = "Frank" frank.last_name = "Herbert" session.save(frank) dune = Book() dune.title = "Dune" dune.author = frank session.save(dune) session.commit()
def setup_command_data(): import os if os.path.exists('/tmp/fixture_example.db'): os.unlink('/tmp/fixture_example.db') if os.path.exists('/tmp/fixture_generate.db'): os.unlink('/tmp/fixture_generate.db') import sqlalchemy as sa from sqlalchemy import orm from fixture.examples.db.sqlalchemy_examples import ( Author, authors, Book, books, metadata) metadata.bind = sa.create_engine('sqlite:////tmp/fixture_example.db') metadata.create_all() orm.mapper(Book, books) orm.mapper(Author, authors, properties={'books': orm.relation(Book, backref='author')}) Session = orm.sessionmaker(bind=metadata.bind, autoflush=True, transactional=True) session = Session() frank = Author() frank.first_name = "Frank" frank.last_name = "Herbert" session.save(frank) dune = Book() dune.title = "Dune" dune.author = frank session.save(dune) session.commit()
def setup_command_data(): import os from fixture import SQLObjectFixture from fixture.examples.db import sqlobject_examples from sqlalchemy import (MetaData, create_engine, Table, Integer, String, ForeignKey, Column) from sqlalchemy.orm import (scoped_session, sessionmaker, mapper, relation) from fixture import DataSet from fixture import SQLAlchemyFixture if os.path.exists('/tmp/fixture_example.db'): os.unlink('/tmp/fixture_example.db') if os.path.exists('/tmp/fixture_generate.db'): os.unlink('/tmp/fixture_generate.db') import sqlalchemy as sa from sqlalchemy import orm from fixture.examples.db.sqlalchemy_examples import (Author, authors, Book, books, metadata) metadata.bind = sa.create_engine('sqlite:////tmp/fixture_example.db') metadata.create_all() orm.mapper(Book, books) orm.mapper(Author, authors, properties={'books': orm.relation(Book, backref='author')}) Session = orm.sessionmaker(bind=metadata.bind, autoflush=True, transactional=True) session = Session() frank = Author() frank.first_name = "Frank" frank.last_name = "Herbert" session.save(frank) dune = Book() dune.title = "Dune" dune.author = frank session.save(dune) session.commit()
def setUp(self): from fixture import SQLAlchemyFixture, NamedDataStyle import sqlalchemy from sqlalchemy.orm import ( mapper, relation, clear_mappers, sessionmaker, scoped_session) from sqlalchemy import create_engine metadata.bind = create_engine(conf.LITE_DSN) metadata.create_all() class options: dsn = conf.LITE_DSN env = ['fixture.examples.db.sqlalchemy_examples'] self.options = options self.generator = DataSetGenerator(self.options, template=StubTemplate()) ScopedSession = scoped_session(sessionmaker(autoflush=False, transactional=True)) ScopedSession.mapper(Category, categories, save_on_init=False) ScopedSession.mapper(Product, products, properties={ 'category': relation(Category), }, save_on_init=False) ScopedSession.mapper(Offer, offers, properties={ 'category': relation(Category, backref='products'), 'product': relation(Product) }, save_on_init=False) self.fixture = SQLAlchemyFixture( env=sqlalchemy_examples, style=NamedDataStyle(), engine=metadata.bind) self.data = self.fixture.data(self.CategoryData) self.data.setup() self.hnd = self.generator.get_handler( "%s.Category" % (Category.__module__), obj=Category, connection=metadata.bind) self.hnd.begin()
def setup_command_data(): import os from fixture import SQLObjectFixture from fixture.examples.db import sqlobject_examples from sqlalchemy import ( MetaData, create_engine, Table, Integer, String, ForeignKey, Column) from sqlalchemy.orm import (scoped_session, sessionmaker, mapper, relation) from fixture import DataSet from fixture import SQLAlchemyFixture if os.path.exists('/tmp/fixture_example.db'): os.unlink('/tmp/fixture_example.db') if os.path.exists('/tmp/fixture_generate.db'): os.unlink('/tmp/fixture_generate.db') import sqlalchemy as sa from sqlalchemy import orm from fixture.examples.db.sqlalchemy_examples import ( Author, authors, Book, books, metadata) metadata.bind = sa.create_engine('sqlite:////tmp/fixture_example.db') metadata.create_all() orm.mapper(Book, books) orm.mapper(Author, authors, properties={'books': orm.relation(Book, backref='author')}) Session = orm.sessionmaker(bind=metadata.bind, autoflush=True, transactional=True) session = Session() frank = Author() frank.first_name = "Frank" frank.last_name = "Herbert" session.save(frank) dune = Book() dune.title = "Dune" dune.author = frank session.save(dune) session.commit()