def clear_all_tables(): test_only() db_drop_and_create_all() """ Tests: test_02_populate_test """ return jsonify({"success": True})
def test_get_movies_404(self): db_drop_and_create_all() res = self.client().get( '/movies', headers={'Authorization': executive_producer_token}) self.assertEqual(res.status_code, 404) db_init_records()
def setUp(self): self.app = create_app() self.client = self.app.test_client self.casting_assistant = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InVMVTRlV0lscHNHMEZWc1VNR2JyUyJ9.eyJpc3MiOiJodHRwczovL25rY29mZmVlLmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHw1ZWMyZDU3ODljMDdhMTBjZTdjNmYyODQiLCJhdWQiOiJhY3RvcnNBbmRNb3ZpZXMiLCJpYXQiOjE1ODk4MjcxODMsImV4cCI6MTU4OTkxMzU4MywiYXpwIjoienBpemRGTkZWNlVuemdzUmVTd1p3UE0xVXpWTTNRVDMiLCJzY29wZSI6IiIsInBlcm1pc3Npb25zIjpbImdldDphY3RvcnMiLCJnZXQ6bW92aWVzIl19.eqgsR8jbfDxxbatEoaExJ7A1DtHtmOCkqsEJiPD1eWhPMhhewRykdtnTI2deaYAN9VwQfm-sTD86kwvBAYnLAj_4BKbTaMZyepcp3gh1l7Pu5JKYfJbzp4Jfk9LsXrDNkoBXecZmFgxw0iQnZMM4-7bB8HB26eOdJrtCmx8C49y7Vd0S3Rv7kdrVkzN3y2V4CUA_1F7A-7FZ1aPhDGtEEIFeUetjb7DZN_bs4Xwd0rb9dQTNs0jXk_T0ck8Lde_J8szjh-UNQO2DiFX_gmwwG0FzoUKn1jUFWDgHgZyyEWl2m23ZU4g6Hfq6BZv7egS02IjPogNxhD_pbadPyB7GPg' self.casting_director = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InVMVTRlV0lscHNHMEZWc1VNR2JyUyJ9.eyJpc3MiOiJodHRwczovL25rY29mZmVlLmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHw1ZWMyZDViODljMDdhMTB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wYXRjaDphY3RvcnMiLCJwYXRjaDptb3ZpZXMiLCJwb3N0OmFjdG9ycyIsInBvc3Q6bW92aWVzIl19.hdsEQKfu12qHqNe6qHrShJc7AOuS416TGGWHLy7bGhM9HGcxeMv2eolpPMb6zTs-uia9LIMcjXtootBgg_DQ3_KL0_iem_5bGwjsPdRq5Gs8abl_UmJNjP7_fzgc9o3fu5JPmlz1eUVOfysnAm6zTrlkRNmBSiHaw_LvJPtAIk9l2TQYElkZ7rXx01M3YulNK_IfiJ113PM89a3k6D62hPaWP-dJL7Nja458-69byDzrNNc0CEmTwcKj774p9jW-VWNEf4E4P31qIf9iXaLcsHYeA6XpaZg7Ep0GgAiwXZJFZa7vi46uPS8CoWVRoIYqKvfkbziU38_K3Kq8FIipdg' self.database_filename = "database.db" self.project_dir = os.path.dirname(os.path.abspath(__file__)) self.database_path = "sqlite:///{}".format( os.path.join(self.project_dir, self.database_filename)) setup_db(self.app, self.database_path) db_drop_and_create_all() self.new_actor = {'name': 'Nick Klenke', 'age': 41, 'gender': 'Male'} self.new_movie = {'title': 'New Movie', 'genre': 'Comedy'} # binds the app to the current context with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app) db_drop_and_create_all()
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_name = "capstone" self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name) db_drop_and_create_all() setup_db(self.app, self.database_path) self.new_movie = { 'title': 'New Year', 'release_date': '6/2019' } self.new_actor = { 'name': 'Dale', 'age': '25', 'gender': 'Male' } # binds the app to the current context 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""" db_drop_and_create_all() actor = Actor(**self.new_actor) actor.insert() movie = Movie(**self.new_movie) movie.insert()
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_filename = "database.db" self.project_dir = os.path.dirname(os.path.abspath(__file__)) self.database_path = "sqlite:///{}".format( os.path.join(self.project_dir, self.database_filename)) setup_db(self.app, self.database_path) db_drop_and_create_all() # test data self.new_actor = { 'name': 'Obi Won Konobe', 'gender': 'unknown', 'age': 100 } self.new_movie = {'title': 'Sun Wars', 'year': 1920} # binds the app to the current context with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app) # create all tables self.db.create_all()
def setup_database(): db_drop_and_create_all() insert_data() return jsonify({ 'success': True, })
def test_a_1_001_user_insert(self): db_drop_and_create_all() user1 = User(username="******", password="******") user1.insert() users = User.query.all() self.assertEqual(len(users), 1) print("Test a_1_1: user insert")
def test_a_2_001_category_insert(self): db_drop_and_create_all() category1 = Category(name="Cheese") category1.insert() categories = Category.query().all() self.assertEqual(len(categories), 1) print("Test a_2_1: category insert")
def test_a_3_001_pc_insert(self): db_drop_and_create_all() populate_tables() pc1 = ProductCategory(product_id=3, category_id=7) pc1.insert() pcs = ProductCategory.query().all() self.assertEqual(len(pcs), 16) print("Test a_3_1: pc insert")
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_name = "players_test" self.database_path = "postgres://{}/{}".format( 'localhost:5432', self.database_name) setup_db(self.app, self.database_path) # sample new concert self.new_concert = { 'title': "LSO returns!", 'style': "Romantic", 'concert_date': '20200901' } # sample incomplete new concert self.incomplete_new_concert = { 'title': "LSO returns!", 'style': "Romantic" } # sample patch concert self.patch_concert = { 'title': "LSO returns (updated)!" } # sample new player self.new_player = { 'name': "Foo Bar", 'instrument': "Oboe", 'experience': 5 } # sample incomplete new concert self.incomplete_new_player = { 'name': "Foo Bar", 'instrument': "Oboe" } # sample patch player self.patch_player = { 'name': "Foo Update Bar", } # binds the app to the current context with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app) # create all tables self.db.create_all() # start with sample data db_drop_and_create_all() add_test_data()
def test_a_2_001_product_insert(self): db_drop_and_create_all() product1 = Product(name="product1", price=5.5, in_stock=True, seller_id=1) product1.insert() products = Product.query.all() self.assertEqual(len(products), 1) print("Test a_2_1: Product insert")
def setUp(self): self.app = create_app() self.client = self.app.test_client self.database_path = os.environ['DATABASE_URL'] setup_db(self.app, self.database_path) db_drop_and_create_all() with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app) self.db.create_all()
def setUp(self): self.app = create_app() self.client = self.app.test_client self.database_path = "postgres://*****:*****@localhost:5432/project_test" setup_db(self.app, self.database_path) db_drop_and_create_all() with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app) self.db.create_all()
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_path = database_path setup_db(self.app, self.database_path) db_drop_and_create_all() # binds the app to the current context with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app)
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_path = 'postgres://*****:*****@localhost:5432/activelix' setup_db(self.app, self.database_path) db_drop_and_create_all() with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app) self.db.create_all()
def test_a_1_001_product_insert(self): db_drop_and_create_all() product1 = Product(name="Cheese", price=50.4, quantity=7.89, id=10000000, code=789456611) product1.insert() products = Product.query().all() self.assertEqual(len(products), 1) print("Test a_1_1: product insert")
def test_0a_1_3_1_MyModel(self): db_drop_and_create_all() # Creating the user user_to_del = User(username="******", password="******") db.session.add(user_to_del) db.session.commit() self.assertEqual(len(User.query.all()), 1) prod_to_del1 = Product(name="abc", price=456, seller_id=user_to_del.id) prod_to_del2 = Product(name="abcdef", price=4567, seller_id=user_to_del.id) db.session.add_all([prod_to_del1, prod_to_del2]) db.session.commit() self.assertEqual(len(Product.query.all()), 2) order_to_del1 = Order(user_id=user_to_del.id, product_id=prod_to_del1.id, amount=1) order_to_del2 = Order(user_id=user_to_del.id, product_id=prod_to_del2.id, amount=3) order_to_del3 = Order(user_id=user_to_del.id, product_id=prod_to_del2.id, amount=5) db.session.add_all([order_to_del1, order_to_del2, order_to_del3]) db.session.commit() self.assertEqual(len(Order.query.all()), 3) #img_to_delete1=Image(seller_id=1,name="abc",formatting = "png") #img_to_delete2=Image(seller_id=1,name="abce",formatting = "jpg") #db.session.add_all([img_to_delete1,img_to_delete2]) #db.session.commit() #self.assertEqual(len(Image.query.all()),2) # Trying to delete #img_to_delete2.delete() #self.assertEqual(len(Image.query.all()),1) order_to_del3.delete() self.assertEqual(len(Order.query.all()), 2) prod_to_del2.delete() self.assertEqual(len(Order.query.all()), 1) self.assertEqual(len(Product.query.all()), 1) user_to_del.delete() #self.assertEqual(len(Image.query.all()),0) self.assertEqual(len(Order.query.all()), 0) self.assertEqual(len(Product.query.all()), 0) self.assertEqual(len(User.query.all()), 0) print("Test 0a_1_3_1 : MyModel: relationships")
def setUp(self): self.app = create_app() self.client = self.app.test_client setup_db(self.app) db.session.close() db.session.remove() db_drop_and_create_all() newMovie = Movie(title="new Movie", release_date="12/12/12") newMovie.insert() newActor = Actor(name="new Actor", age=24, gender="male") newActor.insert()
def test_0a_1_3_1_MyModel(self): db_drop_and_create_all() # Creating the product product_to_del = Product(name="Cheese", price=50.4, quantity=7.89, id=10000000, code=789456611) product_to_del.insert() #self.assertEqual(len(session.query(Product).all()),1) self.assertEqual(len(Product.query().all()), 1) """prod_to_del1 = Product(name = "abc",price=456,seller_id=user_to_del.id) prod_to_del2 = Product(name = "abcdef",price=4567,seller_id=user_to_del.id) db.session.add_all([prod_to_del1,prod_to_del2]) db.session.commit() self.assertEqual(len(Product.query.all()),2) order_to_del1 = Order( user_id = user_to_del.id,product_id=prod_to_del1.id,amount=1) order_to_del2 = Order( user_id = user_to_del.id,product_id=prod_to_del2.id,amount=3) order_to_del3 = Order( user_id = user_to_del.id,product_id=prod_to_del2.id,amount=5) db.session.add_all([order_to_del1,order_to_del2,order_to_del3]) db.session.commit() self.assertEqual(len(Order.query.all()),3)""" #img_to_delete1=Image(seller_id=1,name="abc",formatting = "png") #img_to_delete2=Image(seller_id=1,name="abce",formatting = "jpg") #db.session.add_all([img_to_delete1,img_to_delete2]) #db.session.commit() #self.assertEqual(len(Image.query.all()),2) # Trying to delete #img_to_delete2.delete() #self.assertEqual(len(Image.query.all()),1) """order_to_del3.delete() self.assertEqual(len(Order.query.all()),2) prod_to_del2.delete() self.assertEqual(len(Order.query.all()),1) self.assertEqual(len(Product.query.all()),1)""" product_to_del.delete() #self.assertEqual(len(Image.query.all()),0) """self.assertEqual(len(Order.query.all()),0) self.assertEqual(len(Product.query.all()),0) self.assertEqual(len(Product.query.all()),0)""" print("Test 0a_1_3_1 : MyModel: relationships")
def setUp(self): self.app = create_app() self.client = self.app.test_client setup_db(self.app) db_drop_and_create_all() with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app) self.db.create_all() self.new_actor = {"name": "Richard Gere", "age": 99, "gender": "male"} self.new_movie = {"title": "Batman", "release_date": date.today()}
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_name = "fsnd_capstone" self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name) setup_db(self.app, self.database_path) db_drop_and_create_all() # binds the app to the current context with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app) # create all tables self.db.create_all()
def setUp(self): """Set up of the test""" self.app = app self.client = self.app.test_client self.database_name = "nomadic" self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name) setup_db(self.app, self.database_path) db_drop_and_create_all() # binds the app to the current context with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app) # create all tables self.db.create_all()
def setUp(self): """Define test variables and initialize app.""" self.app = app self.client = self.app.test_client self.database_name = "casting_test" self.database_path = "postgresql://{}/{}".format( 'localhost:5432', self.database_name) setup_db(self.app, self.database_path) db_drop_and_create_all() self.assistant_header = os.environ['AS_HEAD'] self.director_header = os.environ['DR_HEAD'] self.producer_header = os.environ['PR_HEAD'] # binds the app to the current context with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app)
def setUp(self): self.app = create_app() self.client = self.app.test_client self.database_path = os.environ( 'DATABASE_URL', "postgres://{}:{}@{}/{}".format(database_setup["user_name"], database_setup["password"], database_setup["port"], database_setup["database_name"])) setup_db(self.app, self.database_path) db_drop_and_create_all() with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app) # create all tables self.db.create_all()
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_path = os.environ['TEST_DATABASE_URL'] setup_db(self.app, self.database_path) # binds the app to the current context with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app) # drop and create all tables db_drop_and_create_all() # sample actor to be used for test self.new_actor_1 = { 'name': 'Gal Gadot', 'gender': 'female', 'age': 35, } self.new_actor_2 = { 'name': 'Daisy Ridley', 'gender': 'female', 'age': 30, } self.update_actor = { 'name': 'Daisy Ridley', 'gender': 'female', 'age': 28, } self.new_movie_1 = { 'title': 'Mission: Impossible 7', 'release_date': '2021-11-19', } self.new_movie_2 = { 'title': 'Matrix', 'release_date': '2021-12-22', } self.update_movie = { 'title': 'The Matrix 4', 'release_date': '2021-12-22', }
def setUp(self): """Define test variables and initialize app.""" #os.environ['DATABASE_NAME'] = "cast_test" self.app = create_app() self.client = self.app.test_client self.database_name = "cast" self.database_path = "postgresql://{}@{}/{}".format( 'postgres', 'localhost:5432', self.database_name) setup_db(self.app, self.database_path) db_drop_and_create_all() # binds the app to the current context with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app) # create all tables self.db.create_all()
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_name = "casting" self.database_path = "postgresql://{}:{}@{}/{}".format( 'postgres', 'admin', 'localhost:5432', self.database_name) setup_db(self.app, self.database_path) with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app) db_drop_and_create_all() self.assistant_jwt = { 'Content-Type': 'application/json', 'Authorization': "Bearer {}".format(assistant_token) } self.director_jwt = { 'Content-Type': 'application/json', 'Authorization': "Bearer {}".format(director_token) } self.producer_jwt = { 'Content-Type': 'application/json', 'Authorization': "Bearer {}".format(producer_token) } self.new_movie = {'title': 'Head Strong', 'release_date': '2020'} self.new_bad_movie = {'title': '', 'release_date': ''} self.new_actor = {'name': 'Sam England', 'age': '25', 'gender': 'male'} self.new_bad_actor = {'name': ''} self.new_title = { 'title': 'Iron Mind', } self.new_name = { 'name': 'Sammy E', }
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_path = os.environ['DATABASE_URL'] setup_db(self.app, self.database_path) self.casting_director_auth_header = casting_director_auth_header self.casting_assistant_auth_header = casting_assistant_auth_header self.executive_producer_auth_header = executive_producer_auth_header db_drop_and_create_all() # binds the app to the current context with self.app.app_context(): self.db = SQLAlchemy() self.db.init_app(self.app) # create all tables self.db.create_all()
def setUp(self): self.app = create_app() self.client = self.app.test_client self.database_path = os.getenv('DATABASE_URL') setup_db(self.app, self.database_path) db_drop_and_create_all() # binds the app to the current context with self.app.app_context(): self.db = SQLAlchemy() # initalizs db self.db.init_app(self.app) # create all tables self.db.create_all()