本文整理汇总了Python中warehouse.application.Warehouse类的典型用法代码示例。如果您正苦于以下问题:Python Warehouse类的具体用法?Python Warehouse怎么用?Python Warehouse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Warehouse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_static_middleware
def test_static_middleware(monkeypatch):
WhiteNoise = pretend.call_recorder(lambda app, root, prefix, max_age: app)
monkeypatch.setattr(
application,
"WhiteNoise",
WhiteNoise,
)
Warehouse.from_yaml(
os.path.abspath(os.path.join(
os.path.dirname(__file__),
"test_config.yml",
)),
)
assert WhiteNoise.calls == [
pretend.call(
mock.ANY,
root=os.path.abspath(
os.path.join(
os.path.dirname(warehouse.__file__),
"static",
"compiled",
),
),
prefix="/static/",
max_age=31557600,
)
]
示例2: test_static_middleware
def test_static_middleware(monkeypatch):
SharedDataMiddleware = pretend.call_recorder(lambda app, c: app)
monkeypatch.setattr(
application,
"SharedDataMiddleware",
SharedDataMiddleware,
)
Warehouse.from_yaml(
os.path.abspath(os.path.join(
os.path.dirname(__file__),
"test_config.yml",
)),
)
assert SharedDataMiddleware.calls == [
pretend.call(
mock.ANY,
{
"/static/": os.path.abspath(
os.path.join(
os.path.dirname(warehouse.__file__),
"static",
),
),
},
)
]
示例3: test_header_rewrite_middleware
def test_header_rewrite_middleware(monkeypatch):
HeaderRewriterFix = pretend.call_recorder(lambda app, **kw: app)
monkeypatch.setattr(application, "HeaderRewriterFix", HeaderRewriterFix)
Warehouse.from_yaml(
os.path.abspath(os.path.join(
os.path.dirname(__file__),
"test_config.yml",
)),
)
assert HeaderRewriterFix.calls == [
pretend.call(
mock.ANY,
add_headers=[
(
"X-Powered-By",
"Warehouse {__version__} ({__build__})".format(
__version__=warehouse.__version__,
__build__=warehouse.__build__,
),
),
],
),
]
示例4: test_yaml_instantiation
def test_yaml_instantiation():
Warehouse.from_yaml(
os.path.abspath(os.path.join(
os.path.dirname(__file__),
"test_config.yml",
)),
)
示例5: test_cli_instantiation
def test_cli_instantiation(capsys):
with pytest.raises(SystemExit):
Warehouse.from_cli(["-h"])
out, err = capsys.readouterr()
assert "usage: warehouse" in out
assert not err
示例6: test_running_cli_command
def test_running_cli_command(monkeypatch):
commands = {"serve": pretend.call_recorder(lambda *a, **k: None)}
monkeypatch.setattr(cli, "__commands__", commands)
config = os.path.abspath(os.path.join(os.path.dirname(__file__), "test_config.yml"))
Warehouse.from_cli(["-c", config, "serve"])
assert commands["serve"].calls == [pretend.call(mock.ANY)]
示例7: test_guard_middleware
def test_guard_middleware(monkeypatch):
ContentSecurityPolicy = pretend.call_recorder(lambda app, policy: app)
monkeypatch.setattr(guard, "ContentSecurityPolicy", ContentSecurityPolicy)
Warehouse.from_yaml(
os.path.abspath(os.path.join(
os.path.dirname(__file__),
"test_config.yml",
)),
)
assert ContentSecurityPolicy.calls == [pretend.call(mock.ANY, mock.ANY)]
示例8: test_guard_middleware_theme_debug
def test_guard_middleware_theme_debug(monkeypatch):
ContentSecurityPolicy = pretend.call_recorder(lambda app, policy: app)
monkeypatch.setattr(guard, "ContentSecurityPolicy", ContentSecurityPolicy)
Warehouse.from_yaml(
os.path.abspath(os.path.join(
os.path.dirname(__file__),
"test_config.yml",
)),
override={"theme_debug": True},
)
assert ContentSecurityPolicy.calls == []
示例9: app
def app():
from warehouse.application import Warehouse
def connect():
raise RuntimeError(
"Cannot access the database through the app fixture"
)
engine = pretend.stub(connect=connect)
return Warehouse.from_yaml(
override={
"site": {
"access_token": "testing",
"hosts": "localhost",
},
"database": {"url": "postgresql:///nonexistant"},
"redis": {
"downloads": "redis://nonexistant/0",
"sessions": "redis://nonexistant/0",
},
"search": {"hosts": []},
},
engine=engine,
redis_class=ErrorRedis,
)
示例10: dbapp
def dbapp(database, _database):
from warehouse.application import Warehouse
return Warehouse.from_yaml(
override={"database": {"url": _database}},
engine=database,
)
示例11: _database_url
def _database_url(request):
from warehouse.application import Warehouse
def _get_name():
tag = "".join(
random.choice(string.ascii_lowercase + string.digits)
for x in range(7)
)
return "warehousetest_{}".format(tag)
def _check_name(engine, name):
with engine.connect() as conn:
results = conn.execute(
"SELECT datname FROM pg_database WHERE datistemplate = false"
)
return name not in [r[0] for r in results]
database_url_default = 'postgresql://localhost/test_warehouse'
database_url_environ = os.environ.get("WAREHOUSE_DATABASE_URL")
database_url_option = request.config.getvalue("database_url")
if (not database_url_default and not database_url_environ
and not database_url_option):
pytest.skip("No database provided")
# Configure our engine so that we can empty the database
database_url = (
database_url_option or database_url_environ or database_url_default
)
# Create the database schema
engine = sqlalchemy.create_engine(
database_url,
poolclass=sqlalchemy.pool.NullPool,
)
app = Warehouse.from_yaml(
override={
"database": {
"url": database_url,
},
"search": {"hosts": []},
},
engine=engine,
redis=False,
)
with app.engine.connect() as conn:
conn.execute("DROP SCHEMA public CASCADE")
conn.execute("CREATE SCHEMA public")
conn.execute("CREATE EXTENSION IF NOT EXISTS citext")
conn.execute('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"')
alembic_cfg = alembic.config.Config()
alembic_cfg.set_main_option(
"script_location",
"warehouse:migrations",
)
alembic_cfg.set_main_option("url", app.config.database.url)
alembic.command.upgrade(alembic_cfg, "head")
engine.dispose()
return database_url
示例12: test_shared_static
def test_shared_static():
app = Warehouse.from_yaml(
os.path.abspath(os.path.join(
os.path.dirname(__file__),
"test_config.yml",
)),
override={"debug": True},
)
assert isinstance(app.wsgi_app, SharedDataMiddleware)
示例13: test_camo_settings
def test_camo_settings(monkeypatch):
ContentSecurityPolicy = pretend.call_recorder(lambda app, policy: app)
monkeypatch.setattr(guard, "ContentSecurityPolicy", ContentSecurityPolicy)
Warehouse.from_yaml(
os.path.abspath(os.path.join(
os.path.dirname(__file__),
"test_config.yml",
)),
override={"camo": {"url": "https://camo.example.com/", "key": "skey"}},
)
assert ContentSecurityPolicy.calls == [pretend.call(mock.ANY, mock.ANY)]
assert set(ContentSecurityPolicy.calls[0].args[1]["img-src"]) == {
"'self'",
"https://camo.example.com",
"https://secure.gravatar.com",
}
示例14: test_sentry_middleware
def test_sentry_middleware(monkeypatch):
Sentry = pretend.call_recorder(lambda app, client: app)
client_obj = pretend.stub()
Client = pretend.call_recorder(lambda **kw: client_obj)
monkeypatch.setattr(application, "Sentry", Sentry)
monkeypatch.setattr(application, "Client", Client)
Warehouse.from_yaml(
os.path.abspath(os.path.join(
os.path.dirname(__file__),
"test_config.yml",
)),
override={"sentry": {"dsn": "http://public:[email protected]/1"}}
)
assert Sentry.calls == [pretend.call(mock.ANY, client_obj)]
assert Client.calls == [
pretend.call(dsn="http://public:[email protected]/1"),
]
示例15: dbapp
def dbapp(database, _database_url):
from warehouse.application import Warehouse
return Warehouse.from_yaml(
override={
"database": {"url": _database_url},
"search": {"hosts": []},
},
engine=database,
redis=False,
)