Ejemplo n.º 1
0
def setup_app(command, conf, vars):
    """Place any commands to setup tracking here"""
    load_environment(conf.global_conf, conf.local_conf)

    filename = os.path.split(conf.filename)[-1]

    if filename == 'test.ini':

        # Permanently drop any existing tables

        log.info("Dropping existing tables...")

        meta.Base.metadata.drop_all(bind=meta.engine, checkfirst=True)

    log.info("Creating tables...")

    # Create the tables if they don't already exist
    meta.Base.metadata.create_all(bind=meta.engine)

    log.info("Successfully set up.")

    if filename == 'development.ini':

        # load sample data during setup-app

        db = SQLAlchemyFixture(env=model,
                               style=NamedDataStyle(),
                               engine=meta.engine)

        data = db.data(PageviewsData)
        log.info("Loading sample data...")
        data.setup()

    log.info("Successfully set up.")
Ejemplo n.º 2
0
def test_dataset_without_resolvable_model_name():
    class UnknownData(DataSet):
        class foo:
            foo = 1

    fixture = DjangoFixture(style=NamedDataStyle())
    ds = UnknownData()
    fixture.attach_storage_medium(ds)
Ejemplo n.º 3
0
 def create_fixture(self):
     return SQLAlchemyFixture(
         env = self.env,
         style = NamedDataStyle(),
         dataclass = MergedSuperSet,
         # *load* data into the memory db :
         engine = memmeta.bind
     )
Ejemplo n.º 4
0
def main():
    p = optparse.OptionParser(usage="%prog [options]")
    default = "/tmp/dev_appserver.datastore"
    p.add_option(
        "--datastore_path",
        default=default,
        help=
        ("Path to datastore file.  This must match the value used for "
         "the same option when running dev_appserver.py if you want to view the data.  "
         "Default: %s" % default))
    default = "/tmp/dev_appserver.datastore.history"
    p.add_option(
        "--history_path",
        default=default,
        help=
        ("Path to datastore history file.  This doesn't need to match the one you use for "
         "dev_appserver.py.  Default: %s" % default))
    default = "/usr/local/google_appengine"
    p.add_option("--google_path",
                 default=default,
                 help=("Path to google module directory.  Default: %s" %
                       default))
    (options, args) = p.parse_args()

    if not os.path.exists(options.google_path):
        p.error(
            "Could not find google module path at %s.  You'll need to specify the path"
            % options.google_path)

    groot = options.google_path
    sys.path.append(groot)
    sys.path.append(os.path.join(groot, "lib/django"))
    sys.path.append(os.path.join(groot, "lib/webob"))
    sys.path.append(os.path.join(groot, "lib/yaml/lib"))

    from google.appengine.tools import dev_appserver
    from gblog import models
    from tests import datasets

    config, explicit_matcher = dev_appserver.LoadAppConfig(
        os.path.dirname(__file__), {})
    dev_appserver.SetupStubs(
        config.application,
        clear_datastore=False,  # just removes the files when True
        datastore_path=options.datastore_path,
        history_path=options.history_path,
        login_url=None)

    datafixture = GoogleDatastoreFixture(env=models, style=NamedDataStyle())

    data = datafixture.data(datasets.CommentData, datasets.EntryData)
    data.setup()
    print "Data loaded into datastore %s" % (options.datastore_path
                                             or "[default]")
Ejemplo n.º 5
0
def test_model_lookup_by_app_label_and_style_derived_name():
    class PostData(DataSet):
        class Meta:
            django_app_label = "blog"

        class foo:
            foo = 1

    fixture = DjangoFixture(style=NamedDataStyle())
    ds = PostData()
    fixture.attach_storage_medium(ds)
    assert_equal(ds.meta.storage_medium.medium, Post)
Ejemplo n.º 6
0
    def load_fixtures(self, *args):
        # TODO: Check https://github.com/mitsuhiko/flask-sqlalchemy/pull/89
        # and update version of Flask-Sqlalchemy
        from api import models
        from fixture import SQLAlchemyFixture
        from fixture.style import NamedDataStyle

        db = SQLAlchemyFixture(env=models,
                               style=NamedDataStyle(),
                               engine=self.engine)
        data = db.data(*args)
        data.setup()
        db.dispose()
Ejemplo n.º 7
0
 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()
Ejemplo n.º 8
0
    def setUp(self):
        """Set up required for the view tests.
    """

        self.view = TestView()
        self.stubout_helper = StuboutHelper()
        self.stubout_helper.stuboutBase()
        self.stubout_helper.stuboutElement(task.View, 'select',
                                           ['request', 'view', 'redirect'])

        # map all the models
        models_dict = {
            'User': models.user.User,
            'Site': models.site.Site,
            'Sponsor': models.sponsor.Sponsor,
            'Host': models.host.Host,
            'GCITimeline': gci_models.timeline.GCITimeline,
            'GCIProgram': gci_models.program.GCIProgram,
            'GCIOrganization': gci_models.organization.GCIOrganization,
            'GCIOrgAdmin': gci_models.org_admin.GCIOrgAdmin,
            'GCIMentor': gci_models.mentor.GCIMentor,
            'GCIStudent': gci_models.student.GCIStudent,
            'GCITask': gci_models.task.GCITask,
        }

        # create a fixture for Appengine datastore using the previous map
        datafixture = GoogleDatastoreFixture(env=models_dict,
                                             style=NamedDataStyle())

        # seed the data in the datastore
        self.data = datafixture.data(
            datasets.UserData, datasets.SiteData, datasets.SponsorData,
            datasets.HostData, datasets.GCITimelineData,
            datasets.GCIProgramData, datasets.GCIOrganizationData,
            datasets.GCIOrgAdminData, datasets.GCIMentorData,
            datasets.GCIMentorData, datasets.GCITaskData)

        self.data.setup()
Ejemplo n.º 9
0
 def setUpClass(cls):
     SQLAlchemyTestCase.setUpClass()
     cls.fixture = SQLAlchemyFixture(env=_all,
                                     style=NamedDataStyle(),
                                     engine=connection)
Ejemplo n.º 10
0
from fixture import DataSet, DjangoFixture
from fixture.style import NamedDataStyle
from fixture.django_testcase import FixtureTestCase
from datetime import datetime
from django.contrib.auth.models import User
from fixture.examples.django_example.blog.models import Post, Category
from fixture.examples.django_example.blog.datasets.blog_data import (
    UserData, PostData, CategoryData)

db_fixture = DjangoFixture(style=NamedDataStyle())


class TestBlogWithData(FixtureTestCase):
    fixture = db_fixture
    datasets = [PostData]

    def test_blog_posts(self):
        self.assertEquals(Post.objects.all().count(), 3,
                          "There are 3 blog posts")
        post = Post.objects.get(title=PostData.third_post.title)
        self.assertEquals(post.categories.count(), 2,
                          "The 3rd test post is in 2 categories")

    def test_posts_by_category(self):
        py = Category.objects.get(title=CategoryData.python.title)
        self.assertEquals(py.post_set.count(), 3,
                          "There are 3 posts in python category")

    def test_posts_by_author(self):
        ben = User.objects.get(username=UserData.ben.username)
        self.assertEquals(ben.post_set.all().count(), 3,
Ejemplo n.º 11
0
# coding=utf-8

from fixture import SQLAlchemyFixture
from fixture.style import NamedDataStyle

from core.database import db
from wiki.models import WikiPage, WikiPageVersion
from fixture_wiki import WikiPageData, WikiPageVersionData


models_map = {
    'WikiPage': WikiPage,
    'WikiPageVersion': WikiPageVersion,
}

dbfixture = SQLAlchemyFixture(
    env=models_map,
    style=NamedDataStyle(),
    engine=db.engine
)

fixtures_data = (
    WikiPageData,
    WikiPageVersionData,
)


def fixtures_install(app, *args):
    data = dbfixture.data(*args)
    data.setup()
Ejemplo n.º 12
0
def install(app, *args):
    engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
    db = SQLAlchemyFixture(env=models, style=NamedDataStyle(), engine=engine)
    data = db.data(*args)
    data.setup()
    db.dispose()
Ejemplo n.º 13
0
import unittest
from fixture import GoogleDatastoreFixture, DataSet
from fixture.style import NamedDataStyle
from gblog import application, models
from webtest import TestApp
from datasets import CommentData, EntryData

datafixture = GoogleDatastoreFixture(env=models, style=NamedDataStyle())

class TestListEntries(unittest.TestCase):
    def setUp(self):
        self.app = TestApp(application)
        self.data = datafixture.data(CommentData, EntryData)
        self.data.setup()
    
    def tearDown(self):
        self.data.teardown()
    
    def test_entries(self):
        response = self.app.get("/")
        print response
        
        assert EntryData.great_monday.title in response
        assert EntryData.great_monday.body in response
        
        assert CommentData.monday_liked_it.comment in response
        assert CommentData.monday_sucked.comment in response