def setUp(self): app.config['TESTING'] = True app.config['CSRF_ENABLED'] = False #app.config['SECRET_KEY'] = 'my_precious' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db' self.app = app.test_client() db.create_all()
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(basedir, TEST_DB) self.app = app.test_client() db.create_all()
def test_post_show_up(self): tester = app.test_client(self) response = tester.post( '/login', data = dict(username="******", password="******"), follow_redirects = True ) self.assertIn(b'Hello from the shell', response.data)
def test_correct_login(self): tester = app.test_client(self) response = tester.post( '/login', data = dict(username="******", password="******"), follow_redirects = True ) self.assertIn(b'You were logged in.', response.data)
def test_logout(self): tester = app.test_client(self) tester.post('/login', data=dict(username='******',password='******'), follow_redirects=True ) response = tester.get('/logout', follow_redirects=True) self.assertIn(b'You were just logged out', response.data)
def setUp(self): # executes prior to each test app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + TEST_DB app.config['DEBUG'] = False self.app = app.test_client() db.create_all()
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_PATH'] = 'sqlite:///' + os.path.join(basedir, TEST_DB) self.app = app.test_client() db.create_all() self.assertEquals(app.debug, False)
def setUp(self): app.config['TESTING'] = True app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(basedir, TEST_DB) self.app = app.test_client() db.create_all() self.assertEquals(app.debug, False)
def test_incorrect_login(self): tester = app.test_client(self) response = tester.post( '/login', data = dict(username="******", password="******"), follow_redirects = True ) self.assertIn(b'Invalid Credentials', response.data)
def setUp(self): app.config.from_object('config.TestConfig') self.client = app.test_client() db.create_all() user = User("admin", "*****@*****.**", "admin") db.session.add(user) db.session.add( BlogPosts("Test post", "This is a test. Only a test.", user.id)) db.session.commit()
def setUp(self): app.config["TESTING"] = True app.config["WTF_CSRF_ENABLED"] = False app.config["DEBUG"] = False app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, TEST_DB) self.app = app.test_client() db.create_all() self.assertEquals(app.debug, False)
def app(): """session wide Flask application""" settings_override = { 'DEBUG': False, 'TESTING': True, 'WTF_CSRF_ENABLED': False, 'SQLALCHEMY_DATABASE_URI': TEST_DB_URI } _app.config.from_object(settings_override) return _app.test_client()
def app(): """session wide Flask application""" settings_override = { 'DEBUG': False, 'TESTING': True, 'WTF_CSRF_ENABLED': False, 'SQLALCHEMY_DATABASE_URI': TEST_DB_URI } _app.config.from_object(settings_override) return _app.test_client()
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.sqlite' self.app = app.test_client() db.drop_all() db.create_all() self.assertEqual(app.debug, False)
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(basedir, TEST_DB) self.app = app.test_client() db.create_all() self.assertEquals(app.debug, False)
def setUp(self): app.config["TESTING"] = True # VERY IMPORTANT TO DISABLE!!! app.config["WTF_CSRF_ENABLED"] = False app.config["DEBUG"] = False app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, TEST_DB) self.app = app.test_client() db.create_all() self.assertEqual(app.debug, False)
def setUp(self): """ Executing prior to each tasks. Create environnement where tests while be executing. """ app.config.from_object('project._config.TestConfig') self.app = app.test_client() db.create_all() self.assertEquals(app.debug, False)
def test_post_invalid_position(self): tester = app.test_client(self) res = self.app.post('/api/v1/applicants', data=json.dumps( dict(school='VCU', position='cat caller', degree='eyesight')), content_type='application/json', follow_redirects=True) self.assertEqual(res.status_code, 400)
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(app.config['BASEDIR'], TEST_DB) self.app = app.test_client() with app.app_context(): db.create_all() mail.init_app(app) self.assertEquals(app.debug, False)
def setUp(self): """Executed prior to each test.""" app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(basedir, TEST_DB) self.app = app.test_client() db.create_all() self.assertEquals(app.debug, False)
def setUp(self): """ Executing prior to each tasks. Create environnement where tests while be executing. """ app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(basedir, TEST_DB) self.app = app.test_client() db.create_all()
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://localhost/test' self.app = app.test_client() db.drop_all() db.create_all() mail.init_app(app) self.assertEqual(app.debug, False)
def test_post_app1(self): tester = app.test_client(self) res = self.app.post('/api/v1/applicants', data=json.dumps( dict(first_name='bar', last_name="Kirtfield", school='VCU', position='dev intern', degree='eyesight')), content_type='application/json', follow_redirects=True) self.assertEqual(res.status_code, 201)
def test_wrong_method_put_in_get(self): tester = app.test_client(self) res = self.app.put('/api/v1/applicants', data=json.dumps( dict(first_name='bar', last_name="Kirtfield", school='VCU', position='dev engineer', degree='eyesight')), content_type='application/json', follow_redirects=True) self.assertEqual(res.status_code, 405)
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.sqlite' self.app = app.test_client() db.drop_all() db.create_all() # Disable sending emails during unit testing ma.init_app(app) self.assertEqual(app.debug, False)
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join( 'testcode-db.db') self.app = app.test_client() db.drop_all() db.create_all() mail.init_app(app) self.assertEqual(app.debug, False)
def test_post_route__failure__bad_request(): client = app.test_client() url = '/post/test' mock_request_headers = {'authorization-sha256': '123'} mock_request_data = {} response = client.post(url, data=json.dumps(mock_request_data), headers=mock_request_headers) assert response.status_code == 400
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join( basedir, TEST_DB) self.app = app.test_client() db.create_all() self.assertEquals(app.debug, False) register(self, 'Michael', '*****@*****.**', 'python', 'python')
def setUp(self): self.app.config['TESTING'] = True self.app.config['WTF_CSRF_ENABLED'] = False self.app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join( basedir, self.TEST_DB) self.app.config['DEBUG'] = False self.app = app.test_client() self.db.create_all() self.assertEquals(app.config['DEBUG'], False, msg='App cannot run in production with debug mode.')
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['MONGO_URI'] = 'monogodb://localhost' + \ os.path.join(app.config['BASEDIR'], TEST_DB) self.app = app.test_client() db.drop_all() db.create_all() mail.init_app(app) self.assertEqual(app.debug, False)
def setUp(self): """Set up.""" app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(basedir, TEST_DB) self.app = app.test_client() db.create_all() # Make sure we are testing in production mode self.assertEquals(app.debug, False)
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///" + \ os.path.join(basedir, TEST_DB) self.app = app.test_client() db.create_all() self.assertEqual(app.debug, False) self.register('michael', '*****@*****.**', 'michaelherman', 'michaelherman') self.login('michael', 'michaelherman')
def setUp(self): """TODO: Docstring for setup. :returns: TODO """ app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(BASE_DIR, TEST_DB) self.app = app.test_client() db.create_all() self.assertEquals(app.debug, False)
def testUpdateUser3(self): with app.test_client() as client: data = { "uid": "111111BE8m70phdEeRtvjN38bNGEDfhHV2", "email": "*****@*****.**", "dob": "1998-10-18", "fullname": "Hiếu Lương", "is_vegetarian": False, "avatar": "https://graph.facebook.com/1332042503669281/picture" } res = client.put(DEFAULT_PATH.format('/user'), data=json.dumps(data), headers=AUTH_HEADERS) self.assertEqual(402, res.status_code)
def setUp(self): # 更新配置 app.config.update(TESTING=True, SQLALCHEMY_DATABASE_URL='sqlte:///:memory:') db.create_all() user = User(username='******', name='Test') user.set_password('123456') movie = Movie(title='test mvoie', year='2020') db.session.add_all([user, movie]) db.session.commit() self.client = app.test_client() # 测试客户端 self.runner = app.test_cli_runner() # 创建测试命令运行器
def testRatingSurvey1(self): with app.test_client() as client: data = { "rating": [{ "meta_tag_id": 1, "tag_ids": [4221, 4503] }, { "meta_tag_id": 2, "tag_ids": [4222, 4224] }] } res = client.post(DEFAULT_PATH.format('/rating'), data=json.dumps(data), headers=AUTH_HEADERS) self.assertEqual(201, res.status_code)
def setUp(self): """ Executing prior to each tasks. Create environnement where tests while be executing. Start server without the debug mode. """ app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(basedir, TEST_DB) self.app = app.test_client() db.create_all() self.assertEquals(app.debug, False)
def client(): db_fd, app.config['DATABASE'] = tempfile.mkstemp() app.config['TESTING'] = True client = app.test_client() with app.app_context(): # Drop all of the existing database tables db.drop_all() # create the database and the database table db.create_all() yield client print("client end") os.close(db_fd) os.unlink(app.config['DATABASE'])
def setUp(self): app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db' self.app = app.test_client() db.create_all() game1 = game_info(game_name="test1_name", game_description="test1_desc", user="******", Tickets=1) game2 = game_info(game_name="test2_name", game_description="test2_desc", user="******", Tickets=2) db.session.add(game1) db.session.add(game2) db.session.commit()
def app(request): # `TESTING` set to True, `DEBUG` to False, # `SQLALCHEMY_DATABASE_URI` leading to testing postgres database _app.config.from_pyfile('testing_config.py') # Not using SQLite for testing, because there are problems with # summing timedelta. test_client = _app.test_client() ctx = _app.app_context() ctx.push() def teardown(): ctx.pop() request.addfinalizer(teardown) return test_client
def test_post_route__success(): client = app.test_client() url = '/post/test' mock_request_headers = {'authorization-sha256': '123'} mock_request_data = { 'request_id': '123', 'payload': { 'py': 'pi', 'java': 'script' } } response = client.post(url, data=json.dumps(mock_request_data), headers=mock_request_headers) assert response.status_code == 200
def test_post_route__failure__unauthorized(): client = app.test_client() url = '/post/test' mock_request_headers = {} mock_request_data = { 'request_id': '123', 'payload': { 'py': 'pi', 'java': 'script' } } response = client.post(url, data=json.dumps(mock_request_data), headers=mock_request_headers) assert response.status_code == 401
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False # app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ # os.path.join(app.config['BASEDIR'], TEST_DB) self.app = app.test_client() self.app.post('/api/v1/applicants', data=json.dumps( dict(first_name='bar', last_name="Kirtfield", school='VCU', position='dev intern', degree='eyesight')), content_type='application/json', follow_redirects=True) self.app.post('/api/v1/applicants', data=json.dumps( dict(first_name='Ryan', last_name="Kirtfield", school='Penn State', position='dev intern', degree='mathematics')), content_type='application/json', follow_redirects=True) self.app.post('/api/v1/applicants', data=json.dumps( dict(first_name='Little', last_name="John", school='VT', position='dev intern', degree='Health')), content_type='application/json', follow_redirects=True) self.app.post('/api/v1/applicants', data=json.dumps( dict(first_name='Lion', last_name="Welsh", school='Harvard', position='dev intern', degree='good')), content_type='application/json', follow_redirects=True)
def setUp(self) -> None: """ Setup method that runs before each test """ # Overriding flask app settings app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['WTF_CSRF_CHECK_DEFAULT'] = False # Using local sqlite db instead of the one used in the project db_path = os.path.join(basedir, 'tests', 'db_test.sqlite') if os.path.exists(db_path): os.remove(db_path) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + db_path db.create_all() populate_departments() populate_employees() # Creating client for making requests self.client = app.test_client()
def test_add_recipe(self): self.register_user() app_client = app.test_client() app_client.post('/register', data=dict(email='*****@*****.**', password='******', confirm='FlaskIsAwesome'), follow_redirects=True) app_client.post('/login', data=dict(email='*****@*****.**', password='******'), follow_redirects=True) response = app_client.post('/add', buffered=True, content_type='multipart/form-data', data={'recipe_title': 'Local Dev2', 'recipe_description': 'Setup Dev Laptop With Ease', 'recipe_type': 'Ops', 'recipe_steps': 'Step 1 Step 2 Step 3', 'recipe_ingredients': 'Bits & Bytes', 'recipe_inspiration': 'http://www.redhat.com/', 'recipe_image': (BytesIO(b'my file contents'), 'image001.jpg')}, follow_redirects=True) self.assertIn(b'New recipe, Local Dev2, added!', response.data)
def test_edit_recipe_fields(self): self.add_recipes() app_client = app.test_client() app_client.post('/login', data=dict(email='*****@*****.**', password='******'), follow_redirects=True) response = app_client.get('/edit/3', follow_redirects=True) self.assertIn(b'Edit Recipe', response.data) self.assertIn(b'Tacos', response.data) response = app_client.post('/edit/3', buffered=True, content_type='multipart/form-data', data={ 'recipe_title': 'Tacos2', 'recipe_description': 'Ground beef tacos', 'recipe_type': 'Lunch', 'recipe_public': 'True', 'recipe_rating': '8', 'recipe_steps': 'Step 1 Step 2 Step 3', 'recipe_ingredients': 'Ingredient #1 Ingredient #2', 'recipe_inspiration': 'http://www.foodnetwork.com/blaa', 'recipe_dairy_free': 'True', 'recipe_soy_free': 'True', 'recipe_image': (BytesIO(b'my file contents'), 'image001.jpg') }, follow_redirects=True) self.assertIn(b'Recipe has been updated for Tacos2.', response.data)
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False self.app = app.test_client()
def test_index(self): tester = app.test_client(self) response = tester.get('/login', content_type='html/text') self.assertEqual(response.status_code, 200)
def testDeleteHistory(self): with app.test_client() as client: res = client.delete(DEFAULT_PATH.format('/history/10'), headers=AUTH_HEADERS) self.assertEqual(401, res.status_code)