def test_crossorigin_unavailable(monkeypatch): import app.app monkeypatch.setattr(app.app, "crossorigin_available", False) with pytest.raises(ImportError): configure(cors_enabled=True) create_app()
def test_config_override(): configure() assert settings.get("APP_NAME") == "app" configure(app_name="new_name") assert settings.get("APP_NAME") == "new_name"
def test_crossorigin_enabled(): configure(cors_enabled=True) app = create_app() assert ( app._middleware[2][0].__func__ == falcon_crossorigin.CrossOrigin.process_response )
def test_configure(): os.environ[ "REDIS_SENTINEL_HOST"] = "10.128.0.226,10.129.3.16,10.130.0.135,10.130.0.13,10.129.0.135" os.environ["REDIS_SENTINEL_PORT"] = "8001" os.environ["REDIS_PASSWORD"] = "******" os.environ["REDIS_DBNAME"] = "bdb-test" app.configure() assert app.app.config['REDIS_URL'] == "redis+sentinel://:[email protected]:8001," \ "10.129.3.16:8001,10.130.0.135:8001,10.130.0.13:8001,10.129.0.135:8001" \ "/bdb-test/0"
def configure(): # ... # main.py import app import dialog app.configure() dialog.configure() dialog.show()
def test_vcap_configure(): os.environ = dict() os.environ["VCAP_SERVICES"] = """{ "redislabs": [ { "label": "redislabs", "provider": null, "plan": "medium-redis", "name": "redis-webcli-service-NRY6IA75", "tags": [ "redislabs", "redis" ], "instance_name": "redis-webcli-service-NRY6IA75", "binding_name": null, "credentials": { "host": "redis-1071.c1.sys.testpcfb7d42.qa.redislabs.com", "sentinel_addrs": ["10.128.0.226","10.129.3.16","10.130.0.135","10.130.0.13","10.129.0.135"], "sentinel_port": 8001, "ip_list": [ "10.0.4.21" ], "name": "redis-webcli-db-NRY6IA75", "password": "******", "port": 1071 }, "syslog_drain_url": null, "volume_mounts": [] } ] } """ os.environ["NO_URL_QUOTING"] = True app.configure() assert app.app.config['REDIS_URL'] == "redis+sentinel://:[email protected]:8001," \ "10.129.3.16:8001,10.130.0.135:8001,10.130.0.13:8001,10.129.0.135:8001" \ "/redis-webcli-db-NRY6IA75/0"
def init_app(): configure() return create_app()
# main.py import app import dialog app.configure() dialog.configure() dialog.show()
#!/usr/bin/env python3 # Copyright 2014 Brett Slatkin, Pearson Education Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Preamble to mimick book environment import logging from pprint import pprint from sys import stdout as STDOUT # Example 9 import app import dialog app.configure() dialog.configure() dialog.show()
def init_app(): args = vars(parser.parse_args()) configure(**args) return create_app()
from app import configure from app.config import settings settings.parse_argv_disabled = True # don't parse pytest's args # set them here since some tests rely on them configure(json_datetime_mode="DM_ISO8601", json_uuid_mode="UM_HEX")
sys.excepthook = handle_exception if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--endpoint', type=str, default=app.config.base_endpoint) parser.add_argument('--ticker', type=str, default=app.config.ticker) parser.add_argument('--stream', type=str, default=app.config.stream) args = parser.parse_args() with open(os.path.join(app.config.srcdir, 'config.json')) as fp: conf = json.load(fp)['rabbitmq'] # wss://stream.binance.com:9443/ws/bnbbtc@aggTrade endpoint_from_args = "{}/ws/{}@{}".format(args.endpoint, args.ticker, args.stream) endpoint = os.environ.get('ENDPOINT', '') or endpoint_from_args stream = endpoint[endpoint.rfind('@') + 1:] index = stream.find('_') stream = stream[:index] if index > -1 else stream logger.info("endpoint = %r", endpoint) logger.info("stream = %r", stream) mapping = app.binance.wss.get_map(stream) loop = asyncio.get_event_loop() loop.run_until_complete(app.configure(conf)) loop.run_until_complete(app.wss(endpoint, mapping)) loop.close()
def init_app() -> falcon.API: configure() return create_app()
def client(): configure() return testing.TestClient(create_app())