Python main.app() Examples
The following are 30
code examples of main.app().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
main
, or try the search function
.
Example #1
Source File: pullcounter_test.py From python-docs-samples with Apache License 2.0 | 7 votes |
def test_app(testbed): key_name = 'foo' testbed.init_taskqueue_stub(root_path=os.path.dirname(__file__)) app = webtest.TestApp(main.app) app.post('/', {'key': key_name}) tq_stub = testbed.get_stub(gaetestbed.TASKQUEUE_SERVICE_NAME) tasks = tq_stub.get_filtered_tasks() assert len(tasks) == 1 assert tasks[0].name == 'task1' with mock.patch('main.update_counter') as mock_update: # Force update to fail, otherwise the loop will go forever. mock_update.side_effect = RuntimeError() app.get('/_ah/start', status=500) assert mock_update.called
Example #2
Source File: main_test.py From getting-started-python with Apache License 2.0 | 7 votes |
def firestore(): import firestore """This fixture provides a modified version of the app's Firebase model that tracks all created items and deletes them at the end of the test. Any tests that directly or indirectly interact with the database should use this to ensure that resources are properly cleaned up. """ # Ensure no books exist before running the tests. This typically helps if # tests somehow left the database in a bad state. delete_all_books(firestore) yield firestore # Delete all books that we created during tests. delete_all_books(firestore)
Example #3
Source File: main_test.py From getting-started-python with Apache License 2.0 | 6 votes |
def test_upload_image(app): data = { 'title': 'Test Book', 'author': 'Test Author', 'publishedDate': 'Test Date Published', 'description': 'Test Description', 'image': (BytesIO(b'hello world'), 'hello.jpg') } with app.test_client() as c: rv = c.post('books/add', data=data, follow_redirects=True) assert rv.status == '200 OK' body = rv.data.decode('utf-8') img_tag = re.search('<img.*?src="(.*)"', body).group(1) r = requests.get(img_tag) assert r.status_code == 200 assert r.text == 'hello world'
Example #4
Source File: main_test.py From getting-started-python with Apache License 2.0 | 6 votes |
def test_add(app): data = { 'title': 'Test Book', 'author': 'Test Author', 'publishedDate': 'Test Date Published', 'description': 'Test Description' } with app.test_client() as c: rv = c.post('books/add', data=data, follow_redirects=True) assert rv.status == '200 OK' body = rv.data.decode('utf-8') assert 'Test Book' in body assert 'Test Author' in body assert 'Test Date Published' in body assert 'Test Description' in body
Example #5
Source File: main_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def test_app(main): app = webtest.TestApp(main.app) response = app.get('/') assert response.status_int == 200 assert re.search( re.compile(r'.*version.*', re.DOTALL), response.body)
Example #6
Source File: main_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def test_request_id(testbed): app = webtest.TestApp(main.app) os.environ['REQUEST_LOG_ID'] = '1234' response = app.get('/requestid') assert response.headers['Content-Type'] == 'text/plain' assert '1234' in response.body
Example #7
Source File: main_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def test_timer(testbed): app = webtest.TestApp(main.app) with mock.patch('main.time.sleep') as sleep_mock: sleep_mock.side_effect = DeadlineExceededError() app.get('/timer', status=500) assert sleep_mock.called
Example #8
Source File: main_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def test_url_post(urlfetch_mock, app): urlfetch_mock.fetch = mock.Mock( return_value=mock.Mock(content='Albert', status_code=200)) response = app.get('/url_post') assert 'Albert' in response.body
Example #9
Source File: main_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def test_url_fetch(app): response = app.get('/url_fetch') assert 'Google' in response.body
Example #10
Source File: main_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def test_url_lib(app): response = app.get('/') assert 'Google' in response.body
Example #11
Source File: main_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def app(testbed): return webtest.TestApp(main.app)
Example #12
Source File: main_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def test_get(testbed): main.BUCKET_NAME = PROJECT app = webtest.TestApp(main.app) response = app.get('/') assert response.status_int == 200 assert 'The demo ran successfully!' in response.body
Example #13
Source File: main_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def test_get(): app = webtest.TestApp(main.app) response = app.get('/') assert response.status_int == 200 assert response.body == 'Hello, World!'
Example #14
Source File: main_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def app(testbed): yield webtest.TestApp(main.app)
Example #15
Source File: main_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def test_app(testbed): app = webtest.TestApp(main.app) response = app.get('/') assert response.status_int == 200
Example #16
Source File: main_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def test_get(app): response = app.get('/') assert response.status_int == 200
Example #17
Source File: main_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def app(): return webtest.TestApp(main.app)
Example #18
Source File: main_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def test_app(testbed): app = webtest.TestApp(main.app) response = app.get('/') assert response.status_int == 200
Example #19
Source File: main_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def test_blobreader(testbed, login): app = webtest.TestApp(main.app) response = app.get('/blobreader') assert 'abcde\nabc\nabcde\n' in response
Example #20
Source File: main_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def test_app(app): response = app.get('/') assert response.status_int == 200
Example #21
Source File: main_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def test_add_entities(app): response = app.post('/add_entities') assert response.status_int == 200 response = app.get('/') assert response.status_int == 200 assert 'Author: Bob' in response.body assert 'Name: Sunrise' in response.body assert 'Author: Alice' in response.body assert 'Name: Sunset' in response.body
Example #22
Source File: util.py From love with MIT License | 5 votes |
def get_test_app(): def test_loader(app): return load_themes_from(os.path.join(os.path.dirname(__file__), '../themes/')) Themes(main.app, app_identifier='yelplove', loaders=[test_loader]) return TestApp(main.app)
Example #23
Source File: util.py From love with MIT License | 5 votes |
def addCsrfTokenToSession(self): csrf_token = 'MY_TOKEN' with self.app.session_transaction() as session: session['_csrf_token'] = csrf_token return csrf_token
Example #24
Source File: conftest.py From bitcart with MIT License | 5 votes |
def client(): with TestClient(app) as client: yield client
Example #25
Source File: conftest.py From bitcart with MIT License | 5 votes |
def async_client(): async with AsyncClient(app) as client: yield client
Example #26
Source File: main_test.py From getting-started-python with Apache License 2.0 | 5 votes |
def app(request): """This fixture provides a Flask app instance configured for testing. It also ensures the tests run within a request context, allowing any calls to flask.request, flask.current_app, etc. to work.""" app = main.app with app.test_request_context(): yield app
Example #27
Source File: main_test.py From getting-started-python with Apache License 2.0 | 5 votes |
def test_list(app, firestore): for i in range(1, 12): firestore.create({'title': u'Book {0}'.format(i)}) with app.test_client() as c: rv = c.get('/') assert rv.status == '200 OK' body = rv.data.decode('utf-8') assert 'Book 1' in body, "Should show books" assert len(re.findall('<h4>Book', body)) <= 10, ( "Should not show more than 10 books") assert 'More' in body, "Should have more than one page"
Example #28
Source File: main_test.py From getting-started-python with Apache License 2.0 | 5 votes |
def test_edit(app, firestore): existing = firestore.create({'title': "Temp Title"}) with app.test_client() as c: rv = c.post( 'books/%s/edit' % existing['id'], data={'title': 'Updated Title'}, follow_redirects=True) assert rv.status == '200 OK' body = rv.data.decode('utf-8') assert 'Updated Title' in body assert 'Temp Title' not in body
Example #29
Source File: main_test.py From getting-started-python with Apache License 2.0 | 5 votes |
def test_upload_bad_file(app): data = { 'title': 'Test Book', 'author': 'Test Author', 'publishedDate': 'Test Date Published', 'description': 'Test Description', 'image': (BytesIO(b'<?php phpinfo(); ?>'), '1337h4x0r.php') } with app.test_client() as c: rv = c.post('/books/add', data=data, follow_redirects=True) # check we weren't pwned assert rv.status == '400 BAD REQUEST'
Example #30
Source File: test.py From NoseGAE with BSD 2-Clause "Simplified" License | 5 votes |
def test_index(): response = app.get('/') assert 'Hello world!' in str(response) eq_(1, 1, "Math is weird on your planet")