def make_shell(): """Interactive Flask Shell""" from flask import request from hello import init_db as initdb app = make_app() http = app.test_client() reqctx = app.test_request_context return locals()
def test_app(): # get main page response = app.test_client().get('/') # test if status code 200 is returned assert response.status_code == 200 # test if we get "Hello World!" assert response.data == b'Hello, World!'
def setUp(self): app.config.update( TESTING=True, WTF_CSRF_ENABLED=False, SQLALCHEMY_DATABASE_URI='sqlite:///:memory:' ) db.create_all() self.client = app.test_client() self.runner = app.test_cli_runner()
def test_empty_username_password(self): print("test_empty_username_password") """when param loss some value,then return status code=65535 message]""" response = app.test_client().post('/addrec', data={}) print("response",response) json_data = response.data print(json_data) json_dict = json.loads(json_data) self.assertEqual(json_dict['code'], 65536, 'data erro')
def test_storage(up, down): with app.test_client() as client, requests_mock.Mocker() as mocker: mocker.post(E2EMONITORING_URL, text='resp') assert len(storage) == 0 client.post('/add', query_string=up) client.post('/add', query_string=down) client.post('/add', query_string=up) assert len(storage) == 3 client.get('/flush/2') assert len(storage) == 2
def test_hello(): """ Path root returns flask-example app and 'Hello, World' """ response = app.test_client().get('/') assert response.status_code == 200 assert response.data == b'Hello, World!'
def test_home(): tester = app.test_client() response = tester.get('/', content_type='html/text') assert response.status_code == 200 assert b'Hello World!' in response.data
def test_other(): tester = app.test_client() response = tester.get('a', content_type='html/text') assert response.status_code == 404 assert b'does not exist' in response.data
def test_pages(self): tester = app.test_client(self) pages = ['/', 'about', 'register', 'login'] for page in pages: response = tester.get(page, content_type='html/text') self.assertEqual(response.status_code, 200)
def test_hello(): # this merely is to validate the test environment response = app.test_client().get('/') assert response.status_code == 200 assert response.data == b'Hello, World!'
def test_post(self): self.test_app = app.test_client() response = self.test_app.get('/', content_type='html/text') self.assertEqual(response.status_code, 200)
def test_home(self): tester = app.test_client(self) response = tester.get('/', content_type='html/text') self.assertEqual(response.status_code, 200) self.assertEqual(response.data, b'Hello World')
def test_flask_simple(): app.config['TESTING'] = True client = app.test_client() result = client.get('/') assert b'Hello World' == result.data
def setUp(self): self.app = app.test_client()
def setUp(self): #setup flask self.app = app.test_client() self.app.testing = True pass
from hello import app import json testapp = app.test_client() def test_index(): response = testapp.get('/') assert response.status_code == 200 assert b'Bienvenido seas.' in response.data def test_ajax(): response = testapp.post('/api/visitors', data=json.dumps({'name': "Jose"}), content_type='application/json') assert response.status_code == 200 assert b'Jose' in response.data
def setUp(self): self.app = app.test_client() self.app.testing = True
def client(): client = app.test_client() return client
def client(): return app.test_client()
def setUp(self): # create a test client self.app = app.test_client() self.app.testing = True
def setUp(self): app.testing = True self.client = app.test_client()
def test_other(self): tester = app.test_client(self) response = tester.get('a', content_type='html/text') self.assertEqual(response.status_code, 404) self.assertTrue(b'does not exist' in response.data)
from hello import app with app.test_client() as c: response = c.get('/') assert response.data == b'Hello World!' assert response.status_code == 200 print("Test Passed")
def test_other_page(self): tester = app.test_client(self) response = tester.get('test', content_type='html/text') self.assertEqual(response.status_code, 404)
def test_hello(): response = app.test_client().get('/') assert response.status_code == 200 assert response.data == b'Hello, World!'
def test_response(): """Start with a blank database.""" client = app.test_client() rv = client.get('/') assert b'Hello from Kubernetes!' in rv.data