def setUpClass(cls):
        db.drop_all()
        db.session.remove()
        try:
            cls.client = webdriver.Firefox()
        except:
            pass

        if cls.client:
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel("ERROR")

            db.create_all()
            Role.insert_roles()
            fake.users(10)

            admin_role = Role.query.filter_by(permissions=0xff).first()
            admin_user = User(email='*****@*****.**', username='******',
                              password='******', role=admin_role)
            db.session.add(admin_user)
            db.session.commit()

            cls.server_thread = threading.Thread(target=cls.app.run)
            cls.server_thread.start()
            time.sleep(1)
Example #2
0
    def setUpClass(cls):
        options = webdriver.ChromeOptions()
        options.add_argument('headless')
        try:
            cls.client = webdriver.Chrome(chrome_options=options)
        except:
            pass

        if cls.client:
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            import logging

            logger = logging.getLogger('werkzeug')
            logger.setLevel("ERROR")

            db.create_all()
            Role.insert_roles()
            fake.users(10)
            fake.posts(10)

            admin_role = Role.query.filter_by(name='Administrator').first()
            admin = User(email='*****@*****.**', username='******', password='******', role=admin_role, confirmed=True)
            db.session.add(admin)
            db.session.commit()

            cls.server_thread = threading.Thread(target=cls.app.run, kwargs={'debug': False})
            cls.server_thread.start()
            time.sleep(1)
Example #3
0
    def create_users(count):
        """
		Create fake users.
		int:param How many users should be created..
		"""
        with app.app_context():
            users(count)
Example #4
0
    def setUpClass(cls):
        try:
            cls.client = webdriver.Chrome()
        except:
            pass

        if cls.client:
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel("ERROR")

            db.create_all()
            Role.insert_roles()
            fake.users(10)
            fake.posts(10)

            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()

            threading.Thread(target=cls.app.run).start()
    def setUpClass(cls):
        # start Chrome
        options = Options()
        #options = webdriver.ChromeOptions()
        options.headless = True
        #options.log.level = "trace"
        options.add_argument('--headless')
        options.add_argument('--no-proxy-server')
        options.add_argument("--proxy-server='direct://'")
        options.add_argument("--proxy-bypass-list=*")
        #options.set_windows_size(1440, 900)
        try:
            cls.client = webdriver.Chrome(
                r'C:\Users\benha\Documents\Development\chromedriver\chromedriver.exe',
                chrome_options=options)
        except:
            cls.client = webdriver.Chrome(
                r'C:\local-work\GitHub\flask-book-sample-app\flasky\utilities\chromedriver78\chromedriver.exe',
                chrome_options=options)
        finally:
            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()
            fake.users(10)
            fake.posts(10)

            # add an administrator user
            admin_role = Role.query.filter_by(name='Administrator').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
            cls.server_thread = threading.Thread(target=cls.app.run,
                                                 kwargs={'debug': False})
            cls.server_thread.start()

            # give the server a second to ensure it is up
            time.sleep(1)
Example #6
0
def deploy():
    db.drop_all()
    db.create_all()
    Role.insert_roles()
    Town.insert_towns()
    users()
    orders()
    goods()
    reports()
Example #7
0
    def setUpClass(cls):
        # 开启 火狐浏览器 无界面模式 关闭显卡加速
        options = webdriver.FirefoxOptions()
        options.add_argument('--headless')
        options.add_argument('--disable-gpu')
        try:
            # 如果在win10环境下,根据路径找到软件
            if os.name == 'nt':
                cls.client = webdriver.Firefox(
                    executable_path=
                    r'D:\Program Files\geckodriver\geckodriver.exe',
                    firefox_options=options)
            else:
                cls.client = webdriver.Firefox(firefox_options=options)
        except Exception as e:
            print(e)
            pass

        # 如果无法启动浏览器,跳过这些测试
        if cls.client:
            # 创建程序
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            # 禁止日志,保持输出的清洁
            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel('ERROR')

            # 创建数据库,并使用一些虚拟数据填充
            db.create_all()
            Role.update_roles()
            fake.users(30)
            fake.posts(30)

            # 添加管理员
            admin_role = Role.query.filter_by(
                role_name='Administrator').first()
            admin = User(email='*****@*****.**',
                         username='******',
                         password='******',
                         role=admin_role,
                         confirmed=True)
            db.session.add(admin)
            db.session.commit()

            # 在一个线程中启动flask服务器
            cls.server_thread = threading.Thread(target=cls.app.run,
                                                 kwargs={'debug': False})
            cls.server_thread.start()
            # 睡一秒,确保服务器已经开启
            time.sleep(1)
Example #8
0
    def setUpClass(cls):
        #打开Chrome
        options = webdriver.ChromeOptions()
        #options.add_argument('headless')
        options.add_argument('--no-sandbox')
        try:
            cls.client = webdriver.Chrome(options=options)
        except:
            pass

        #浏览器不能打开就跳过
        if cls.client:
            #create the application
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            #关闭日志,使输出简洁
            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel('ERROR')

            #数据库输入少量虚拟数据
            db.create_all()
            Role.insert_roles()
            fake.users(10)
            fake.posts(10)

            #添加管理员john(已确认)
            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()

            #添加普通用户ken(已确认)
            user = User(email='*****@*****.**',
                        username='******',
                        password='******',
                        confirmed=True)
            db.session.add(user)
            db.session.commit()

            #另一个线程中启动服务器
            cls.server_thread = threading.Thread(target=cls.app.run,
                                                 kwargs={'debug': False})
            cls.server_thread.start()

            time.sleep(1)
Example #9
0
    def setUpClass(cls):
        #start Chrome
        print('%%%%%%%%%%%% CHROME %%%%%%%%%%%%%%%%%%%')
        options = webdriver.ChromeOptions()
        #options.add_argument('headless')

        try:
            cls.client = webdriver.Chrome()
        except:
            pass

        #skip thse tess if the browser could not be started
        if cls.client:
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

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

            db.create_all()
            Role.insert_roles()
            fake.users(10)
            fake.posts(10)

            admin_role = Role.query.filter_by(permissions=0xff).first()
            admin = User(email='*****@*****.**',
                         username='******',
                         role=admin_role,
                         password='******')
            db.session.add(admin)
            db.session.commit()
            print(admin.id)

            #print('Added USer.............')
            #user = User.query.filter_by(email='*****@*****.**').first()
            #print(user)
            #allobjs = User.query.order_by(User.username).all()
            #for obj in allobjs:
            #    print(obj.email)
            #start the Flask Server in a thread

            cls.server_thread = threading.Thread(target=cls.app.run,
                                                 kwargs={
                                                     'debug': 'true',
                                                     'use_reloader': False,
                                                     'use_debugger': True
                                                 })
            cls.server_thread.start()
Example #10
0
    def setUpClass(cls):
        # 啟動 Firefox
        options = webdriver.FirefoxOptions()
        options.add_argument('-private')
        options.add_argument('-headless')
        try:
            cls.client = webdriver.Firefox(options=options)
        except Exception:
            pass

        # 如果瀏覽器無法啟動,就跳過這些測試
        if cls.client:
            # 建立 app
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            # 禁止紀錄,來讓 unittest 有簡明的輸出
            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel('ERROR')

            # 建立資料庫並填入一些偽造資料
            db.create_all()
            Role.insert_roles()
            fake.users(10)
            fake.posts(10)

            # 加入一位管理員使用者
            admin_role = Role.query.filter_by(permissions=0xfff).first()
            admin = User(
                email='*****@*****.**',
                username='******',
                password='******',
                role=admin_role,
                confirmed=True,
            )
            db.session.add(admin)
            db.session.commit()

            # 在執行緒中啟動 Flask 伺服器
            os.environ['FLASK_RUN_FROM_CLI'] = 'false'
            cls.server_thread = threading.Thread(
                target=cls.app.run,
                kwargs={
                    'debug': 'false',
                    'use_reloader': False,
                    'use_debugger': False,
                },
            )
            cls.server_thread.start()
Example #11
0
    def setUpClass(cls):
        # start Chrome
        options = webdriver.ChromeOptions()
        options.add_argument('headless')
        try:
            cls.client = webdriver.Chrome(chrome_options=options)
        except:
            pass

        # skip test if 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 db and fill fake data
            db.create_all()
            Role.insert_roles()
            fake.users(10)
            fake.posts(10)

            # add admin user
            admin_role = Role.query.filter_by(name='Administrator').first()
            admin = User(email='*****@*****.**',
                         username='******',
                         password='******',
                         role=admin_role,
                         confirmed=True)
            db.session.add(admin)
            db.session.commit()

            # 在一个线程启动 Flask 服务器
            # threading.Thread(target=cls.app.run).start()

            # flask 1.0 bug 不能自定义 app.run 启动位置
            import os
            os.environ['FLASK_RUN_FROM_CLI'] = "false"  # 让 app.run 运行

            cls.server_thread = threading.Thread(target=cls.app.run,
                                                 kwargs={'debug': False})
            cls.server_thread.start()

            time.sleep(1)
Example #12
0
    def setUpClass(cls):
        # 启动Chrome
        # 不加载图片和CSS,加快测试速度
        prefs = {
            'profile.managed_default_content_settings.images': 2,
            'permissions.default.stylesheet': 2
        }
        options = webdriver.ChromeOptions()
        # options.add_argument('headless')
        options.add_experimental_option('prefs', prefs)
        try:
            cls.client = webdriver.Chrome(options=options)
        except:
            pass

        # 如果无法启动浏览器,跳过这些测试
        if cls.client:
            # 创建应用
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            # 禁止日志,保持输出简洁
            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel("ERROR")

            # 创建数据库,并使用一些虚拟数据填充
            db.create_all()
            Role.insert_rows()
            fake.users(10)
            fake.posts(10)

            # 添加管理员
            admin_role = Role.query.filter_by(name='Administrator').first()
            admin = User(email='*****@*****.**',
                         username='******',
                         password='******',
                         role=admin_role,
                         confirmed=True)
            db.session.add(admin)
            db.session.commit()

            # 在一个线程中启动Flask服务器
            cls.server_thread = threading.Thread(target=cls.app.run,
                                                 kwargs={'debug': False})
            cls.server_thread.start()
            # 确保服务器已完成启动
            time.sleep(2)
Example #13
0
    def setUpClass(cls):
        # 启动 Chrome
        options = webdriver.ChromeOptions()
        options.add_argument('headless')
        try:
            cls.client = webdriver.Chrome(chrome_options=options)
        except:
            pass

        # 如果无法启动浏览器,跳过这些测试
        if cls.client:
            # 创建应用
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            # 禁止日志,保持输出简洁
            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel("ERROR")

            # 创建数据库,并使用一些虚拟数据填充
            db.create_all()
            Role.insert_roles()
            fake.users(10)
            fake.posts(10)

            # 添加管理员
            admin_role = Role.query.filter_by(name='Administrator').first()
            admin = User(email='*****@*****.**',
                         username='******',
                         password='******',
                         role=admin_role,
                         confirmed=True)
            db.session.add(admin)
            db.session.commit()

            # 在一个线程中启动 Flask 服务器
            cls.server_thread = threading.Thread(target=cls.app.run,
                                                 kwargs={
                                                     'debug': 'false',
                                                     'use_reloader': False,
                                                     'use_debugger': False
                                                 })
            cls.server_thread.start()

            # give the server a second to ensure it si up
            time.sleep(1)
Example #14
0
    def setUpClass(cls):
        # start chrome
        options = webdriver.ChromeOptions()
        #options.add_argument('headless')
        # THIS NEEDS TO BE ADDED TO THE SHELL PATH VIA THE FOLLOWING
        # PATH = $PATH:/mnt/c/Users/jheis/documents/flaskwebdevelopment/environments/chromedriver.exe
        uri = '/mnt/c/Users/jheis/documents/flaskwebdevelopment/environments/chromedriver.exe'
        try:
            cls.client = webdriver.Chrome(uri)
        except:
            pass

        # Skip these test if the browser could not be started
        if cls.client:
            # create the application
            cls.app = create_app('testing')
            print (cls.app.config['SQLALCHEMY_DATABASE_URI'])
            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()
            fake.users(10)
            fake.posts(10)

            # add an administrator
            print('you here ho')
            admin_role = Role.query.filter_by(name='administrator').first()
            admin = User(role = admin_role,\
                         email = '*****@*****.**',\
                         password = '******',\
                         confirmed = True,\
                         username = '******')
            db.session.add(admin)
            db.session.commit()

            # start the flask server in the thread
            print('Defining the thread')
            cls.server_thread = Thread(target = cls.app.run,kwargs={'debug':False})
            print('Running the thread')
            if __name__ == "__main__":
                cls.server_thread.start()
Example #15
0
    def setUpClass(cls):
        #start chrome
        options = webdriver.ChromeOptions()
        options.add_experimental_option('excludeSwitches', ['enable-logging'])
        # options.add_argument('headless')
        try:
            cls.client = webdriver.Chrome(
                r"D:\Program Files\Python\Python37-32\chromedriver.exe",
                chrome_options=options)
        except:
            print('client not started')

        #skip these tests if chrome 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()
            fake.users(10)
            fake.posts(10)

            #add in administrator user
            r_admin = Role.query.filter_by(name='Administrator').first()
            u = User(email='*****@*****.**',
                     username='******',
                     password='******',
                     confirmed=True,
                     role=r_admin)
            db.session.add(u)
            db.session.commit()

            #start the flask server in thread
            cls.server_thr = Thread(target=cls.app.run,
                                    kwargs={'debug': False})
            cls.server_thr.start()
            # print('alive?',cls.server_thr.is_alive())

            #give the server a second to ensure it is up
            sleep(2)
Example #16
0
    def setUpClass(cls):
        # start Chrome
        options = webdriver.ChromeOptions()
        # options.add_argument('headless')
        try:
            cls.client = webdriver.Chrome(chrome_options=options)
        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()
            fake.users(10)
            fake.posts(10)

            # add an administrator user
            admin_role = Role.query.filter_by(name="Administrator").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
            cls.server_thread = threading.Thread(target=cls.app.run,
                                                 kwargs={"debug": False})
            cls.server_thread.start()

            # give the server a second to ensure it is up
            time.sleep(1)
Example #17
0
    def setUpClass(cls):
        # start Chrome
        options = webdriver.ChromeOptions()
        options.add_argument('headless')
        try:
            cls.client = webdriver.Chrome(chrome_options=options)
        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()
            fake.users(10)
            fake.posts(10)

            # add an administrator user
            admin_role = Role.query.filter_by(name='Administrator').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
            # cls.server_thread = threading.Thread(target=cls.app.run,
            #                                      kwargs={'debug': False})
            # cls.server_thread.start()
            os.environ["FLASK_APP"] = "sblog.py"
            os.environ["FLASK_CONFIG"] = "testing"
            os.environ["FLASK_ENV"] = "testing"
            os.system("flask run  > /dev/null 2>&1 &")
            # give the server a second to ensure it is up
            time.sleep(3)
Example #18
0
    def setUpClass(cls):
        # start Chrome
        options = webdriver.FirefoxOptions()
        options.add_argument('-headless')
        try:
            cls.client = webdriver.Firefox(
                executable_path=r'D:\firefox_driver\geckodriver',
                options=options)
        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()
            fake.users(10)
            fake.posts(10)

            # add an administrator user
            admin_role = Role.query.filter_by(name='Administrator').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
            cls.server_thread = threading.Thread(target=run_simple,
                                                 args=('127.0.0.1', 5000,
                                                       cls.app))
            cls.server_thread.start()

            # give the server a second to ensure it is up
            time.sleep(1)
    def setUpClass(cls):
        # start Chrome
        options = webdriver.ChromeOptions()
        options.add_argument('headless')
        try:
            cls.client = webdriver.Chrome(chrome_options=options)
        except:
            pass

        # skip these tests if the browser could not be started
        if cls.client:
            # create the app
            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()
            fake.users(10)
            fake.posts(10)

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

            # start Flask server in a thread
            cls.server_thread = threading.Thread(target=cls.app.run,
                                                 kwargs={
                                                     'debug': 'false',
                                                     'use_reloader': False,
                                                     'use_debugger': False
                                                 })

            cls.server_thread.start()
Example #20
0
    def setUpClass(cls):
        # start Chrome
        options = webdriver.ChromeOptions()  # brew install webdriver
        options.add_argument('headless')
        try:
            cls.client = webdriver.Chrome(chrome_options=options)  # 拉取浏览器
        except:
            pass

        # skip these tests if the browser could not be started
        if cls.client:  # 成功启动浏览器插件
            # create the application
            cls.app = create_app('testing')  # 创建 test 环境
            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()  # 初始hua  roles
            fake.users(10)
            fake.posts(10)

            # add an administrator user
            admin_role = Role.query.filter_by(name='Administrator').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
            cls.server_thread = threading.Thread(target=cls.app.run,
                                                 kwargs={'debug': False
                                                         })  # 使用子线程启动 web 服务
            cls.server_thread.start()

            # give the server a second to ensure it is up
            time.sleep(1)  # 休眠一秒,等待web服务启动完毕
Example #21
0
    def setUpClass(cls):
        #启动chrome
        options = webdriver.ChromeOptions()  #无界浏览
        options.add_argument('headless')  #add_argument读入命令行参数
        try:
            cls.client = webdriver.Chrome(options=options)
        except:
            pass

        #如果无法启动浏览器,跳过下列测试
        if cls.client:
            #创建应用
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            #禁止日志,保持输出清洁
            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel("ERROR")  #指定最低的日志级别,低于ERROR的级别将被忽略

            #创建数据库,并使用一些虚拟数据填充
            db.create_all()
            Role.insert_roles()
            fake.users(10)
            fake.posts(10)

            #添加管理员
            admin_role = Role.query.filter_by(name='Administrator').first()
            admin = User(email='*****@*****.**',
                         username='******',
                         password='******',
                         role=admin_role,
                         confirmed=True)
            db.session.add(admin)
            db.session.commit()

            #flask 1.1.1下失效,更改为0.12.2才能运行
            #在一个线程中启动Flask服务器
            cls.server_thread = threading.Thread(target=cls.app.run,
                                                 kwargs={'debug': False})
            cls.server_thread.start()

            #等待1s确保服务器已启动
            time.sleep(1)
Example #22
0
    def setUpClass(cls):
        # inicia o chrome
        options = webdriver.ChromeOptions()
        # options.add_argument('headless')
        try:
            cls.client = webdriver.Chrome(chrome_options=options)
        except:
            pass

        # Ignora testes caso navegador não possa ser inicalizado
        if cls.client:
            # cria app
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel('ERROR')

            db.create_all()
            Role.insert_roles()
            fake.users(10)
            fake.posts(10)

            # Adiciona um usuario adm
            admin_role = Role.query.filter_by(name='Administrator').first()
            admin = User(email='*****@*****.**',
                         username='******',
                         password='******',
                         role=admin_role,
                         confirmed=True)
            db.session.add(admin)
            db.session.commit()

            #Inicia servidor flask thread segundo plano
            cls.server_thread = threading.Thread(target=cls.app.run,
                                                 kwargs={
                                                     'debug': False,
                                                     'use_reloader': False,
                                                     'use_debugger': False
                                                 })

            cls.server_thread.start()
            time.sleep(1)
Example #23
0
 def forge(user, post, follow, comment):
     """create the fake data"""
     from app.fake import admin, users, posts, follows, comments
     click.echo('init db...')
     db.drop_all()
     db.create_all()
     click.echo('init role...')
     Role.insert_rows()
     click.echo('create admin...')
     admin()
     click.echo('create users...')
     users(user)
     click.echo('create posts...')
     posts(post)
     click.echo('create follows...')
     follows(follow)
     click.echo('create comment...')
     comments(comment)
Example #24
0
    def setUpClass(cls):
        # start Chrome
        options = webdriver.ChromeOptions()
        options.add_argument('headless')
        try:
            cls.client = webdriver.Chrome(chrome_options=options)
        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()
            fake.users(10)
            fake.posts(10)

            # add an administrator user
            admin_role = Role.query.filter_by(name='Administrator').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
            cls.server_thread = threading.Thread(target=cls.app.run,
                                                 kwargs={'debug': False})
            cls.server_thread.start()

            # give the server a second to ensure it is up
            time.sleep(1) 
Example #25
0
def easy():

    db.drop_all()
    db.create_all()
    Role.insert_roles()
    u = User(
        confirmed=True,
        email="*****@*****.**",
        username="******",
        password="******",
        profile_picture=
        'https://pbs.twimg.com/profile_images/994988604899328012/Brd4grOw_400x400.jpg'
    )
    db.session.add(u)
    db.session.commit()
    from app import fake
    fake.users(10)
    fake.categories(5)
    fake.topics(20)
    fake.posts(250)
    print("Done")
Example #26
0
    def setUpClass(cls):
        # 启动Chrome
        options = webdriver.ChromeOptions()
        # options.add_argument('headless')    # 用谷歌浏览器的无头模式(没有界面)
        try:
            cls.client = webdriver.Chrome(chrome_options=options)
        except:
            pass  # 如果无法启动浏览器则跳过这些测试

        if cls.client:
            # 创建程序
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            # 禁止日志,保持输出简洁
            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel('ERROR')

            # 创建数据库,并生成一些虚拟数据
            # db.drop_all() # 如果有脏数据,先清空
            # db.session.remove()
            db.create_all()
            Role.insert_roles()
            fake.users(10)
            fake.posts(10)

            # 添加管理员
            admin_role = Role.query.filter_by(name='Administrator').first()
            admin = User(email='*****@*****.**',
                         username='******',
                         password='******',
                         role=admin_role,
                         confirmed=True)
            db.session.add(admin)
            db.session.commit()

            # 在一个线程中启动Flask服务起
            threading.Thread(target=cls.app.run).start()
Example #27
0
    def setUpClass(cls):
        options = webdriver.ChromeOptions()
        options.add_argument('headless')

        try:
            cls.client = webdriver.Chrome(
                options=options)  #chrome_options deprecated
        except:
            pass

        if cls.client:
            cls.app = create_app("testing")
            cls.app_context = cls.app.app_context()
            cls.app_context.push()
            import logging
            logger = logging.getLogger("werkzeug")
            logger.setLevel("ERROR")

            db.create_all()
            Role.insert_roles()
            fake.users(10)
            fake.posts(10)

            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()
            time.sleep(1)
            cls.server_thread = threading.Thread(target=cls.app.run,
                                                 kwargs={
                                                     "debug": "false",
                                                     "use_reloader": "false",
                                                     "use_debugger": "false"
                                                 })
            cls.server_thread.start()
            time.sleep(1)
Example #28
0
    def setUpClass(cls):
        # 启动浏览器
        # options = webdriver.ChromeOption()
        # options.add_argument('headless')
        try:
            cls.client = webdriver.Chrome('C:/Python/chromedriver')
        except:
            pass
        # 如果无法启动浏览器  则跳过这些测试
        if cls.client:
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            # 禁止日志,保持输出简洁
            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel('ERROR')

            # 创建数据库, 使用一些虚拟数据填充
            db.create_all()
            Role.insert_roles()
            # User.generate_fake(10)
            # Post.generate_fake(10)
            fake.users(10)
            fake.posts(10)


            #添加管理员
            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()

            # 在一个线程中启动Flask服务器
            cls.server_thread = threading.Thread(target=cls.app.run, kwargs={'debug':False})
            cls.server_thread.start()
            time.sleep(1)
Example #29
0
def generate_fake():
    users(50)
    posts(50)
Example #30
0
def fake_data():
    fake.users()
    fake.posts(200)
Example #31
0
def run_fake():
    from app import fake
    fake.users()
    fake.posts()