Example #1
0
    def setUp(self):
        self.app = create_app("testing")

        # app context
        self.app_context = self.app.app_context()
        self.app_context.push()

        # drop database in case it exissts, and create new version
        db.drop_all()
        db.create_all()

        # test client
        self.client = self.app.test_client()

        # stormpath client
        self.sp_client = Client(id=environ.get("STORMPATH_API_KEY_ID"), secret=environ.get("STORMPATH_API_KEY_SECRET"))

        # retrieve photog_test application instance
        href = "https://api.stormpath.com/v1/applications/Nq2qQQegOh9a9qJRekxeA"
        self.application = self.sp_client.applications.get(href)

        self.test_email = "test_user@photog.com"
        self.test_password = "4P@$$w0rd!"

        self.user = self.create_default_user()
Example #2
0
def remove_database(app, db):
    db.session.remove()
    db.drop_all()
    try:
        os.remove(app.config["TEST_DB_FILEPATH"])
    except FileNotFoundError:
        pass
Example #3
0
    def tearDown(self):
        # Wipes the testing database and remove the test application
        # context.

        db.session.remove()
        db.drop_all()
        self.app_context.pop()
Example #4
0
def rebuild():
    if config == "development":
        with app.app_context():
            db.drop_all()
            db.create_all()
            Role.insert_roles()
            admin_me = User(
                email=app.config["FLASKR_ADMIN"],
                username=app.config["MY_USERNAME"],
                password=app.config["MY_PASSWORD"],
                confirmed=True,
                name=forgery_py.name.full_name(),
                location=forgery_py.address.city(),
                about_me=forgery_py.lorem_ipsum.sentences(10),
                member_since=forgery_py.date.date(True, min_delta=10),
            )
            db.session.add(admin_me)
            ordinary_me = User(
                email=forgery_py.internet.email_address(),
                username="exm",
                password="exm",
                confirmed=True,
                name=forgery_py.name.full_name(),
                location=forgery_py.address.city(),
                about_me=forgery_py.lorem_ipsum.sentences(10),
                member_since=forgery_py.date.date(True, min_delta=10),
            )
            db.session.add(ordinary_me)
            db.session.commit()
            User.generate_fake(30)
            Post.generate_fake(500)
            Follow.generate_fake(500)
            Comment.generate_fake(500)
    else:
        print("Permission denied.")
Example #5
0
def teardown_func():
    "tear down test fixtures"
    db.session.remove()
    db.drop_all()
    app.config.from_object("config.DevelopmentConfig")
    app.config["WTF_CSRF_ENABLED"] = True
    app.config["CSRF_ENABLED"] = True
Example #6
0
 def tearDown(self):
     """
     数据库和程序上下文在 tearDown() 方法中删除。
     """
     db.session.remove()
     db.drop_all()
     self.app_context.pop()
Example #7
0
 def tearDown(self):
     # ?
     db.session.remove()
     # drop tables
     db.drop_all()
     # pop app context
     self.app_context.pop()
Example #8
0
def dropdb():
    """Drops database tables"""
    if prompt_bool("Are you sure you want to lose all your data"):
        destroy_db()
        db.drop_all()
        db_setup()
        db.create_all()
Example #9
0
def createdb():
    print "creating db.."
    db.drop_all()
    db.create_all()
    Role.insert_roles()

    print "adding feed sources.."
    with open("sources.yaml", "r") as f:
        feed_sources = yaml.load(f)

        # Insert feedprovider
    for site in feed_sources:
        provider_name = unicode(site["name"])
        provider_domain = site["domain"]
        provider = FeedProvider(name=provider_name, domain=provider_domain, favicon=site["favicon"])
        db.session.add(provider)
        db.session.commit()

        # Add feedsource
        for channel_name in site["channels"]:
            source_name = unicode(site["name"] + " - " + channel_name)
            source_href = site["channels"][channel_name]
            fs = FeedSource(name=source_name, url=source_href, provider=provider)
            db.session.add(fs)

    db.session.commit()

    print "add feed articles.."
    from app.mod_crawler.fetch import update_db

    update_db()
Example #10
0
 def tearDown(self):
     try:
         shutil.rmtree(app.config["UPLOAD_FOLDER"])
     except OSError:
         pass
     db.session.remove()
     db.drop_all()
Example #11
0
def init():
    """ Fixture for test initialisation
    """
    # App configuration overide
    app.config["TESTING"] = True
    app.config["WTF_CSRF_ENABLED"] = False
    app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://"
    app.config["SERVER_NAME"] = "localhost"
    # DB creation
    db.create_all()
    user = User(
        nickname="utest",
        email="utest@test.com",
        password="pptest",
        active=True,
        confirmed_at=datetime.utcnow(),
        auth_token="ddg56@dgfdG°dkjvk,",
    )
    db.session.add(user)
    db.session.commit()
    # Context setup
    context = app.app_context()
    context.push()
    yield
    db.session.remove()
    db.drop_all()
    context.pop()
def create_dev_database():
    """
    Use this when running a development server.  It creates tables without
    using db migration scripts, instead asking SQLAlchemy to create them
    directly from your models.  Good for testing/iterating.  When done,
    write proper db migration scripts and test.
    """
    from app import db
    from app.models import Role, User

    db.drop_all()
    db.create_all()

    admin_role = Role(name="Admin")
    mod_role = Role(name="Moderator")
    user_role = Role(name="User")
    db.session.add(admin_role)
    db.session.add(mod_role)
    db.session.add(user_role)

    user_john = User(username="john", role=admin_role, password="cat", email="john@example.com", confirmed=True)
    user_susan = User(username="susan", role=user_role, password="cat", email="susan@example.com", confirmed=False)
    user_david = User(username="david", role=user_role, password="cat", email="david@example.com", confirmed=False)

    db.session.add(user_john)
    db.session.add(user_susan)
    db.session.add(user_david)
    db.session.commit()
Example #13
0
    def tearDown(self):
        """database removal"""
        assert self.cls_initialized
        db.drop_all()
        self.cls_initialized = False

        print("TestAPI Class Teardown\n")
Example #14
0
def reset_db():
    """ Resets database and creates some initial fixtures for us """
    db.drop_all()
    db.create_all()

    username = "jerkovic"
    email = "erilundin@gmail.com"
    u1 = User(username, email, "test")
    db.session.add(u1)
    db.session.commit()

    for name in [
        "Fluffy",
        "Zeebree",
        "Starky",
        "Yawney",
        "Tyson",
        "Pretty",
        "Happey",
        "Chaperon",
        "Fraidy",
        "Weee",
        "Licky",
        "Cuddley",
        "Rocky",
        "Prey",
        "Strangy",
        "Garfield",
    ]:
        k = Kitten(name, u1.id)
        db.session.add(k)

    db.session.commit()
Example #15
0
 def setUp(self):
     db.session.close()
     db.drop_all()
     db.create_all()
     self.app = app.test_client()
     if not os.path.exists("users/"):
         os.makedirs("users/")
Example #16
0
 def tearDown(self):
     # 在所有测试函数运行后运行,收尾的函数
     db.session.remove()
     # 删除会话
     db.drop_all()
     # 删除所有的表
     self.app_context.pop()
Example #17
0
 def setUp(self):
     _app = create_app("config.TestConfig")
     ctx = _app.test_request_context()
     ctx.push()
     db.session.commit()
     db.drop_all()
     db.create_all()
Example #18
0
 def recreate_schema(test_class):
     # print 'Re-creating db schema for environmet %s'%flapp.config['REDIS_PREFIX']
     db.session.remove()
     db.drop_all()
     db.create_all()
     # setup_func(test_class)
     return setup_func
Example #19
0
def db(app, request):
    _db.app = app
    _db.create_all()

    yield _db

    _db.drop_all()
Example #20
0
def populate():
    db.drop_all()
    db.create_all()

    user = User(username="test_username", password="test_password")

    db.session.add(user)
Example #21
0
 def teardown():
     _db.session.rollback()
     _db.session.remove()
     if _db.engine.dialect.name == "postgresql":
         _db.engine.execute("drop schema if exists public cascade")
         _db.engine.execute("create schema public")
     _db.drop_all()
    def tearDownClass(cls):
        if cls.client:
            cls.client.close()

            db.drop_all()
            db.session.remove()

            cls.app_context.pop()
Example #23
0
def recreate_db():
    """
    Recreates a local database. You probably should not use this on
    production.
    """
    db.drop_all()
    db.create_all()
    db.session.commit()
Example #24
0
 def setUp(self):
     self.app = create_app("testing")
     self.app_ctx = self.app.app_context()
     self.app_ctx.push()
     self.client = self.app.test_client()
     db.drop_all()
     db.create_all()
     Role.seed()
Example #25
0
def initdb():
    """initialize database"""
    db.drop_all()
    db.create_all()

    admin = User(email=u"elarellano@gmail.com", password=u"unconquered", role=1)
    db.session.add(admin)
    db.session.commit()
Example #26
0
    def tearDown(self):
        self.user.delete()
        group = self.get_test_user_group("test_user2@example.com")
        group.delete()

        db.session.remove()
        db.drop_all()
        self.app_context.pop()
Example #27
0
def init_db():
    """Erase database, seed it with mock data."""
    db.drop_all()
    db.create_all()
    seed_companies()
    seed_emission_reports()
    seed_reduction_targets()
    seed_milestones()
Example #28
0
    def setUp(self):
        """Before each test, set up a blank database"""
        app.config["TESTING"] = True
        self.app = app.test_client()

        # Drop the database
        db.drop_all()
        db.create_all()
Example #29
0
    def setUp(self):
        # app.config.from_object('testing_configuration') # put in a testing configuration
        db.session.close()
        db.drop_all()
        db.create_all()

        # do subclass setup
        self.setup()
Example #30
0
    def tearDownClass(cls):
        if cls.client:
            cls.client.get("http://localhost:5000/shutdown")
            cls.client.close()

            db.drop_all()
            db.session.remove()

            cls.app_context.pop()