Пример #1
0
    def setUp(self):
        """ Creates a headless chrome instance for Selenium and clears the DB. """
        DataGen.create_defaults()
        db.session.flush()

        chrome_options = Options()
        chrome_options.add_argument("--headless")
        chrome_options.add_argument(
            "window-size=1980,960")  # Make screenshots larger
        self.browser = webdriver.Chrome(chrome_options=chrome_options)
        self.browser.implicitly_wait(1)
        self.base_url = self.get_server_url()

        # Ensure browser executable is cleaned up at the end of the test
        self.addCleanup(self.browser.quit)

        # Set up default accounts for logging in
        default_resident = current_app.config['USERS']['RESIDENT']
        self.default_resident_email = default_resident['email']
        self.default_resident_password = default_resident['password']
        self.default_resident_name = default_resident['first_name']

        default_admin = current_app.config['USERS']['ADMIN']
        self.default_admin_email = default_admin['email']
        self.default_admin_password = default_admin['password']
        self.default_admin_name = default_admin['first_name']
Пример #2
0
 def setUp(self):
     """ Runs before every test and clears relevant tables """
     DataGen.clear_db()
     self.db = db
     DataGen.create_default_room()
     self.bcrypt_patch = patch('ovs.models.user_model.Bcrypt',
                               new=bcrypt_mock)
     self.addCleanup(self.bcrypt_patch.stop)
     self.bcrypt_patch.start()
Пример #3
0
 def create_test_users(self):
     """ Creates two RESIDENT accounts and one ADMIN account for use in testing """
     DataGen.create_default_room()
     self.test_resident_1 = UserService.create_user('*****@*****.**', 'Bob',
                                                    'Ross', 'RESIDENT')
     self.test_resident_2 = UserService.create_user('*****@*****.**',
                                                    'Joe', 'Smith',
                                                    'RESIDENT')
     self.test_admin = UserService.create_user('*****@*****.**', 'Jim',
                                               'White', 'ADMIN')
Пример #4
0
 def tearDown(self):
     """
     Runs after every tests and clears relevant tables. Subclasses should
     override this if they require additional teardown code to be run
     """
     DataGen.clear_db()
Пример #5
0
def create_app(config_path=None):
    """
    Creates a Flask app instance and returns it

    Args:
        config_path (str): A path to a JSON object with an app configuration.

    Note:
        Some default configurations can be found in `config`.

    Returns:
        Flask: a Flask app.
    """
    app = Flask(__name__)
    config = OVSConfig(config_path)
    for key, value in config.items():
        app.config[key] = value

    env = app.config['ENV']
    app.config['DEVELOPMENT'] = env == 'DEV'
    app.config['TESTING'] = env == 'TEST'
    app.config['PRODUCTION'] = env == 'PROD'

    with app.app_context():
        db_config = app.config['DATABASE']
        if app.config['SELENIUM']:
            app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/ovs.db'
        elif app.config['TESTING']:
            app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
        else:
            app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://' + \
                                                    db_config['USER'] + ':' + \
                                                    db_config['PASSWORD'] + '@' + \
                                                    db_config['HOSTNAME'] + ':' + \
                                                    db_config['PORT'] + '/' + \
                                                    db_config['NAME']
        app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

        db.init_app(app)
        if app.config['SELENIUM']:
            from ovs.datagen import DataGen  # Avoid circular dependencies.
            DataGen.clear_db()
        else:
            import ovs.models  # pylint: disable=unused-variable
            db.create_all()

        from ovs.blob import blob
        blob.init_app(app)

        from ovs.models.user_model import bcrypt_app
        bcrypt_app.init_app(app)

        from ovs.utils import serializer
        serializer.init_app(app)

        from ovs.services.auth_service import LOGIN_MANAGER
        LOGIN_MANAGER.init_app(app)
        LOGIN_MANAGER.login_view = '/'
        LOGIN_MANAGER.login_message_category = 'danger'

        from flask_wtf.csrf import CSRFProtect
        csrf = CSRFProtect()
        csrf.init_app(app)

        from ovs import routes
        app.register_blueprint(routes.OvsRoutes, url_prefix='/')
        app.register_blueprint(routes.AdminRoutes, url_prefix='/admin')
        app.register_blueprint(routes.ManagerRoutes, url_prefix='/manager')
        app.register_blueprint(routes.ResidentRoutes, url_prefix='/resident')
        app.register_blueprint(routes.AuthRoutes, url_prefix='/auth')

        app.jinja_env.globals.update(utc_to_timezone=utc_to_timezone)

        if (os.environ.get("WERKZEUG_RUN_MAIN") == "true" or os.environ.get("FLASK_DEBUG") != "True")\
           and not app.config['TESTING']:
            from ovs.datagen import DataGen  # Avoid circular dependencies.
            DataGen.create_defaults()

        db.session.commit()

    return app
Пример #6
0
 def setUp(self):
     """ Runs before every test and clears relevant tables """
     super().setUp()
     DataGen.create_defaults()
Пример #7
0
 def setUp(self):
     """ Runs before every test and clears relevant tables """
     super().setUp()
     DataGen.create_default_room()
     self.create_test_resident()