def setUp(self): self.app = app self.client = app.test_client() self.user = { 'username': self.TEST_USERNAME, 'password': self.TEST_PASSWORD }
def test_index_page(mock_connect): expected = [{'id': 1, 'name': 'foo'}, {'id': 2, 'name': 'bar'}] mock_connect.return_value.cursor.return_value.fetchall.return_value = expected app.testing = True test_auth_header = {'X-Forwarded-User': '******'} with app.test_client() as c: rv = c.get(headers=test_auth_header, path='/') assert b'core-content-container' in rv.data and rv.status_code == 200
def client(request): test_client = app.test_client() def teardown(): pass request.addfinalizer(teardown) return test_client
def test_saml_groups(): app.testing = True test_auth_header = { 'X-Forwarded-User': '******', 'X-Forwarded-Groups': 'group1:group2' } with app.test_client() as c: rv = c.get(headers=test_auth_header, path='/item/1') assert b'This is item id' in rv.data and rv.status_code == 200
def setUp(self): app.config.from_object('config') app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False #the basedir lines could be added like the original db app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db' self.app = app.test_client() db.create_all() pass
def setUp(self): # Make sure that database exists app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' with app.app_context(): db.init_app(app) db.create_all() self.app = app.test_client() self.app_context = app.app_context
def client(): from flask_app import app app.config["SERVER_NAME"] = "example.com" app.config["TESTING"] = True client = app.test_client() # Establish an application context before running the tests. ctx = app.app_context() ctx.push() yield client # this is where the testing happens! ctx.pop()
def test_app(): '''Uses ``app`` imported from flask_app to create a testable Flask application. :yield: Flask application with a context, ready for testing ''' # Uses global variable "app" app.config['TESTING'] = True test_app = app.test_client() ctx = app.app_context() ctx.push() yield test_app ctx.pop()
def client(request): """ Creates the test client """ client = app.test_client() app.config.from_pyfile("config/testing.py") # Update celery app config for testing current_app.conf.update(app.config) # Add email and password as globals for easy ref. global EMAIL EMAIL = app.config["TEST_EMAIL"] global PASSWORD PASSWORD = app.config["TEST_PASSWORD"] # Initialize db and add a test user create_db() user_datastore.create_user(email=EMAIL, password=PASSWORD) db.session.commit() return client
def test_alphabet_checker_page(): response = app.test_client().get('/alphabet-checker') assert response.status_code == 200 assert "input" in str(response.data)
def test_alphabet_checker_api_true_input(): response = app.test_client().get( '/api/alphabet-checker?input=The quick brown fox jumps over the lazy dog' ) assert response.status_code == 200 assert response.data == b'{"input": "The quick brown fox jumps over the lazy dog", "result": true}'
def setUp(self): self.app = app.test_client()
def test_home(self): tester = app.test_client(self) response = tester.get('/', content_type='html/text') self.assertEqual(response.status_code, 200)
def setUp(self): self.tester = app.test_client()
def setUpClass(self): self.app = app.test_client()
def test_home(self): tester = app.test_client(self) response = tester.get("/home") status_code = response.status_code self.assertEqual(status_code, 200)
def test_index(self): """initial test. ensure flask was set up correctly""" tester = app.test_client(self) response = tester.get('/api/v1/posts', content_type='application/json') self.assertEqual(response.status_code, 200) self.assertEqual(type(response.data),type('qwerty'))
import os import sys sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))) from flask_app import app api = app.test_client() def test_hello(): response = api.get('/') assert response.status_code == 200 assert response.data == b'Hello!' def test_get_kospi(): response = api.get(f'/finance/kospi') assert response.status_code == 200
def test_alphabet_checker_api_no_input(): response = app.test_client().get('/api/alphabet-checker') assert response.status_code == 400 assert "Bad Request" in str(response.data)
def setUp(self): app.config['DATABASE'] = tempfile.mkstemp() app.testing = True self.client = app.test_client() self.endpoint = "/predict"
def test_alphabet_checker_api_has_input(): response = app.test_client().get('/api/alphabet-checker?input=abc') assert response.status_code == 200
def test_emoji_input(): response = app.test_client().get('/api/alphabet-checker?input=😀') result = json.loads(response.data) assert response.status_code == 200 assert result["input"] == '😀' assert result["result"] == False
def test_404(): response = app.test_client().get('/chicken') assert response.status_code == 404
def setUp(self): self.db = data_access.Database() self.db.create_database() self.test_client = app.test_client()
def setUp(self): self.db_fd, app.config['DATABASE'] = tempfile.mkstemp() app.config['TESTING'] = True self.app = app.test_client() db.create_all()
def test_home_loads(self): tester = app.test_client(self) response = tester.get("/home", content_type="html/text") self.assertTrue(b'Dashboard' in response.data)
def test_api_health_check(): with app.test_client() as c: rv = c.get(path='/api/healthz') assert b'{"pass":true}' in rv.data and rv.status_code == 200
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'flask_app/db/flask.db') self.app = app.test_client() db.create_all()
def test_item_page_401(): with app.test_client() as c: rv = c.get(path='/item/1') assert rv.status_code == 401
def test_other(self): tester = app.test_client(self) response = tester.get('a', content_type='html/text') self.assertEqual(response.status_code, 404)
def test_item_page(): app.testing = True test_auth_header = {'X-Forwarded-User': '******'} with app.test_client() as c: rv = c.get(headers=test_auth_header, path='/item/1') assert b'This is item id' in rv.data and rv.status_code == 200
def test_hello(): response = app.test_client().get('/hello') assert response.status_code == 200 assert response.data == b'Hello from Martin!'
def test_db_down(): app.testing = True test_auth_header = {'X-Forwarded-User': '******'} with app.test_client() as c: rv = c.get(headers=test_auth_header, path='/') assert b'Unable to connect to database' in rv.data and rv.status_code == 500
def test_health_check(): with app.test_client() as c: rv = c.get(path='/healthz') assert b'OK' in rv.data and rv.status_code == 200
def test_alphabet_checker_api_false_input(): response = app.test_client().get('/api/alphabet-checker?input=abccd12') assert response.status_code == 200 assert response.data == b'{"input": "abccd12", "result": false}'