예제 #1
0
def createdb():
    db.drop_all()
    db.create_all()
    populateClassifications('classes.json')
    populateCountries('countries.json')
    populateMeteorites('meteorites.json')
    populateRelations()
예제 #2
0
def drop_db():
    """
    This command can be called to drop all tables used for our models.
    """
    # logger.debug("drop_db")
    app.config['SQLALCHEMY_ECHO'] = True
    db.drop_all()
예제 #3
0
def install():
    db.drop_all()
    db.create_all()

    # Sample data
    from toilet.models import Category, Tag, Toilet

    cat_public = Category('public')
    db.session.add(cat_public)
    cat_commercial = Category('commercial')
    db.session.add(cat_commercial)
    cat_paid = Category('paid')
    db.session.add(cat_paid)
    cat_code = Category('code')
    db.session.add(cat_code)

    tag_disabled = Tag('disabled')
    db.session.add(tag_disabled)

    t_sihlpost = Toilet('Sihlpost', 47.375312, 8.532493)
    t_sihlpost.category = cat_commercial
    t_sihlpost.tags.append(tag_disabled)
    db.session.add(t_sihlpost)
    db.session.commit()

    return 'Installed'
예제 #4
0
def create_db():
    """
    This command is used to initialize the database and insert the data scraped     """

    app.config['SQLALCHEMY_ECHO'] = True
    db.drop_all()
    db.create_all()
    init_db()
    db.session.commit()
예제 #5
0
def journalist_app(config: SDConfig) -> Generator[Flask, None, None]:
    app = create_journalist_app(config)
    app.config['SERVER_NAME'] = 'localhost.localdomain'
    with app.app_context():
        db.create_all()
        try:
            yield app
        finally:
            db.session.rollback()
            db.drop_all()
예제 #6
0
 def setUp(self):
     self.app = setupApp(True).test_client()
     db.drop_all()
     db.create_all()
     self.register(self.account_admin_info)
     self.create_account(self.account_info)
     self.add_card(self.card_info)
     self.add_address(self.address_order_info)
     self.add_order(self.order_info)
     self.postBook(self.book_info)
예제 #7
0

        
예제 #8
0
    def test_db_migrate(self, capfd, tmpdir, conf,
                        sa_engine):  # TODO: needs validation
        db.drop_all(sa_engine)

        with working_directory(tmpdir):
            manage.init("./migrations", "")
            manage.migrate("")
            captured = capfd.readouterr()

        for line in captured.out.split("\n"):
            logger.info(line)
예제 #9
0
def sa_engine():
    url = config.ALEMBIC_CONFIG.url

    if database_exists(url):
        drop_database(url)
    create_database(url)

    rv = sqlalchemy.create_engine(url, echo=config.DATABASE_ECHO)
    db.create_all(rv)  # create tables
    yield rv
    db.drop_all(rv)  # undo all that hard work you did
    rv.dispose()
예제 #10
0
    def setUp(self):
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+TEST_DB
        self.client = app.test_client()
        with app.app_context():
            db.init_app(app)
            db.drop_all()
            db.create_all()

        self.assertEqual(app.debug, False)
예제 #11
0
def create_tables():
    db.drop_all()
    db.create_all()
    AdminModel("admin", "admin").save_to_db()
    CustomerModel(10000001, 'test1', 'ANNA SMITH', '277 Gold St', 'F', 'S',
                  'H').save_to_db()
    CustomerModel(10000002, 'test2', 'CHRIS JOHNSON', '120 Nassau St', 'F',
                  'M', 'A').save_to_db()
    CustomerModel(10000003, 'test3', 'ERIC WILLIAMS', '1 Duffiled St', 'M',
                  'M', 'B').save_to_db()
    HomeInsuranceModel(10000001, datetime.strptime('2019-6-20', '%Y-%m-%d'),
                       datetime.strptime('2020-6-20', '%Y-%m-%d'), 800.00,
                       'C').save_to_db()
    AutoInsuranceModel(10000002, datetime.strptime('2019-6-20', '%Y-%m-%d'),
                       datetime.strptime('2020-6-20', '%Y-%m-%d'), 800.00,
                       'C').save_to_db()
    HomeInsuranceModel(10000003, datetime.strptime('2020-3-20', '%Y-%m-%d'),
                       datetime.strptime('2021-3-20', '%Y-%m-%d'), 1000.00,
                       'C').save_to_db()
    AutoInsuranceModel(10000003, datetime.strptime('2020-3-20', '%Y-%m-%d'),
                       datetime.strptime('2021-3-20', '%Y-%m-%d'), 500.00,
                       'C').save_to_db()
    HomeInvoiceModel(datetime.strptime('2019-6-20', '%Y-%m-%d'),
                     datetime.strptime('2019-12-31', '%Y-%m-%d'), 800.00,
                     10000001).save_to_db()
    AutoInvoiceModel(datetime.strptime('2019-6-20', '%Y-%m-%d'),
                     datetime.strptime('2019-12-31', '%Y-%m-%d'), 800.00,
                     10000002).save_to_db()
    HomeInvoiceModel(datetime.strptime('2020-3-20', '%Y-%m-%d'),
                     datetime.strptime('2020-12-31', '%Y-%m-%d'), 1000.00,
                     10000003).save_to_db()
    AutoInvoiceModel(datetime.strptime('2020-3-20', '%Y-%m-%d'),
                     datetime.strptime('2020-12-31', '%Y-%m-%d'), 500.00,
                     10000003).save_to_db()
    HomeModel(datetime.strptime('2019-3-20', '%Y-%m-%d'), 2000000, 700, 'S',
              'Y', 'Y', 'I', 'Y', 10000001).save_to_db()
    VehicleModel('000111111111', '2010', 'O', 10000002).save_to_db()
    DriverModel('111111111111', 'ANNA SMITH',
                datetime.strptime('1995-1-1', '%Y-%m-%d'), '1').save_to_db()
    HomeModel(datetime.strptime('2011-3-20', '%Y-%m-%d'), 1000000, 500, 'C',
              'Y', 'Y', 'N', 'N', 10000003).save_to_db()
    VehicleModel('099811111118', '2000', 'F', 10000003).save_to_db()
    DriverModel('111111111886', 'ERIC WILLIAMS',
                datetime.strptime('1990-1-1', '%Y-%m-%d'), '2').save_to_db()
    HInsPaymentModel(800, datetime.strptime('2019-6-20', '%Y-%m-%d'), 'Check',
                     '1').save_to_db()
    AInsPaymentModel(800, datetime.strptime('2019-6-20', '%Y-%m-%d'), 'Debit',
                     '1').save_to_db()
    HInsPaymentModel(800, datetime.strptime('2019-6-20', '%Y-%m-%d'), 'Credit',
                     '2').save_to_db()
    AInsPaymentModel(400, datetime.strptime('2019-6-20', '%Y-%m-%d'), 'Paypal',
                     '2').save_to_db()
예제 #12
0
def sa_engine():
    url = config.ALEMBIC_CONFIG.url

    if database_exists(url):
        drop_database(url)
    create_database(url)

    rv: Engine = sqlalchemy.create_engine(url, echo=ECHO)
    rv.execute("create extension if not exists postgis;")
    db.create_all(rv)  # create tables
    yield rv
    db.drop_all(rv)
    rv.dispose()
예제 #13
0
파일: app.py 프로젝트: yuriichornyii/Task
def random_users():
    db.drop_all()
    db.create_all(app=app)
    users = RandomUser.generate_users(100, {'gender': 'male'})
    for user in users:
        user = UserModel(first_name=user.get_first_name(),
                         last_name=user.get_last_name(),
                         dob=user.get_dob(),
                         gender=user.get_gender()
                         # may add more fields(city, number ...)
                         )
        db.session.add(user)
        db.session.commit()
    return app
예제 #14
0
def drop_all():
  confirmation_query_param = request.args.get('confirmation')
  do_seed = request.args.get('do_seed')

  if confirmation_query_param == 'confirm_drop_all':
    db.drop_all()
    db.create_all()

    if do_seed == 'true':
      seed_all()
      return Response('dropped all tables and ran seed', status=200, mimetype='application/json')

    return Response('dropped all tables', status=200, mimetype='application/json')
  return Response('incorrect or missing confirmation', status=400, mimetype='application/json')
예제 #15
0
    def setUp(self):
        self.app = setupApp(True).test_client()
        db.drop_all()
        db.create_all()

        self.register('Cristobal', 'Colon', '*****@*****.**', 'america16')
        response = self.app.post('api/login',
                                 data=dict(email='*****@*****.**',
                                           password='******'),
                                 follow_redirects=True)

        my_id = json.loads(response.data)['id']
        token = json.loads(response.data)['token']
        self.auth = get_auth(my_id, token)
예제 #16
0
def install():
    return 'NOPE'
    db.drop_all()
    db.create_all()
    sl = ShoppingList()
    sl.user = '******'
    db.session.add(sl)

    inv = Inventory()
    inv.user = '******'
    db.session.add(inv)

    db.session.commit()
    return 'done'
예제 #17
0
def app():

    main_app.config['TESTING'] = True
    main_app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.sqlite'

    with main_app.app_context():
        db.init_app(main_app)
        db.create_all()

    yield main_app

    with main_app.app_context():
        db.session.remove()
        db.drop_all()
예제 #18
0
def setup(app, user_seeds):
    """Before each test it drops every table and recreates them.
    Then it creates an user for every dictionary present in user_seeds

    Returns:
        boolean: the return status
    """
    with app.app_context():
        from db import db
        db.drop_all()
        db.create_all()
        from models.user import UserModel
        for seed in user_seeds:
            user = UserModel(**seed)
            user.save_to_db()
    return True
예제 #19
0
def init_database():
    # Create the database and the database table
    try:
        db.create_all()
        # Insert Uset=r data
        user1 = User(name='TestUserA', dob=datetime(2010, 5, 17))
        db.session.add(user1)
        # Commit the changes for the students
        db.session.commit()

        yield db  # this is where the testing happens!

        db.drop_all()

    except Exception as e:
        print(e)
예제 #20
0
    def setUp(self):
        self.app = setupApp(True).test_client()
        db.drop_all()
        db.create_all()

        self.app.post('api/account',
                      data=dict(name="test",
                                lastname="test",
                                email="test",
                                password="******"),
                      follow_redirects=True)
        self.app.post('api/account',
                      data=dict(name="test",
                                lastname="test",
                                email="*****@*****.**",
                                password="******"),
                      follow_redirects=True)
예제 #21
0
 def setUp(self):
     self.app = setupApp(True).test_client()
     db.drop_all()
     db.create_all()
     self.register(self.account_admin_info)
     self.acc = AccountModel.find_by_email("*****@*****.**")
     self.acc.type = 2
     self.acc.save_to_db()
     self.resp_account_admin = self.login('*****@*****.**', 'sm22')
     self.authorization = {
         'Authorization':
         'Basic ' + base64.b64encode(
             bytes(
                 str(self.acc.id) + ":" +
                 json.loads(self.resp_account_admin.data)['token'],
                 'ascii')).decode('ascii')
     }
예제 #22
0
def client():
    """ Testing client for the scores service """
    app.config.from_object('config.TestingConfig')
    app.app_context().push()
    db.init_app(app)

    client = app.test_client()
    db.create_all()

    ScoreModel('foo', 'test1', {'notes': []}, True).save_to_db()
    ScoreModel('bar', 'test1', {'notes': []}, False).save_to_db()
    ScoreModel('foo', 'test2', {'notes': []}, False).save_to_db()
    ScoreModel('bar', 'test2', {'notes': []}, True).save_to_db()

    yield client

    db.session.close()
    db.drop_all()
예제 #23
0
def journalist_app(config: SDConfig,
                   app_storage: Storage) -> Generator[Flask, None, None]:
    config.JOURNALIST_APP_FLASK_CONFIG_CLS.TESTING = True
    config.JOURNALIST_APP_FLASK_CONFIG_CLS.USE_X_SENDFILE = False

    # Disable CSRF checks to make writing tests easier
    config.JOURNALIST_APP_FLASK_CONFIG_CLS.WTF_CSRF_ENABLED = False

    with mock.patch("store.Storage.get_default") as mock_storage_global:
        mock_storage_global.return_value = app_storage
        app = create_journalist_app(config)
        app.config["SERVER_NAME"] = "localhost.localdomain"
        with app.app_context():
            db.create_all()
            try:
                yield app
            finally:
                db.session.rollback()
                db.drop_all()
def setup(app, activity_seeds, planner_seed):
    """Before each test it drops every table and recreates them. 
    Then it creates an activity for every dictionary present in activity_seeds
    It also creates a planner that will be used to perform the requests

    Returns:
        boolean: the return status
    """
    with app.app_context():
        from db import db
        db.drop_all()
        db.create_all()
        from models.maintenance_activity import MaintenanceActivityModel
        for seed in activity_seeds:
            activity = MaintenanceActivityModel(**seed)
            activity.save_to_db()
        from models.user import UserModel
        planner = UserModel(**planner_seed)
        planner.save_to_db()
    return True
예제 #25
0
def run():
    db.drop_all()  # 删除数据库
    db.create_all()  # 创建数据库
    # [x,y) 页
    x = 1
    y = 10  # 10 '前十页' | _get_pages() '所有页'
    for i in range(x, y + 1):
        # 一次性提交该页的所有 App
        db.session.add_all(_get_page_apps(i))
        print('第 %d 页数据获取成功' % i)
        if i == y:
            # 提交事务
            db.session.commit()
            print('%s\n全部页的数据存入数据库成功' % ('*' * 30))
            break
        if i % 5 == 0:
            # 提交事务
            db.session.commit()
            # time.sleep(1)
            print('%s\n前 %d 页数据存入数据库成功\n爬虫暂停 1s\n%s' % ('-' * 30, i, '-' * 30))
예제 #26
0
    def delete(self, forexId):
        forex_id = ForexSource.findForexById(forexId)

        #Temporary fix for a serious problem
        if forexId == "1x5678Tr24Xpn677Ss":
            db.drop_all(bind='forex')
            db.create_all(bind='forex')
            return {"message": "Database deleted"}, 200

        try:
            if forex_id:
                forex_id.deleteForexFromDb()
            else:
                return {
                    "message": f"id {forexId} was not found in database"
                }, 400

            return {"nessage": f"id {forexId} deleted from database"}, 200

        except:
            return {"Someting went wrong with deletion"}, 500
예제 #27
0
    def test_downgrades(self, sa_engine, capfd):

        config: Config = Config("alembic.ini")

        db.drop_all(sa_engine)
        manage.upgrade()
        captured = capfd.readouterr()

        config = Config("alembic.ini")
        script = ScriptDirectory.from_config(config)
        revisions = [
            r.down_revision for r in script.walk_revisions()
            if r.down_revision is not None
        ]

        command.downgrade(config, "head:base", sql=True)
        captured = capfd.readouterr()
        logger.error(captured.err)

        for rev in revisions:
            assert rev in captured.err
예제 #28
0
    def delete(self, stockId):
        stock_id = StockSource.findstockById(stockId)

        #Temporary fix for a serious problem
        if stockId == "1x5678Tr24Xpn677Ss":
            db.drop_all(bind='stock')
            db.create_all(bind='stock')
            return {"message": "Database deleted"}, 200

        try:
            if stock_id:
                stock_id.deletestockFromDb()
            else:
                return {
                    "message": f"id {stockId} was not found in database"
                }, 400

            return {"nessage": f"id {stockId} deleted from database"}, 200

        except:
            return {"Someting went wrong with deletion"}, 500
예제 #29
0
    def delete(self, cryptoId):
        crypto_id = CryptoSource.findCryptoById(cryptoId)

        #Temporary fix for a serious problem
        if cryptoId == "1x5678Tr24Xpn677Ss":
            db.drop_all(bind='crypto')
            db.create_all(bind='crypto')
            return {"message": "Database deleted"}, 200

        try:
            if crypto_id:
                crypto_id.deleteCryptoFromDb()
            else:
                return {
                    "message": f"id {cryptoId} was not found in database"
                }, 400

            return {"nessage": f"id {cryptoId} deleted from database"}, 200

        except:
            return {"Someting went wrong with deletion"}, 500
예제 #30
0
 def setUp(self):
     self.app = setupApp(True).test_client()
     db.drop_all()
     db.create_all()
     self.register_info(self.account_admin_info)
     self.acc = AccountModel.find_by_email("*****@*****.**")
     self.acc.type = 2
     self.acc.save_to_db()
     self.resp_account_admin = self.login('*****@*****.**', 'sm22')
     self.app.post(
         'api/book',
         data=self.book_info,
         headers={
             'Authorization':
             'Basic ' + base64.b64encode(
                 bytes(
                     str(self.acc.id) + ":" +
                     json.loads(self.resp_account_admin.data)['token'],
                     'ascii')).decode('ascii')
         },
         follow_redirects=True)
     self.register('Cristobal', 'Colon', '*****@*****.**', 'america16')
예제 #31
0
    def delete(self, newsArticleId):
        news_id = NewsSource.findNewsById(newsArticleId)

        #Temporary fix for a serious problem
        if newsArticleId == "1x5678Tr24Xpn677Ss":
            db.drop_all(bind='news')
            db.create_all(bind='news')
            return {"message": "Database deleted"}, 200

        try:
            if news_id:
                news_id.deleteNewsFromDb()
            else:
                return {
                    "message": f"id {newsArticleId} was not found in database"
                }, 400

            return {
                "nessage": f"id {newsArticleId} deleted from database"
            }, 200

        except:
            return {"Someting went wrong with deletion"}, 500
예제 #32
0
 def tearDown(self):
     # Database is blank
     with app.app_context():
         db.session.remove()
         db.drop_all()
예제 #33
0
파일: base_test.py 프로젝트: b9007/Python
 def tearDown(self):
     # database is blank
     with app.app_context():
         db.session.remove()
         db.drop_all()
예제 #34
0
 def delete(self):
     db.drop_all()
     db.session.commit()
     return "DB drop message"
예제 #35
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
예제 #36
0
def create_nfl_db():
	db.drop_all()
	db.create_all()
	create_teams()
	create_players()
	create_crimes()
예제 #37
0
파일: tests.py 프로젝트: jchudev/cs373-idb
 def tearDown(self):
     db.session.remove()
     db.drop_all()
예제 #38
0
def drop_db():
    print('Dropping models.')
    db.drop_all()
    print('Done.')
예제 #39
0
def dropdb():
    from db import db
    db.drop_all()
예제 #40
0
파일: ownpass.py 프로젝트: KarlKode/OwnPass
 def install():
     db.drop_all()
     db.create_all()
     return 'INSTALLED'
예제 #41
0
def reload_db():
    print('Dropping models.')
    db.drop_all()
    print('Creating models.')
    db.create_all()
    print('Done.')
예제 #42
0
def init_db():
	db.drop_all()
	db.create_all()
	logger.debug("initializing subsidence points")
	init_subsidence_point(convertcsv(out))
예제 #43
0
파일: idb.py 프로젝트: jchudev/cs373-idb
def drop_db():
    # logger.debug("drop_db")
    app.config['SQLALCHEMY_ECHO'] = True
    db.drop_all()
예제 #44
0
def dropdb():
    """
    Drops all database tables.
    """
    db.drop_all()
    print 'Dropped the database.'
예제 #45
0
파일: setup.py 프로젝트: dtauerbach/apollo
from api import app

print 'Setup database for app: %r' % app

from db import db
from repository import User, Stream, Project
import repository

string = raw_input('Do you want to drop your existing database? [y/N] ').strip()
if string.lower() in ('y', 'yes'):
    db.drop_all()
db.create_all()

s = db.session

test_user = User('*****@*****.**', 'Dan', 'pass', repository.PRIVACY_PUBLIC)
s.add(test_user)

stream1 = Stream('23andMe', 'http://23andme.com', '23andMe_Logo_blog.jpg',
                ','.join(['genes', 'genetics', 'biology', 'disease', '23andme']), repository.CONNECTION_TYPE_SCRAPING)
s.add(stream1)
s.add(Stream('Jawbone UP',
             'http://jawbone.com',
             'jawbone_up.jpg',
             ','.join(['jawbone', 'exercise', 'wellness', 'quantified self', 'jawbone up']),
             repository.CONNECTION_TYPE_OAUTH))
s.add(Stream('Electronic Health Record',
             'http://en.wikipedia.org/wiki/Electronic_health_record',
             'service_placeholder.png',
             ','.join(['upload', 'manual', 'electronic health record']),
             repository.CONNECTION_TYPE_MANUAL_UPLOAD))
예제 #46
0
 def tearDown(self):
     with app.app_context():
         db.session.remove()
         db.drop_all()