def setUp(self): self.app = create_app('TEST') self.app.testing = True self.test_client = self.app.test_client() self.parameters = { 'reference_number': 'braintree_reference_number', 'user_exists_id': 5, 'user_new_id': '67', 'customer_id': 'customer_id', 'method_used': 'Web Form Credit Card', 'given_to': 'NERF', 'transaction_status': 'Completed', 'transaction_type': 'Gift', 'gross_gift_amount': Decimal(25.00), 'fee': Decimal(0.00) } init_braintree_credentials(self.app) with self.app.app_context(): database.reflect() database.drop_all() database.create_all() # Create some ultsys user data for the Ultsys endpoints wrapped in functions for mocking. create_ultsys_users() database.session.add_all(create_method_used()) database.session.commit() self.method_used_id = MethodUsedModel.get_method_used( 'name', self.parameters['method_used']).id
def get_recipes_without_images(*args): app = create_app() import os if len(os.listdir('/home/ubuntu/eaterator/spool')) > 300: return with app.app_context(): default = -1 recipes = Recipe.query.\ filter( not_( Recipe.pk.in_( db.session.query(func.distinct(RecipeImage.recipe)) ) ), Recipe.title.isnot(None) ).limit(55).all() if len(recipes) <= 0: app.logger.debug( "CLICKR CRON | Added reicpes from failed searches") default = -2 recipes = Recipe.query.filter( Recipe.pk.in_( db.session.query(RecipeImage.recipe).filter( RecipeImage.secret == 'default', RecipeImage.farm_id != '-2'))).limit(55).all() for recipe in recipes: if recipe.title: uwsgi.spool({ b'pk': str(recipe.pk).encode('utf-8'), b'title': recipe.title.encode('utf-8'), b'default': str(default).encode('utf-8') }) db.session.close() db.session.remove() return
def setUp(self): self.app = create_app('TEST') self.app.testing = True self.test_client = self.app.test_client() self.parameters = { 'reference_number': '101', 'method_used': 'Check', 'date_of_method_used': '2018-07-12 00:00:00', 'given_to': 'NERF', 'transaction_type': 'Gift', 'gross_gift_amount': Decimal(10.00), 'transaction_status': 'Completed', 'new_user_email': '*****@*****.**', 'customer_id': 'customer_id', 'second_transaction_type': 'Deposit to Bank', 'bank_deposit_number': '<bank-deposit-number>' } with self.app.app_context(): database.reflect() database.drop_all() database.create_all() # Create some ultsys user data for the Ultsys endpoints wrapped in functions for mocking. create_ultsys_users() database.session.add_all(create_method_used()) database.session.commit() self.method_used_id = MethodUsedModel.get_method_used( 'name', self.parameters['method_used']).id
def setUp(self): self.app = create_app('TEST') self.app.testing = True self.test_client = self.app.test_client() self.parameters = { 'gift_amount_refund': Decimal('1.00'), 'gift_amount_reallocate': Decimal('25.00'), 'gift_amount_bounced': Decimal('0.00'), 'transaction_type_void': 'Void', 'transaction_type_bounced': 'Bounced', 'transaction_type_refund': 'Refund', 'transaction_type_correction': 'Correction' } with self.app.app_context(): database.reflect() database.drop_all() database.create_all() # Create some ultsys user data for the Ultsys endpoints wrapped in functions for mocking. create_ultsys_users() database.session.add_all(create_method_used()) database.session.commit()
def app(): _app = create_app(TestConfig) ctx = _app.test_request_context() ctx.push() yield _app ctx.pop()
def app(): """Create application for the tests.""" _app = create_app("test.settings") ctx = _app.test_request_context() ctx.push() yield _app ctx.pop()
def get_app(): conf = config.BaseConfig if str(MainApp.flask_env.env).lower() == "prod": conf = config.ProdConfig elif str(MainApp.flask_env.env).lower() == "staging": conf = config.StageConfig elif str(MainApp.flask_env.env).lower() == "dev": conf = config.DevConfig return create_app(conf)
def setUp( self ): self.app = create_app( 'TEST' ) self.app.testing = True self.test_client = self.app.test_client() self.access_token = ACCESS_TOKEN self.headers = { 'Authorization': 'Bearer {}'.format( self.access_token ) } with self.app.app_context(): database.reflect() database.drop_all() database.create_all()
def app(): app = create_app( dict(TESTING=True, SQLALCHEMY_DATABASE_URI='sqlite:///:memory:', SERVER_NAME='127.1')) with app.app_context(): init_db() yield app
def client(): # Use our test integration config instead of the 'real' version. file_path = find_dotenv('.env.test') load_dotenv(file_path, override=True) # Create the new app. test_app = app.create_app() # Use the app to create a test_client that can be used in our tests. with test_app.test_client() as client: yield client
def app_dev_with_config_file(): os.environ['APP_ENV'] = 'DEV' test_settings = os.path.join( os.getcwd(), 'tests', 'test_files', 'test_settings.cfg', ) settings = os.path.join(os.getcwd(), 'settings.cfg') shutil.copyfile(test_settings, settings) yield create_app() os.remove(settings)
def setUp(self): self.app = create_app('TEST') self.app.testing = True self.test_client = self.app.test_client() with self.app.app_context(): database.reflect() database.drop_all() database.create_all() # Create some ultsys user data for the Ultsys endpoints wrapped in functions for mocking. create_ultsys_users()
def app_no_env_with_file(): if 'APP_ENV' in os.environ: os.environ.pop('APP_ENV') test_settings = os.path.join( os.getcwd(), 'tests', 'test_files', 'test_settings.cfg', ) settings = os.path.join(os.getcwd(), 'settings.cfg') shutil.copyfile(test_settings, settings) yield create_app() os.remove(settings)
def flask_app(): app = create_app("testing") # app.db.disconnect with app.app_context(): # print("=========="*2) # for x in dir(app.login_manager): # print(f"login manager: {x}") # print("=========="*2) # for x in dir(app.user_manager): # print(f"user manager: {x}") # print("=========="*2) yield app
def client_v1(): test_settings = os.path.join( os.getcwd(), 'tests', 'test_files', 'test_settings.cfg', ) settings = os.path.join(os.getcwd(), 'settings.cfg') shutil.copyfile(test_settings, settings) app = create_app() os.remove(settings) client = app.test_client() yield client
def setUpDB(self): from tests.tsting_config import SQLALCHEMY_DATABASE_URI from application import config config.SQLALCHEMY_DATABASE_URI = SQLALCHEMY_DATABASE_URI self.app = create_app(app_config=config) from application.base_models import db self.db = db with self.app.app_context(): self.db.session.remove() self.db.session.close() self.db.drop_all() self.db.create_all() self.roles = self.ingredients = self.recipes = None self.test_client = self.app.test_client()
def client_v1_backend_issue(monkeypatch): test_settings = os.path.join( os.getcwd(), 'tests', 'test_files', 'test_settings.cfg', ) settings = os.path.join(os.getcwd(), 'settings.cfg') shutil.copyfile(test_settings, settings) monkeypatch.setattr("application.models.init_app", lambda x: '') app = create_app() os.remove(settings) client = app.test_client() yield client
def setUp(self): self.app = create_app('TEST') self.app.testing = True self.test_client = self.app.test_client() self.parameters = {} init_braintree_credentials(self.app) with self.app.app_context(): database.reflect() database.drop_all() database.create_all() database.session.add_all(create_method_used()) database.session.commit()
def app(): """ Setup our flask test app, this only gets executed once. :return: Flask app """ params = {'DEBUG': False, 'TESTING': True, 'WTF_CSRF_ENABLED': False} _app = create_app(settings_override=params) # Establish an application context before running the tests. ctx = _app.app_context() ctx.push() yield _app ctx.pop()
def test_app(): # Load the environment variables. file_path = find_dotenv('.env') load_dotenv(file_path, override=True) # Override environment variables. temp_db = "temp_db" os.environ['COSMOS_TODO_APP_DATABASE'] = temp_db os.environ['LOGIN_DISABLED'] = "False" # Create app instance using newly created board. application = app.create_app() # Start the app in its own thread. thread = Thread(target=lambda: application.run(use_reloader=False)) thread.daemon = True thread.start() yield application # Tear down. thread.join(1) drop_database(temp_db)
#!/usr/bin/env python # -*- coding: utf-8 -*- import os from flask_script import Manager, Shell, Server from flask_migrate import MigrateCommand from application.app import create_app from application.settings import DevConfig, ProdConfig from application.models.foo import Foo from application.models.basket import Basket from application.models.page import Page from application.models.kv import KV from application.extensions import db if os.environ.get("APPLICATION_ENV") == 'prod': app = create_app(ProdConfig) else: app = create_app(DevConfig) HERE = os.path.abspath(os.path.dirname(__file__)) TEST_PATH = os.path.join(HERE, 'tests') manager = Manager(app) def _make_context(): """Return context dict for a shell session so you can access app, db and the Foo model by default. """ return { 'app': app,
def test_dev_config(): app = create_app(DevConfig) assert app.config['ENV'] == 'dev' assert app.config['DEBUG'] is True
def test_production_config(): app = create_app(ProdConfig) assert app.config['ENV'] == 'prod' assert app.config['DEBUG'] is False
import pymysql import requests from s3_web_storage.web_storage import WebStorage from application.app import create_app from application.helpers.general_helper_functions import get_vault_data from application.helpers.sql_queries import query_transactions_for_csv # pylint: disable=bare-except # pylint: disable=no-member # pylint: disable=invalid-name # Check for how the application is being run and use that. # The environment variable is set in the Dockerfile. app_config_env = os.environ['APP_ENV'] # pylint: disable=invalid-name app = create_app(app_config_env) # pylint: disable=C0103 WebStorage.init_storage(app, app.config['AWS_CSV_FILES_BUCKET'], app.config['AWS_CSV_FILES_PATH']) HEADER = [ 'gift_id', 'method_used', 'given_to', 'given_by_user_id', 'originating_agent_name', 'originating_agent_id', 'searchable_gift_id', 'gift_id', 'reference_number', 'transaction_agent_name', 'transaction_agent_id', 'transaction_type', 'transaction_status', 'transaction_date', 'transaction_gross', 'transaction_fee', 'notes' ] FILE_TYPE = 'csv' FILE_PREFIX = 'full_database_dump_at' FILE_DATETIME = datetime.now().strftime('%Y_%m_%d')
def client(): os.environ['TESTING'] = 'true' from application.settings import TestConfig from application.app import create_app return create_app(TestConfig).test_client()
def setUpClass(cls) -> None: cls.app = create_app(testing=True) cls.db = get_db() cls.client = TestClient(cls.app) cls.base_url = "/api/v1"
def _create_app(config=None): app = create_app() return app
import re import sys from application.app import create_app app = create_app('application.config.DevelopmentConfig') if __name__ == '__main__': app.run(host='0.0.0.0', port=5000)
import os from application.app import create_app app = create_app(os.environ["FLASK_CONFIG"])
if config.USE_PYPY: from psycopg2cffi import compat compat.register() if config.USE_GEVENT: # patch built-in modules for greenlets/async from gevent.pywsgi import WSGIServer import gevent.monkey gevent.monkey.patch_all() # patch database driver to be non blocking import psycogreen.gevent psycogreen.gevent.patch_psycopg() # modify db for gevent from application.app import create_app app = create_app() # development and testing if __name__ == '__main__': if config.USE_GEVENT and config.DEBUG: app.config['DEBUG'] = config.DEBUG if config.GEVENT_REQUEST_LOGGING: server = WSGIServer(('', config.GEVENT_PORT), app) else: server = WSGIServer(('', config.GEVENT_PORT), app, log=None) print('Serving dev (gevent WSGI server) application on localhost:{0}'. format(config.GEVENT_PORT)) server.serve_forever() elif config.DEBUG or not config.USE_GEVENT: print("Running flask development server") # db.app.config.update(
def app(): app = create_app("test") return app
can be added to manage other database tasks. To run a function navigate to the project root and, for example, on the command line type: python -c "import scripts.manage_donors_db;scripts.manage_donors_db.drop_all_and_create()" python -c "import scripts.manage_donors_db;scripts.manage_donors_db.create_database_tables()" """ import uuid from application.app import create_app from application.flask_essentials import database from application.schemas.agent import AgentSchema from application.schemas.caged_donor import CagedDonorSchema from application.schemas.queued_donor import QueuedDonorSchema from tests.helpers.default_dictionaries import get_caged_donor_dict app = create_app('DEV') # pylint: disable=C0103 def drop_all_and_create(): """A function to drop and then recreate the database tables.""" with app.app_context(): database.reflect() database.drop_all() database.create_all() def create_database_tables(): """Function to create the DONATE database tables, specifically the CagedDonorModel and QueuedDonorModel with UUID. All that is said here for the CagedDonorModel also holds for the QueuedDonorModel. The CagedDonorModel is built
from flask_script import Manager from flask_migrate import MigrateCommand from application.app import create_app from application.extensions import db from models.member import Member app = create_app('application.config.Config') manager = Manager(app) @manager.command def create_db(): """ Create Database """ db.create_all() @manager.command def drop_db(): """ Drop Database """ db.drop_all() @manager.command def create_member(email, password, fullname): hashed_password = Member.hash_password(password) member = Member(email, hashed_password, fullname)
from application.app import create_app if __name__ == "__main__": application = create_app() application.run()
import uvicorn from application.app import create_app app = create_app() if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=8000)
import re import sys from gunicorn.app.wsgiapp import run from application.app import create_app app = create_app('application.config.DeploymentConfig') if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) sys.exit(run())