예제 #1
0
 def setUp(self) -> None:
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     Role.insert_roles()
     self.client = self.app.test_client(use_cookies=True)
예제 #2
0
def create_db():
    """
    Recreates a local database. You probably should not use this on
    production.
    """
    db.create_all()
    db.session.commit()
예제 #3
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     Role.insert_roles()
     self.client = self.app.test_client()
예제 #4
0
def resetDatabase():
    """Reset database for testing purpose"""
    db.drop_all()
    db.create_all()

    user_password_encrypted = sha256_crypt.hash('user')
    admin_password_encrypted = sha256_crypt.hash('admin')

    user = Users('user', '*****@*****.**', '081122112211',
                 user_password_encrypted, False)
    admin = Users('admin', '*****@*****.**', '0811221122112',
                  admin_password_encrypted, True)
    trash_category = ListTrashCategory(2, 'dummy_category')
    trash_one = {
        "trash_category_id": 1,
        "admin_id": 2,
        "trash_name": "dummy_trash",
        "price": 1000,
        "photo": "dummy_photo",
        "point": 1
    }
    trash_two = {
        "trash_category_id": 1,
        "admin_id": 2,
        "trash_name": "dummy_trash",
        "price": 2000,
        "photo": "dummy_photo",
        "point": 2
    }
    trash_instance_one = ListTrash(trash_one)
    trash_instance_two = ListTrash(trash_two)

    reward = Rewards(2, "reward dummy", 20, "photo", 20, True)
    reward1 = Rewards(2, "reward dummy", 20, "photo", 20, True)
    reward2 = Rewards(2, "reward dummy", 20, "photo", 20, True)
    order = ListOrders({
        'user_id': 1,
        'adress': "dummy",
        'time': datetime.datetime.utcnow(),
        'photo': 'url',
        'status': 'waiting'
    })

    db.session.add(user)
    db.session.add(admin)
    db.session.add(trash_category)
    db.session.add(trash_instance_one)
    db.session.add(trash_instance_two)
    db.session.add(reward)
    db.session.add(reward1)
    db.session.add(reward2)
    db.session.add(order)
    db.session.commit()

    user_attr = UserAttributes(1, 0, 0, False)
    admin_attr = UserAttributes(2, 0, 0, False)
    db.session.add(user_attr)
    db.session.add(admin_attr)
    db.session.commit()
예제 #5
0
def client():
    from apps import create_app, db
    flask_app = create_app('testing')

    testing_client = flask_app.test_client()

    with flask_app.app_context():
        db.create_all()
        yield testing_client
        db.drop_all()
예제 #6
0
 def setUp(self):
     """function to setup app variables"""
     config_name = config.TestingConfig
     app.config.from_object(config_name)
     self.app = app
     self.test_client = self.app.test_client()
     self.app_context = self.app.app_context()
     self.app_context.push()
     self.name = 'test user'
     self.email = '*****@*****.**'
     self.test_username = '******'
     self.test_password = '******'
     with self.app_context:
         db.create_all()
예제 #7
0
    def setUpClass(cls):
        # start Firefox
        try:
            cls.client = webdriver.Firefox()
        except:
            pass

        # skip these tests if the browser could not be started
        if cls.client:
            # create the application
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            # suppress logging to keep unittest output clean
            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel("ERROR")

            # create the database and populate with some fake data
            db.create_all()
            Role.insert_roles()
            User.generate_fake(10)
            Post.generate_fake(10)

            # add an administrator user
            admin_role = Role.query.filter_by(permissions=0xff).first()
            admin = User(email='*****@*****.**',
                         username='******',
                         password='******',
                         role=admin_role,
                         confirmed=True)
            db.session.add(admin)
            db.session.commit()

            # start the Flask server in a thread
            threading.Thread(target=cls.app.run).start()

            # give the server a second to ensure it is up
            time.sleep(1)
예제 #8
0
 def setUp(self):
     db.create_all()
     db.session.commit()
     tc_sms.send_sms = self.hook_sender
     tc_oss.upload_image = self.hook_upload_image
예제 #9
0
class ArticleComment(db.Model):
    __tablename__ = 'article_comment'
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    article_id = db.Column(db.Integer, db.ForeignKey('article.id'))
    comment = db.Column(db.TEXT)
    addtime = db.Column(db.DATETIME, index=True, default=datetime.now)

    def __repr__(self):
        return '<ArticleComment %r>' % self.id


if __name__ == "__main__":
    db.drop_all()
    db.create_all()
    flag = 1
    if flag == 0:
        db.drop_all()
        db.create_all()
    if flag == 1:
        tag0 = AlbumTag(name='风景')
        tag1 = AlbumTag(name='动漫')
        tag2 = AlbumTag(name='星空')
        tag3 = AlbumTag(name='萌宠')
        tag4 = AlbumTag(name='静物')
        tag5 = AlbumTag(name='汽车')
        tag6 = AlbumTag(name='海洋')
        tag7 = AlbumTag(name='美女')
        tag8 = AlbumTag(name='城市')
        tag9 = AlbumTag(name='飞鸟')
예제 #10
0
 def setUp(self):
     self.app = app.test_client()
     self.app.testing = True
     db.drop_all()
     db.create_all()
예제 #11
0
def create_db():
    db.create_all()
예제 #12
0
파일: manage.py 프로젝트: timechild/arke
def run():
    db.create_all()
    app.config.from_object('config.Config')
    app.run(host=app.config['SERVER_IP'], port=app.config['PORT'])
예제 #13
0
def create_all():
    """Creates database tables"""
    db.create_all()
예제 #14
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
예제 #15
0
def load_cmd(aUseRandomValues=None):

    if aUseRandomValues:
        print(' >>> Randomize Values ')
    else:
        print(' >>> Use Values from input file ')

    # Create Tables (if not exist)
    db.create_all()

    # Truncate
    db.session.query(Data).delete()
    db.session.commit()

    with open('media/transactions_data.csv', newline='') as csvfile:

        csvreader = csv.reader(csvfile)  # load file
        header = next(csvreader)  # ignore header (1st line)
        '''
        Expected format: 
            HEADER: product_code,product_info,value,currency,type
            SAMPLE: Lenovo_Ideapad_3i, Lenovo Ideapad 3i 14.0inch FHD Laptop,9.5,euro,transaction
            
            product_code (string)  : Lenovo_Ideapad_3i
            product_info (string)  : Lenovo Ideapad 3i 14.0inch FHD Laptop
            value        (integer) : 9 
            currency     (string)  : usd, eur 
            type         (string)  : transaction (hardoded)
        '''

        iter = 0  # used for timestamp
        for row in csvreader:

            iter += 1

            if len(row) != 5:
                print(' >>> Error parsing line (' + str(iter) + ') -> ' +
                      ' '.join([str(elem) for elem in row]))
                continue

            item_code = row[0]
            item_name = row[1]

            if aUseRandomValues:
                item_value = randint(5, 100)
            else:
                item_value = row[2]

            item_currency = row[3]
            item_type = row[4]

            # randomize in the past the transaction date
            # The distribuition range ~1 month
            item_ts = datetime.utcnow().timestamp() - (2 * iter *
                                                       randint(5, 10) * 3600)
            item_ts = int(item_ts)

            _data = Data(code=item_code,
                         name=item_name,
                         value=item_value,
                         currency=item_currency,
                         type=item_type,
                         ts=item_ts)

            db.session.add(_data)

        db.session.commit()
예제 #16
0
def initdb():
    '''Creates all database tables.'''
    db.create_all()
예제 #17
0
def init_db():
    db.create_all()
예제 #18
0
def create_all():
    """Creates database tables"""
    db.create_all()
예제 #19
0
def main():
    db.create_all()
    load_admin()

    if len(sys.argv) == 2:
        load_file_in_db(sys.argv[1])
예제 #20
0
 def setUpClass(cls):
     cls.app = createApp()
     cls.app_context = cls.app.app_context()
     cls.app_context.push()
     cls.client = cls.app.test_client()
     db.create_all()
예제 #21
0
def syncdb():
    with app.test_request_context():
        from apps.users.models import User
        db.create_all()
예제 #22
0
#!flask/bin/python
from migrate.versioning import api
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
from apps import db
import os.path
db.create_all()
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
    api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
    api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
else:
    api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))
예제 #23
0
파일: manage.py 프로젝트: savad/monitor
def syncdb():
    with app.test_request_context():
        from apps.users.models import User
        db.create_all()