def test_suite_setup(): destroy_db() setup_db() memberlib.create(**test_commenter) publicationlib.create(**test_publication) asset_req_id = assetrequestlib.create(**test_asset_request) assetrequestlib.approve(asset_req_id, approver=12)
def setUp(self): self.app = app self.client = self.app.test_client self.database_name = "capstone_test" self.user_name = "AshNelson" self.password = "******" self.app.config[ "SQLALCHEMY_DATABASE_URI"] = "postgresql://{}:{}@{}/{}".format( self.user_name, self.password, 'localhost:5432', self.database_name) setup_db(self.app, database_path=self.app.config["SQLALCHEMY_DATABASE_URI"]) # with self.app.app_context(): # self.db = SQLAlchemy() # self.db.init_app(self.app) # self.db.create_all() def tearDown(self): """Executed after reach test""" selection = Movies.query.filter( Movies.name == 'Peace keepers').all() for movie in selection: movie.delete() selection = Actors.query.filter(Actors.name == 'Jina Rice').all() for actor in selection: actor.delete() pass
def setUp(self): '''Define test variables and initialize app.''' self.app = create_app() self.client = self.app.test_client setup_db(self.app) with self.app.app_context(): # binds the app to the current context self.db = SQLAlchemy() self.db.init_app(self.app)
def create_app(): app = Flask(__name__) if app.config["ENV"] == "production": app.config.from_object("config.ProductionConfig") else: app.config.from_object("config.DevelopmentConfig") CORS(app) setup_jwt(app) app.register_blueprint(site) app.register_blueprint(api) setup_db(app) return app
def setUp(self): """Define test variables and initialize app.""" self.app = app self.client = self.app.test_client self.headers = { 'Content-Type': 'application/json', 'Authorization': jwt_token } setup_db(app) # binds the app to the current context with self.app.app_context(): self.db = SQLAlchemy(self.app)
def setUp(self): """Define test variables and initialize app""" self.app = app self.client = self.app.test_client database_path = os.getenv('TEST_DATABASE_URI') setup_db(self.app, database_path) self.movie_id = '' with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app) self.db.create_all() # Add a movie self.movie = Movie(title='The Hatchet', release_date=date(2020, 12, 11)) self.movie.insert() self.movie_id = self.movie.id
def setUp(self): """Define test variables and initialize app""" self.app = app self.client = self.app.test_client database_path = os.getenv('TEST_DATABASE_URI') setup_db(self.app, database_path) self.actor_id = '' with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app) self.db.create_all() # Add an actor self.actor = Actor(name="Mugerwa Fred", dob='1996-05-07', gender="male") self.actor.insert() self.actor_id = self.actor.id
def create_app(): # create and configure the app app = Flask(__name__) app.config.from_object(Config) cors = CORS(app, resources={r"/api/*": {"origins": "*"}}) with app.app_context(): setup_db(app) # import blueprints from .venues import venues from .errors import errors from .shows import shows from .users import users # register blueprints app.register_blueprint(venues.venues) app.register_blueprint(shows.shows) app.register_blueprint(errors.error) app.register_blueprint(users.users) return app
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_name = "capstoneDB_test" self.database_path = os.getenv("TEST_DATABASE_URL") setup_db(self.app, self.database_path, self.database_name) self.movie = Movie(title="instersteller", release_date="2014-4-4") self.actor = Actor(name="tom cruise", age=55, gender="M") self.casting_producer_jwt = os.getenv("CASTING_PRODUCER_JWT") self.casting_director_jwt = os.getenv("CASTING_DIRECTOR_JWT") self.casting_assistant_jwt = os.getenv("CASTING_ASSISTANT_JWT") # binds the app to the current context with self.app.app_context(): db = SQLAlchemy() db.init_app(self.app) # create all tables db.create_all()
from flask import Flask from flask_cors import CORS from flask_script import Manager from flask_migrate import Migrate, MigrateCommand from app.models import setup_db from app.auth.routes import auth from app.user.routes import user ''' setting up flask app with cors middleware and db connection with sqlalchemy ''' app = Flask(__name__) setup_db(app) CORS(app) app.register_blueprint(auth) app.register_blueprint(user) # for db migration when running manage.py manager = Manager(app) manager.add_command('db', MigrateCommand) if __name__ == '__main__': manager.run() app.run(host='0.0.0.0', port='5000')
def test_suite_setup(): destroy_db() setup_db() memberlib.create(**test_commenter) publicationlib.create(**test_publication)
def test_suite_setup(): destroy_db() setup_db()
from flask import Flask, request from flask_restx import Resource, Api from flask_cors import CORS, cross_origin from flask_sqlalchemy import SQLAlchemy from app.models import setup_db, Items app = Flask(__name__) app.secret_key = "test" setup_db(app, database_path="postgresql://*****:*****@localhost:5432/test") CORS(app) api = Api(app, version="1.0", title="Portfolio RestAPI", description="A simple portfolio API") db = SQLAlchemy(app) @api.route("/items") class Test(Resource): def get(self): return {"items": store}, 200 @api.route("/additem") class AddItem(Resource): def post(self): item = request.get_json()["item"] price = request.get_json()["price"]