def app(): """Create and configure a new app instance for each test.""" # create the app with common test config app = create_app({"TESTING": True, "SQLALCHEMY_DATABASE_URI": "sqlite:///:memory:"}) # create the database and load test data # set _password to pre-generated hashes, since hashing for each test is slow with app.app_context(): init_db() user = User(username="******", _password=_user1_pass) db.session.add_all( ( user, User(username="******", _password=_user2_pass), Post( title="test title", body="test\nbody", author=user, created=datetime(2018, 1, 1), ), ) ) db.session.commit() yield app
def setUp(self): app = flaskr.create_app(TestConfig) self.db_fd, self.dbname = tempfile.mkstemp() app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///{}".format(self.dbname) self._ctx = app.test_request_context() self._ctx.push() db.create_all() self.valid_user = User(email="admin@localhost", password="******", active=True) self.client = app.test_client()
def app(): db_fd, db_path = tempfile.mkstemp() app = create_app({ 'TESTING': True, 'DATABASE': db_path, }) with app.app_context(): init_db() get_db().executescript(_data_sql) yield app os.close(db_fd) os.unlink(db_path)
def app(): """Create and configure a new app instance for each test.""" # create a temporary file to isolate the database for each test db_fd, db_path = tempfile.mkstemp() # create the app with common test config app = create_app({ 'TESTING': True, 'DATABASE': db_path, }) # create the database and load test data with app.app_context(): init_db() get_db().executescript(_data_sql) yield app # close and remove the temporary database os.close(db_fd) os.unlink(db_path)
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_name = "trivia_test" self.database_path = "postgres://abdullahalshehri@localhost:5432/trivia_test" 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) # create all tables self.db.create_all() self.question = { 'question': 'What movie earned Tom Hanks his third straight Oscar nomination, in 1996?', 'answer': 'Apollo 13', 'difficulty': 4, 'category': 5 }
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_name = "trivia_test" self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name) setup_db(self.app, self.database_path) # POST data self.new_question_success = { 'question': 'What is the best educational platform?', 'answer': 'Udacity', 'category': 1, 'difficulty': 1 } self.new_question_fail = { 'question': '', 'answer': '', 'category': 1, 'difficulty': 5 } self.successful_quiz = { 'previous_questions': [11, 9, 12], 'quiz_category': { 'id': 0 } } self.failed_quiz = {'previous_questions': None, 'quiz_category': None} # 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 = "trivia_test" self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name) setup_db(self.app, self.database_path) #Sample Trivia Question to be used for testing self.sample_question = { 'question': 'In what year did Nixon resign?', 'answer': '1974', 'difficulty': 3, 'category': 2 } # 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 = "trivia_test" self.database_path = "postgres://{}/{}".format( 'localhost:5432', self.database_name) 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) # create all tables self.db.create_all() self.new_question = { 'question': 'What is Brad Pitts Character in Fight Club?', 'answer': 'Tyler Durden', 'category': 5, 'difficulty': 2, }
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.username = "******" self.password = "******" self.database_name = "trivia_test" self.database_path = "postgresql://{}:{}@{}/{}".format( self.username, self.password, 'localhost:5432', self.database_name) setup_db(self.app, self.database_path) self.deleted_question_id = 22 self.new_question = { 'question': 'What movie earned Tom Hanks his third straight Oscar nomination, in 1996?', 'answer': 'Apollo 13', 'category': 5, 'difficulty': 4 } self.quiz_request_data = { "previous_questions": [10], "quiz_category": { 'id': 6, 'type': 'Sports' } } self.quiz_request_data_no_questions_left = { "previous_questions": [10, 11], "quiz_category": { 'id': 6, 'type': 'Sports' } } # 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 = "trivia_test" #self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name) self.database_path = 'postgresql://*****:*****@localhost:5432/trivia_test' setup_db(self.app, self.database_path) self.new_question = { 'question': 'test question', 'answer': 'test answer', 'difficulty': 3, 'category': '2' } # 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 = "trivia_test" self.database_path = "postgres://{}:{}@{}/{}".format('test_user', 'test', 'localhost:5432', self.database_name) 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) # create all tables self.db.create_all() # Test create_question self.new_question = { 'question': 'What is the best test? ', 'answer': 'The test done.', 'category': 2, 'difficulty': 3 }
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_name = "trivia_test" self.database_path = ("postgres://{}/{}".format( 'localhost:5432', self.database_name)) setup_db(self.app, self.database_path) self.new_question = { "question": "How many rings does the Lakers have?", "answer": "Five", "difficulty": 1, "category": "6" } # 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 = "trivia_test" self.database_path = "postgres://*****:*****@{}/{}".format( 'localhost:5432', self.database_name) 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) # create all tables self.db.create_all() self.new_question = { 'answer': 'Agra', 'category': 3, 'difficulty': 2, 'question': 'The Taj Mahal is located in which Indian city?' }
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_name = "trivia_test" self.database_path = "postgresql://{}:{}@{}/{}".format( 'postgres', 'postgres', 'localhost:5432', self.database_name) setup_db(self.app, self.database_path) self.new_question = { 'question': "In which city is the Empire State Building located?", 'category': 3, 'difficulty': 2, 'answer': 'New York City' } # 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 = "trivia_test" self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name) setup_db(self.app, self.database_path) self.new_question = { 'question': 'when was the kingdom established?', 'answer': 'september 23, 1932', 'difficulty': 4, 'category': 5 } # 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 = "trivia" self.database_path = "postgres://{}:{}@{}/{}".format('caryn','postgre','localhost:5432', self.database_name) 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) # create all tables self.db.create_all() self.new_question = { 'question': 'What country has the longest coastline in the world?', 'answer': 'Canada', 'difficulty': '4', 'category': '3' }
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_name = "trivia_test" self.database_path = "postgres://{}:{}@{}/{}".format( 'postgres', 'password', 'localhost:5432', self.database_name) setup_db(self.app, self.database_path) self.dummy_data = { 'question': 'TEST', 'answer': 'TEST', 'difficulty': 1, 'category': 3 } # 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 = "trivia_test" self.database_path = 'postgres://{}:{}@{}/{}'.format( 'postgres', 'postgres', 'localhost:5432', self.database_name) setup_db(self.app, self.database_path) self.new_question = { 'question': 'how many oceans in the earth', 'answer': 'five', 'category': '5', 'difficulty': 3 } # 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 = "trivia_test" self.database_path = "postgresql://{}:{}@{}/{}".format( 'postgres', 'password', 'localhost:5433', self.database_name) setup_db(self.app, self.database_path) self.new_question = { "question": "Is this a new question?", "answer": "Yes", "difficulty": 1, "category": 1, } # 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 = "trivia_test" self.database_path = "postgresql://{}/{}".format( 'postgres:amany@localhost:5432', self.database_name) setup_db(self.app, self.database_path) self.new_question = { 'question': 'what is olembic?', 'answer': 'group of sports ', 'category': '6', 'difficulty': 1 } # 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 = "trivia_test" self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name) 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) # create all tables self.db.create_all() self.new_question = { 'answer': 'France', 'category': '6', 'difficulty': 4, 'question': 'Who won the last world cup?' }
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_name = "trivia" self.database_path = "postgres://Nani:@{}/{}".format( 'localhost:5432', self.database_name) 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) # create all tables self.db.create_all() # create a new question self.new_question = { "question": 'What is tha captial of Saudi Arabia?', "answer": "Riaydh", "category": 1, "difficulty": 1 }
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_name = "trivia_test" self.database_path = "postgres://{}:{}@{}/{}".format('postgres', 'postgres', 'localhost:5432', database_name) setup_db(self.app, self.database_path) # sample input for adding a question self.new_question = { 'question': 'What organ does a typical human use to smell objects?', 'answer': 'The Nose', 'category': 1, 'difficulty': 1 } # 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 = "trivia_test" self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name) setup_db(self.app, self.database_path) self.new_question = { 'question': 'De que color era el caballo blance de Napoleon?', 'answer': 'blanco', 'difficulty': 1, 'category': '4' } # 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. Executed before each test. """ self.app = create_app() self.client = self.app.test_client self.database_name = "trivia_test" self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name) 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) # create all tables self.db.create_all() self.new_question = { 'question': 'What\'s your name', 'answer': 'Trivia', 'difficulty': 2, 'category': 2 }
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_name = "cating_test" self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name) setup_db(self.app) self.new_movie = { 'title': 'Title', 'release_date': datetime.now().strftime('%Y-%m-%d %H:%M:%S') } self.new_actor = {'name': 'Name', 'age': 42, 'gender': 'M'} # 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 = "trivia_test" self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name) setup_db(self.app, self.database_path) self.new_question = { 'question': 'Who invented the telegraph?', 'answer': 'Samuel Morse', 'difficulty': 3, 'category': 1 } # 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 = "trivia_test" self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name) 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) # create all tables self.db.create_all() self.new_question = { "question": "do you want a car?", "answer": "Yes", "difficulty": 2, "category": 3 }
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_name = "trivia_test" self.database_path = "postgres://*****:*****@#@{}/{}".format( 'localhost:5432', self.database_name) setup_db(self.app, self.database_path) self.new_question = { 'question': 'What is Your Name ?', 'difficulty': 5, 'category': 1, 'answer': 'Mario' } # 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 = "trivia_test" self.database_path = "postgres://{}:{}@{}/{}".format( 'postgres', 'root', 'localhost:5432', self.database_name) setup_db(self.app, self.database_path) self.new_q = { 'question': 'New Test Question ?', 'answer': 'Test Answer', 'difficulty': '1', 'category': '2' } self.duplicate_q = { 'question': 'Test Question 2 ?', 'answer': 'Test Answer', 'difficulty': '1', 'category': '2' } self.search_term = {'searchTerm': 'Test'} self.play = { 'previous_questions': [], 'quiz_category': { 'type': 'click', 'id': 1 } } # 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 = "trivia" self.database_path = "postgres://{}/{}".format( 'localhost:5432', self.database_name) 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) # create all tables self.db.create_all() self.new_question = { 'question': 'What is the capital of Saudi Arabia?', 'answer': 'Riyadh', 'difficulty': 1, 'category': '3' }
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client #self.database_name = "trivia_test" self.database_path = "postgres://*****:*****@localhost:5432/trivia_test" 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) # create all tables self.db.create_all() self.search_term = { 'search_term': 'what' } self.new_question = { 'question': 'Test Question', 'answer': 'Test Answer', 'difficulty': 1, 'category': 1, 'category_name': 'Test Category Name' } self.quiz_options = { 'quiz_category': { 'id': 1, 'type': 'Science'}, 'previous_questions': [] } self.bad_request_new_question = { 'kwestion': 'Test Question', 'answer': 'Test Answer', 'difficulty': 1, 'category': 1, 'category_name': 'Test Category Name' }
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_name = "trivia_test" self.database_path = "postgres://{}:{}@{}/{}".format( 'postgres', 'Pranita123', 'localhost:5432', self.database_name) 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) # create all tables self.db.create_all() self.new_question = { 'question': 'Who is current Prime Minister', 'answer': 'Narendra Modi', 'difficulty': '4', 'category': 1, }
def setUp(self): """Define test variables and initialize app.""" self.app = create_app() self.client = self.app.test_client self.database_name = "trivia_test" self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name) setup_db(self.app, self.database_path) self.new_question = { 'question' : 'How won the US Election 2020?', 'answer' : 'Joe Biden & Kamala Harris', 'diffculty' : '1', 'Category' : '2' } # 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 test_config(): """Test create_app without passing test config.""" assert not create_app().testing assert create_app({'TESTING': True}).testing
def test_config(): assert not create_app().testing assert create_app({'TESTING': True}).testing