本文整理汇总了Python中warehouse.packaging.views.project_detail函数的典型用法代码示例。如果您正苦于以下问题:Python project_detail函数的具体用法?Python project_detail怎么用?Python project_detail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了project_detail函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_project_detail_invalid_version
def test_project_detail_invalid_version():
app = pretend.stub(
config=pretend.stub(
cache=pretend.stub(
browser=False,
varnish=False,
),
),
db=pretend.stub(
packaging=pretend.stub(
get_project=pretend.call_recorder(
lambda proj: "test-project",
),
get_releases=pretend.call_recorder(
lambda proj: [{"version": "1.0"}],
),
),
),
)
request = pretend.stub()
project_name = "test-project"
with pytest.raises(NotFound):
project_detail(app, request, project_name, "2.0")
assert app.db.packaging.get_project.calls == [
pretend.call("test-project"),
]
assert app.db.packaging.get_releases.calls == [
pretend.call("test-project"),
]
示例2: test_project_detail_missing_project
def test_project_detail_missing_project():
app = pretend.stub(db=pretend.stub(packaging=pretend.stub(get_project=pretend.call_recorder(lambda proj: None))))
request = pretend.stub()
project_name = "test-project"
with pytest.raises(NotFound):
project_detail(app, request, project_name)
assert app.db.packaging.get_project.calls == [pretend.call("test-project")]
示例3: test_project_detail_redirects
def test_project_detail_redirects():
app = pretend.stub(
config=pretend.stub(cache=pretend.stub(browser=False, varnish=False)),
db=pretend.stub(
packaging=pretend.stub(
get_project=pretend.call_recorder(lambda proj: {"name": "test-project"}),
get_releases=pretend.call_recorder(lambda proj: [{"version": "1.0"}]),
)
),
)
request = pretend.stub(
url_adapter=pretend.stub(build=pretend.call_recorder(lambda *a, **kw: "/projects/test-project/"))
)
project_name = "test-Project"
normalized = "test-project"
resp = project_detail(app, request, project_name=project_name)
assert resp.status_code == 301
assert resp.headers["Location"] == "/projects/test-project/"
assert resp.headers["Surrogate-Key"] == "project project/{}".format(normalized)
assert app.db.packaging.get_project.calls == [pretend.call("test-Project")]
assert app.db.packaging.get_releases.calls == [pretend.call("test-project")]
assert request.url_adapter.build.calls == [
pretend.call(
"warehouse.packaging.views.project_detail",
{"project_name": "test-project", "version": None},
force_external=False,
)
]
示例4: test_project_detail_no_versions
def test_project_detail_no_versions():
app = pretend.stub(
db=pretend.stub(
packaging=pretend.stub(
get_project=pretend.call_recorder(lambda proj: {"name": "test-project"}),
get_releases=pretend.call_recorder(lambda proj: []),
)
)
)
request = pretend.stub()
project_name = "test-project"
with pytest.raises(NotFound):
project_detail(app, request, project_name)
assert app.db.packaging.get_project.calls == [pretend.call("test-project")]
assert app.db.packaging.get_releases.calls == [pretend.call("test-project")]
示例5: test_project_detail_valid
def test_project_detail_valid(app, version, description, html, camo):
release = {"description": description, "requires_dist": ["foo", "xyz > 0.1"]}
app.config = pretend.stub(cache=pretend.stub(browser=False, varnish=False), camo=camo)
app.db = pretend.stub(
packaging=pretend.stub(
get_project=pretend.call_recorder(lambda proj: {"name": "test-project"}),
get_releases=pretend.call_recorder(lambda proj: [{"version": "2.0"}, {"version": "1.0"}]),
get_release=pretend.call_recorder(lambda proj, version: release),
get_download_counts=pretend.call_recorder(lambda proj: {"last_day": 1, "last_week": 7, "last_month": 30}),
get_reverse_dependencies=pretend.call_recorder(lambda proj: [{"name": "foo"}, {"name": "bar"}]),
get_downloads=pretend.call_recorder(lambda proj, ver: []),
get_classifiers=pretend.call_recorder(lambda proj, ver: []),
get_documentation_url=pretend.call_recorder(lambda proj: None),
get_bugtrack_url=pretend.call_recorder(lambda proj: None),
get_users_for_project=pretend.call_recorder(lambda proj: []),
)
)
request = pretend.stub(url_adapter=pretend.stub(build=lambda *a, **kw: "/projects/test-project/"))
project_name = "test-project"
normalized = "test-project"
resp = project_detail(app, request, project_name=project_name, version=version)
assert resp.status_code == 200
assert resp.headers["Surrogate-Key"] == "project project/{}".format(normalized)
assert resp.response.context == {
"bugtracker": None,
"classifiers": [],
"description_html": html,
"documentation": None,
"download_counts": {"last_day": 1, "last_week": 7, "last_month": 30},
"downloads": [],
"maintainers": [],
"project": "test-project",
"release": release,
"releases": [{"version": "2.0"}, {"version": "1.0"}],
"reverse_dependencies": [
{"name": "foo", "url": "/projects/test-project/"},
{"name": "bar", "url": "/projects/test-project/"},
],
"requirements": [
{"project_name": "foo", "other": "", "project_url": "/projects/test-project/"},
{"project_name": "xyz", "other": "> 0.1", "project_url": "/projects/test-project/"},
],
}
assert app.db.packaging.get_project.calls == [pretend.call("test-project")]
assert app.db.packaging.get_releases.calls == [pretend.call("test-project")]
assert app.db.packaging.get_users_for_project.calls == [pretend.call("test-project")]
assert app.db.packaging.get_reverse_dependencies.calls == [pretend.call("test-project %")]
示例6: test_only_prereleases
def test_only_prereleases(self, monkeypatch, db_request):
project = ProjectFactory.create()
ReleaseFactory.create(project=project, version="1.0.dev0")
ReleaseFactory.create(project=project, version="2.0.dev0")
release = ReleaseFactory.create(project=project, version="3.0.dev0")
response = pretend.stub()
release_detail = pretend.call_recorder(lambda ctx, request: response)
monkeypatch.setattr(views, "release_detail", release_detail)
resp = views.project_detail(project, db_request)
assert resp is response
assert release_detail.calls == [pretend.call(release, db_request)]
示例7: test_normalizing_redirects
def test_normalizing_redirects(self, db_request):
project = ProjectFactory.create()
name = project.name.lower()
if name == project.name:
name = project.name.upper()
db_request.matchdict = {"name": name}
db_request.current_route_path = pretend.call_recorder(
lambda name: "/project/the-redirect/"
)
resp = views.project_detail(project, db_request)
assert isinstance(resp, HTTPMovedPermanently)
assert resp.headers["Location"] == "/project/the-redirect/"
assert db_request.current_route_path.calls == [pretend.call(name=project.name)]
示例8: test_missing_release
def test_missing_release(self, db_request):
project = ProjectFactory.create()
resp = views.project_detail(project, db_request)
assert isinstance(resp, HTTPNotFound)
示例9: test_project_detail_valid
def test_project_detail_valid(version, description):
release = {
"description": description,
}
template = pretend.stub(
render=pretend.call_recorder(lambda **ctx: ""),
)
app = pretend.stub(
config=pretend.stub(
cache=pretend.stub(
browser=False,
varnish=False,
),
),
models=pretend.stub(
packaging=pretend.stub(
get_project=pretend.call_recorder(
lambda proj: Project("test-project"),
),
get_releases=pretend.call_recorder(
lambda proj: [{"version": "2.0"}, {"version": "1.0"}],
),
get_release=pretend.call_recorder(
lambda proj, version: release,
),
get_download_counts=pretend.call_recorder(
lambda proj: {
"last_day": 1,
"last_week": 7,
"last_month": 30,
},
),
get_downloads=pretend.call_recorder(lambda proj, ver: []),
get_classifiers=pretend.call_recorder(lambda proj, ver: []),
get_documentation_url=pretend.call_recorder(
lambda proj: None,
),
get_bugtrack_url=pretend.call_recorder(lambda proj: None),
get_users_for_project=pretend.call_recorder(lambda proj: []),
),
),
templates=pretend.stub(
get_template=pretend.call_recorder(lambda t: template),
),
)
request = pretend.stub()
project_name = "test-project"
normalized = "test-project"
resp = project_detail(
app,
request,
project_name=project_name,
version=version,
)
assert resp.status_code == 200
assert resp.headers["Surrogate-Key"] == \
"project-detail project-detail~{}".format(normalized)
assert app.models.packaging.get_project.calls == [
pretend.call("test-project"),
]
assert app.models.packaging.get_releases.calls == [
pretend.call("test-project"),
]
assert app.models.packaging.get_users_for_project.calls == [
pretend.call("test-project"),
]
示例10: test_missing_release
def test_missing_release(self, db_request):
project = ProjectFactory.create()
with pytest.raises(HTTPNotFound):
views.project_detail(project, db_request)
示例11: test_project_detail_valid
def test_project_detail_valid(version, description, camo):
release = {
"description": description,
"requires_dist": ["foo", "xyz > 0.1"]
}
template = pretend.stub(
render=pretend.call_recorder(lambda **ctx: ""),
)
app = pretend.stub(
config=pretend.stub(
cache=pretend.stub(
browser=False,
varnish=False,
),
camo=camo,
),
db=pretend.stub(
packaging=pretend.stub(
get_project=pretend.call_recorder(
lambda proj: "test-project",
),
get_releases=pretend.call_recorder(
lambda proj: [{"version": "2.0"}, {"version": "1.0"}],
),
get_release=pretend.call_recorder(
lambda proj, version: release,
),
get_download_counts=pretend.call_recorder(
lambda proj: {
"last_day": 1,
"last_week": 7,
"last_month": 30,
},
),
get_downloads=pretend.call_recorder(lambda proj, ver: []),
get_classifiers=pretend.call_recorder(lambda proj, ver: []),
get_documentation_url=pretend.call_recorder(
lambda proj: None,
),
get_bugtrack_url=pretend.call_recorder(lambda proj: None),
get_users_for_project=pretend.call_recorder(lambda proj: []),
),
),
templates=pretend.stub(
get_template=pretend.call_recorder(lambda t: template),
),
)
request = pretend.stub(
url_adapter=pretend.stub(build=lambda *a,
**kw: "/projects/test-project/")
)
project_name = "test-project"
normalized = "test-project"
resp = project_detail(
app,
request,
project_name=project_name,
version=version,
)
assert resp.status_code == 200
assert resp.headers["Surrogate-Key"] == \
"project project/{}".format(normalized)
assert app.db.packaging.get_project.calls == [
pretend.call("test-project"),
]
assert app.db.packaging.get_releases.calls == [
pretend.call("test-project"),
]
assert app.db.packaging.get_users_for_project.calls == [
pretend.call("test-project"),
]