Python app.app.test_client() Examples
The following are 29
code examples of app.app.test_client().
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
app.app
, or try the search function
.
Example #1
Source File: test_secscan.py From quay with Apache License 2.0 | 6 votes |
def setUp(self): # Enable direct download in fake storage. storage.put_content(["local_us"], "supports_direct_download", b"true") # Have fake storage say all files exist for the duration of the test. storage.put_content(["local_us"], "all_files_exist", b"true") # Setup the database with fake storage. setup_database_for_testing(self) self.app = app.test_client() self.ctx = app.test_request_context() self.ctx.__enter__() instance_keys = InstanceKeys(app) self.api = SecurityScannerAPI( app.config, storage, app.config["SERVER_HOSTNAME"], app.config["HTTPCLIENT"], uri_creator=get_blob_download_uri_getter( app.test_request_context("/"), url_scheme_and_hostname ), instance_keys=instance_keys, )
Example #2
Source File: test_app.py From Flask-Analytics with The Unlicense | 6 votes |
def test_google_universal(self): self.test_app = app.test_client() response = self.test_app.get('/google-universal/') expected = """<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'iqmbak3kfpdg2N', 'auto'); ga('send', 'pageview'); </script>""" self.assertEquals(response.data, expected.encode('utf8'))
Example #3
Source File: test_app.py From Flask-Analytics with The Unlicense | 6 votes |
def test_google_classic(self): self.test_app = app.test_client() response = self.test_app.get('/google-classic/') expected = """<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'wiengech9tiefuW']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script>""" self.assertEquals(response.data, expected.encode('utf8'))
Example #4
Source File: test_app.py From Flask-Analytics with The Unlicense | 6 votes |
def test_piwik(self): self.test_app = app.test_client() response = self.test_app.get('/piwik/') expected = """<script type="text/javascript"> var _paq = _paq || []; (function(){ var u=(("https:" == document.location.protocol) ? "https://aeniki8pheiFiad/" : "http://aeniki8pheiFiad/"); _paq.push(['setSiteId', 'uiP3eeKie6ohDo6']); _paq.push(['setTrackerUrl', u+'piwik.php']); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); })(); </script>""" self.assertEquals(response.data, expected.encode('utf8'))
Example #5
Source File: test_app.py From Flask-Analytics with The Unlicense | 6 votes |
def test_gosquared(self): self.test_app = app.test_client() response = self.test_app.get('/gosquared/') expected = """<script> !function(g,s,q,r,d){r=g[r]=g[r]||function(){(r.q=r.q||[]).push( arguments)};d=s.createElement(q);q=s.getElementsByTagName(q)[0]; d.src='//d1l6p2sc9645hc.cloudfront.net/tracker.js';q.parentNode. insertBefore(d,q)}(window,document,'script','_gs'); _gs('ahz1Nahqueorahw'); </script>""" self.assertEquals(response.data, expected.encode('utf8'))
Example #6
Source File: test_app.py From Flask-Analytics with The Unlicense | 5 votes |
def test_disabled(self): self.test_app = app.test_client() response = self.test_app.get('/disabled/') expected = "" self.assertEquals(response.data, expected.encode('utf8'))
Example #7
Source File: tests.py From gender-decoder with MIT License | 5 votes |
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()
Example #8
Source File: test_client.py From flask-vuejs-template with MIT License | 5 votes |
def client(): app.config['TESTING'] = True return app.test_client()
Example #9
Source File: test_api.py From flask-vuejs-template with MIT License | 5 votes |
def client(): app.config['TESTING'] = True return app.test_client()
Example #10
Source File: app_tests.py From jardiniot with GNU General Public License v3.0 | 5 votes |
def setUp(self): app.testing = True self.app = app.test_client()
Example #11
Source File: test_ldap.py From quay with Apache License 2.0 | 5 votes |
def setUp(self): setup_database_for_testing(self) self.app = app.test_client() self.ctx = app.test_request_context() self.ctx.__enter__()
Example #12
Source File: test_endpoints.py From quay with Apache License 2.0 | 5 votes |
def setUp(self): setup_database_for_testing(self) self.app = app.test_client() self.ctx = app.test_request_context() self.ctx.__enter__()
Example #13
Source File: test_v1_endpoint_security.py From quay with Apache License 2.0 | 5 votes |
def _test_generator(url, expected_status, open_kwargs, session_var_list): def test(self): with app.test_client() as c: if session_var_list: # Temporarily remove the teardown functions teardown_funcs = [] if None in app.teardown_request_funcs: teardown_funcs = app.teardown_request_funcs[None] app.teardown_request_funcs[None] = [] with c.session_transaction() as sess: for sess_key, sess_val in session_var_list: sess[sess_key] = sess_val # Restore the teardown functions app.teardown_request_funcs[None] = teardown_funcs rv = c.open(url, **open_kwargs) msg = "%s %s: %s expected: %s" % ( open_kwargs["method"], url, rv.status_code, expected_status, ) self.assertEqual(rv.status_code, expected_status, msg) return test
Example #14
Source File: test_app.py From Flask-Analytics with The Unlicense | 5 votes |
def test_chartbeat(self): self.test_app = app.test_client() response = self.test_app.get('/chartbeat/') expected = """<script type="text/javascript"> var _sf_async_config={}; /** CONFIGURATION START **/ _sf_async_config.uid = "uiP3eeKie6ohDo6"; /** CHANGE THIS **/ _sf_async_config.domain = "eeda8Otheefu5qu"; /** CHANGE THIS **/ /** CONFIGURATION END **/ (function(){ function loadChartbeat() { window._sf_endpt=(new Date()).getTime(); var e = document.createElement("script"); e.setAttribute("language", "javascript"); e.setAttribute("type", "text/javascript"); e.setAttribute('src', '//static.chartbeat.com/js/chartbeat.js'); document.body.appendChild(e); } var oldonload = window.onload; window.onload = (typeof window.onload != "function") ? loadChartbeat : function() { oldonload(); loadChartbeat(); }; })(); </script>""" self.assertEquals(response.data, expected.encode('utf8'))
Example #15
Source File: test_user.py From passhport with GNU Affero General Public License v3.0 | 5 votes |
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:' self.app = app.test_client() db.drop_all() db.create_all()
Example #16
Source File: test_app.py From Flask-Analytics with The Unlicense | 5 votes |
def test_none(self): self.test_app = app.test_client() response = self.test_app.get('/none/') expected = "" self.assertEquals(response.data, expected.encode('utf8'))
Example #17
Source File: flask_test.py From Cloud-Native-Python with MIT License | 5 votes |
def setUp(self): # creates a test client self.app = app.test_client() # propagate the exceptions to the test client self.app.testing = True
Example #18
Source File: flask_test.py From Cloud-Native-Python with MIT License | 5 votes |
def setUp(self): # creates a test client self.app = app.test_client() # propagate the exceptions to the test client self.app.testing = True
Example #19
Source File: flask_test.py From Cloud-Native-Python with MIT License | 5 votes |
def setUp(self): # creates a test client self.app = app.test_client() # propagate the exceptions to the test client self.app.testing = True
Example #20
Source File: __init__.py From the-example-app.py with MIT License | 5 votes |
def setUp(self): I18n(app) app.testing = True self.app = app.test_client()
Example #21
Source File: testing.py From Flask-PostgreSQL-API-Seed with MIT License | 5 votes |
def setUp(self): app.config['TESTING'] = True app.config['DEBUG'] = True self.app = app.test_client() db.create_all()
Example #22
Source File: utils.py From contentdb with GNU General Public License v3.0 | 5 votes |
def client(): app.config["TESTING"] = True recreate_db() assert User.query.count() == 1 with app.test_client() as client: yield client app.config["TESTING"] = False
Example #23
Source File: test_app.py From simple-math-flask with MIT License | 5 votes |
def setUp(self): app.testing = True self.app = app.test_client()
Example #24
Source File: app-test.py From learning-python with MIT License | 5 votes |
def setUp(self): """Set up a blank temp database before each test""" basedir = os.path.abspath(os.path.dirname(__file__)) app.config['TESTING'] = True app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(basedir, TEST_DB) self.app = app.test_client() db.create_all()
Example #25
Source File: app-test.py From learning-python with MIT License | 5 votes |
def test_index(self): """inital test. ensure flask was set up correctly""" tester = app.test_client(self) response = tester.get('/', content_type='html/text') self.assertEqual(response.status_code, 200)
Example #26
Source File: test_todo.py From learning-python with MIT License | 5 votes |
def setUp(self): self.app = app.test_client()
Example #27
Source File: test_user.py From passhport with GNU Affero General Public License v3.0 | 5 votes |
def setup_class(cls): """Initialize configuration and create an empty database before testing """ app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///:memory:" cls.app = app.test_client() db.create_all()
Example #28
Source File: test_target.py From passhport with GNU Affero General Public License v3.0 | 5 votes |
def setup_class(cls): """Initialize configuration and create an empty database before testing """ app.config["TESTING"] = True app.config["WTF_CSRF_ENABLED"] = False app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:"# /" + \ # os.path.join("/tmp/", "test.db") cls.app = app.test_client() db.create_all()
Example #29
Source File: test_v2_endpoint_security.py From quay with Apache License 2.0 | 4 votes |
def _test_generator(url, test_spec, attrs): def test(self): with app.test_client() as c: headers = [] expected_index_status = getattr(test_spec, attrs["result_attr"]) if attrs["auth_username"]: # Get a signed JWT. username = attrs["auth_username"] password = "password" jwt_scope = test_spec.get_scope_string() query_string = ( "service=" + app.config["SERVER_HOSTNAME"] + "&scope=" + jwt_scope ) arv = c.open( "/v2/auth", headers=[("authorization", test_spec.gen_basic_auth(username, password))], query_string=query_string, ) msg = "Auth failed for %s %s: got %s, expected: 200" % ( test_spec.method_name, test_spec.index_name, arv.status_code, ) self.assertEqual(arv.status_code, 200, msg) headers = [("authorization", "Bearer " + json.loads(arv.data)["token"])] rv = c.open(url, headers=headers, method=test_spec.method_name) msg = "%s %s: got %s, expected: %s (auth: %s | headers %s)" % ( test_spec.method_name, test_spec.index_name, rv.status_code, expected_index_status, attrs["auth_username"], len(headers), ) self.assertEqual(rv.status_code, expected_index_status, msg) return test