本文整理汇总了Python中warehouse.packaging.tables.releases.insert函数的典型用法代码示例。如果您正苦于以下问题:Python insert函数的具体用法?Python insert怎么用?Python insert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了insert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_projects_for_user
def test_get_projects_for_user(dbapp):
dbapp.engine.execute(users.insert().values(
password="!",
username="test-user",
name="Test User",
last_login=datetime.datetime.utcnow(),
is_active=True,
is_superuser=False,
is_staff=False,
))
dbapp.engine.execute(packages.insert().values(name="test-project"))
dbapp.engine.execute(releases.insert().values(
name="test-project",
version="1.0",
summary="test summmary",
_pypi_ordering=1,
))
dbapp.engine.execute(releases.insert().values(
name="test-project",
version="2.0",
summary="test summmary 2.0",
_pypi_ordering=2,
))
dbapp.engine.execute(roles.insert().values(
package_name="test-project",
user_name="test-user",
role_name="Owner",
))
assert dbapp.db.packaging.get_projects_for_user("test-user") == [
{"name": "test-project", "summary": "test summmary 2.0"},
]
示例2: test_get_project_versions
def test_get_project_versions(dbapp):
dbapp.engine.execute(packages.insert().values(name="test-project"))
dbapp.engine.execute(releases.insert().values(
name="test-project",
version="2.0",
_pypi_ordering=2,
))
dbapp.engine.execute(releases.insert().values(
name="test-project",
version="1.0",
_pypi_ordering=1,
))
dbapp.engine.execute(releases.insert().values(
name="test-project",
version="3.0",
_pypi_ordering=3,
))
dbapp.engine.execute(releases.insert().values(
name="test-project",
version="4.0",
_pypi_ordering=4,
))
assert dbapp.db.packaging.get_project_versions("test-project") == \
["4.0", "3.0", "2.0", "1.0"]
示例3: test_get_full_latest_releases
def test_get_full_latest_releases(dbapp):
created = datetime.datetime.utcnow()
dbapp.engine.execute(packages.insert().values(name="test-project"))
dbapp.engine.execute(releases.insert().values(
created=created,
name="test-project",
version="1.0",
author="John Doe",
author_email="[email protected]",
maintainer="Jane Doe",
maintainer_email="[email protected]",
home_page="https://example.com/",
license="Apache License v2.0",
summary="A Test Project",
description="A Longer Test Project",
keywords="foo,bar,wat",
platform="All",
download_url="https://example.com/downloads/test-project-1.0.tar.gz",
_pypi_ordering=1,
))
dbapp.engine.execute(releases.insert().values(
created=created,
name="test-project",
version="2.0",
author="John Doe",
author_email="[email protected]",
maintainer="Jane Doe",
maintainer_email="[email protected]",
home_page="https://example.com/",
license="Apache License v2.0",
summary="A Test Project",
description="A Longer Test Project",
keywords="foo,bar,wat",
platform="All",
download_url="https://example.com/downloads/test-project-1.0.tar.gz",
_pypi_ordering=2,
))
assert dbapp.db.packaging.get_full_latest_releases() == [
{
"created": created,
"name": "test-project",
"version": "2.0",
"author": "John Doe",
"author_email": "[email protected]",
"maintainer": "Jane Doe",
"maintainer_email": "[email protected]",
"home_page": "https://example.com/",
"license": "Apache License v2.0",
"summary": "A Test Project",
"description": "A Longer Test Project",
"keywords": "foo,bar,wat",
"platform": "All",
"download_url": (
"https://example.com/downloads/test-project-1.0.tar.gz"
),
}
]
示例4: test_get_releases_since
def test_get_releases_since(dbapp):
dbapp.engine.execute(packages.insert().values(name="foo1"))
dbapp.engine.execute(packages.insert().values(name="foo2"))
dbapp.engine.execute(packages.insert().values(name="foo3"))
now = datetime.datetime.utcnow()
dbapp.engine.execute(releases.insert().values(
name="foo2", version="1.0",
created=now - datetime.timedelta(seconds=10),
))
dbapp.engine.execute(releases.insert().values(
name="foo3", version="2.0",
created=now - datetime.timedelta(seconds=9),
))
dbapp.engine.execute(releases.insert().values(
name="foo1", version="1.0",
created=now - datetime.timedelta(seconds=4),
))
dbapp.engine.execute(releases.insert().values(
name="foo3", version="1.0",
created=now - datetime.timedelta(seconds=3),
))
dbapp.engine.execute(releases.insert().values(
name="foo1", version="2.0", created=now,
))
since = now - datetime.timedelta(seconds=5)
assert dbapp.db.packaging.get_releases_since(since) == [
{
"name": "foo1",
"version": "2.0",
"summary": None,
"created": now,
},
{
"name": "foo3",
"version": "1.0",
"summary": None,
"created": now - datetime.timedelta(seconds=3),
},
{
"name": "foo1",
"version": "1.0",
"summary": None,
"created": now - datetime.timedelta(seconds=4),
},
]
示例5: test_get_release_urls
def test_get_release_urls(name, attrs, dbapp):
# prepare database
dbapp.engine.execute(packages.insert().values(name=name))
for data in attrs:
dbapp.engine.execute(releases.insert().values(name=name, **data))
assert dbapp.models.packaging.get_release_urls(name) == {
a["version"]: (a.get("home_page"), a.get("download_url")) for a in attrs
}
示例6: add_project
def add_project(name, classifiers):
dbapp.engine.execute(packages.insert().values(name=name))
dbapp.engine.execute(releases.insert().values(name=name, version="1"))
for trove_id in classifiers:
dbapp.engine.execute(release_classifiers.insert().values(
name=name,
version="1",
trove_id=trove_id,
))
示例7: test_get_downloads
def test_get_downloads(pgp, dbapp, monkeypatch):
dbapp.engine.execute(packages.insert().values(name="test-project"))
dbapp.engine.execute(releases.insert().values(
name="test-project",
version="1.0",
))
dbapp.engine.execute(release_files.insert().values(
name="test-project",
version="1.0",
filename="test-project-1.0.tar.gz",
python_version="source",
packagetype="sdist",
md5_digest="0cc175b9c0f1b6a831c399e269772661",
downloads=10,
upload_time=datetime.datetime(year=2013, month=1, day=30),
))
def os_exists():
yield # start
yield True # whether download file exists
yield pgp # whether .asc pgp file exists
f = os_exists().send
f(None) # start it off
os_exists = pretend.call_recorder(f)
monkeypatch.setattr(os.path, "exists", os_exists)
monkeypatch.setattr(os.path, "getsize", lambda x: 10)
dbapp.config.paths.packages = "fake"
downloads = dbapp.db.packaging.get_downloads("test-project", "1.0")
pgp_url = "/packages/source/t/test-project/test-project-1.0.tar.gz.asc"
assert downloads == [
{
"name": "test-project",
"version": "1.0",
"filename": "test-project-1.0.tar.gz",
"filepath": "fake/source/t/test-project/test-project-1.0.tar.gz",
"comment_text": None,
"downloads": 10,
"upload_time": datetime.datetime(year=2013, month=1, day=30),
"python_version": "source",
"md5_digest": "0cc175b9c0f1b6a831c399e269772661",
"url": "/packages/source/t/test-project/test-project-1.0.tar.gz",
"packagetype": "sdist",
"size": 10,
"pgp_url": pgp_url if pgp else None,
},
]
assert os_exists.calls == [
pretend.call(downloads[0]["filepath"]),
pretend.call(downloads[0]["filepath"] + ".asc")
]
示例8: release
def release(name, version, delta):
dbapp.engine.execute(releases.insert().values(
name=name,
version=version,
created=now - delta,
))
dbapp.engine.execute(journals.insert().values(
id=create.id,
name=name,
version=version,
submitted_date=now - delta,
action="new release",
))
create.id += 1
示例9: test_get_recent_projects
def test_get_recent_projects(dbapp):
def create_package(name, version, ordering, created):
dbapp.engine.execute(packages.insert().values(
name=name, created=created))
dbapp.engine.execute(releases.insert().values(
name=name, version=version, _pypi_ordering=ordering,
created=created))
now = datetime.datetime.utcnow()
create_package("foo1", "2.0", 2, now)
create_package("foo2", "1.0", 1, now - datetime.timedelta(seconds=45))
create_package("foo3", "1.0", 1, now - datetime.timedelta(seconds=15))
create_package("foo4", "1.0", 1, now - datetime.timedelta(seconds=40))
create_package("foo5", "1.0", 1, now - datetime.timedelta(seconds=25))
create_package("foo6", "1.0", 1, now - datetime.timedelta(seconds=30))
create_package("foo7", "1.0", 1, now - datetime.timedelta(seconds=35))
dbapp.engine.execute(releases.insert().values(
name="foo1", version="1.0", _pypi_ordering=1,
created=now - datetime.timedelta(seconds=5),
))
assert dbapp.db.packaging.get_recent_projects(num=4) == [
{
"name": "foo1",
"version": "2.0",
"summary": None,
"created": now,
},
{
"name": "foo3",
"version": "1.0",
"summary": None,
"created": now - datetime.timedelta(seconds=15),
},
{
"name": "foo5",
"version": "1.0",
"summary": None,
"created": now - datetime.timedelta(seconds=25),
},
{
"name": "foo6",
"version": "1.0",
"summary": None,
"created": now - datetime.timedelta(seconds=30),
},
]
示例10: test_get_download_count
def test_get_download_count(dbapp):
dbapp.engine.execute(packages.insert().values(name="foo"))
dbapp.engine.execute(releases.insert().values(name="foo", version="1.0"))
dbapp.engine.execute(release_files.insert().values(
name="foo",
version="1.0",
filename="foo-1.0.tar.gz",
downloads=15,
))
dbapp.engine.execute(release_files.insert().values(
name="foo",
version="1.0",
filename="foo-1.0.tar.bz2",
downloads=12,
))
assert dbapp.models.packaging.get_download_count() == 27
示例11: test_get_downloads_missing
def test_get_downloads_missing(dbapp, monkeypatch):
dbapp.engine.execute(packages.insert().values(name="test-project"))
dbapp.engine.execute(releases.insert().values(
name="test-project",
version="1.0",
))
dbapp.engine.execute(release_files.insert().values(
name="test-project",
version="1.0",
filename="test-project-1.0.tar.gz",
python_version="source",
packagetype="sdist",
md5_digest="0cc175b9c0f1b6a831c399e269772661",
downloads=10,
upload_time=datetime.datetime(year=2013, month=1, day=30),
))
# file does not exist
os_exists = pretend.call_recorder(lambda p: False)
# we match the specific arguments below - no need forcing them here as well
log_error = pretend.call_recorder(lambda *a: None)
monkeypatch.setattr(os.path, "exists", os_exists)
# log from warehouse.packaging.db
monkeypatch.setattr(log, "error", log_error)
dbapp.config.paths.packages = "fake"
downloads = dbapp.db.packaging.get_downloads("test-project", "1.0")
assert downloads == []
filepath = "fake/source/t/test-project/test-project-1.0.tar.gz"
assert os_exists.calls == [pretend.call(filepath)]
# actual error message may vary, so just assert that the logging was called
assert log_error.calls == [
pretend.call(
"%s missing for package %s %s",
filepath,
"test-project",
"1.0",
),
]
示例12: test_get_classifiers
def test_get_classifiers(dbapp):
dbapp.engine.execute(packages.insert().values(name="test-project"))
dbapp.engine.execute(releases.insert().values(
name="test-project",
version="1.0",
))
dbapp.engine.execute(classifiers.insert().values(
id=1,
classifier="Test :: Classifier",
))
dbapp.engine.execute(release_classifiers.insert().values(
name="test-project",
version="1.0",
trove_id=1,
))
test_classifiers = dbapp.db.packaging.get_classifiers(
"test-project",
"1.0",
)
assert test_classifiers == ["Test :: Classifier"]
示例13: upsert_release
def upsert_release(self, project_name, version, username, user_ip,
classifiers=None, release_dependencies=None,
description=None, **additional_db_values):
"""
Takes in the following:
* project_name: the name of the package to insert
* version: the version of the package to insert
* username: username of the user upserting the package
* user_ip: ip address of the user upserting the package
* classifiers: a list of the classifiers to classify the release with
* release_dependencies: a dictionary of
'ReleaseDependencyKind.value: [specifier]' pairs.
* description: a restructured text description of the release/project
* additional_db_values: any other column in the release table,
as specified by get_settable_release_columns
and inserts the release (if one doesn't exist), or updates otherwise
"""
is_update = self.get_release(project_name, version) is not None
modified_elements = list(additional_db_values.keys())
db.validate_argument_column_mapping(
additional_db_values,
releases,
blacklist=['name', 'version', 'description', 'description_html',
'_pypi_ordering', '_pypi_hidden']
)
if not is_update:
additional_db_values['name'] = project_name
additional_db_values['version'] = version
if description:
modified_elements += ['description', 'description_html']
additional_db_values['description'] = description
additional_db_values['description_html'] = \
readme.rst.render(description)[0]
if len(additional_db_values) > 0:
if is_update:
self.engine.execute(
releases
.update()
.where(releases.columns.name == project_name)
.where(releases.columns.version == version)
.values(**additional_db_values)
)
else:
self.engine.execute(
releases.insert().values(**additional_db_values)
)
# external tables
# this is legacy behavior. According to PEP-438, we should
# no longer support parsing urls from descriptions
hosting_mode = self.get_hosting_mode(project_name)
if hosting_mode in ('pypi-scrape-crawl', 'pypi-scrape') \
and 'description_html' in additional_db_values:
self.update_release_external_urls(
project_name, version,
utils.find_links_from_html(
additional_db_values['description_html']
)
)
if classifiers:
modified_elements.append('classifiers')
self.update_release_classifiers(project_name, version,
classifiers)
if release_dependencies:
self.update_release_dependencies(project_name, version,
release_dependencies)
if is_update:
journal_message = 'update {0}'.format(','.join(modified_elements))
else:
journal_message = "new release"
self._insert_journal_entry(project_name, version, journal_message,
username, user_ip)
# insert specific actions
if not is_update:
self._update_release_ordering(project_name)
示例14: test_get_release
def test_get_release(dbapp):
created = datetime.datetime.utcnow()
dbapp.engine.execute(packages.insert().values(name="test-project"))
dbapp.engine.execute(releases.insert().values(
created=created,
name="test-project",
version="1.0",
author="John Doe",
author_email="[email protected]",
maintainer="Jane Doe",
maintainer_email="[email protected]",
home_page="https://example.com/",
license="Apache License v2.0",
summary="A Test Project",
description="A Longer Test Project",
keywords="foo,bar,wat",
platform="All",
download_url="https://example.com/downloads/test-project-1.0.tar.gz",
_pypi_ordering=1,
))
dbapp.engine.execute(releases.insert().values(
created=created,
name="test-project",
version="2.0",
author="John Doe",
author_email="[email protected]",
maintainer="Jane Doe",
maintainer_email="[email protected]",
home_page="https://example.com/",
license="Apache License v2.0",
summary="A Test Project",
description="A Longer Test Project",
keywords="foo,bar,wat",
platform="All",
download_url="https://example.com/downloads/test-project-1.0.tar.gz",
_pypi_ordering=2,
))
dbapp.engine.execute(release_dependencies.insert().values(
name="test-project",
version="1.0",
kind=4,
specifier="requests (>=2.0)",
))
dbapp.engine.execute(release_dependencies.insert().values(
name="test-project",
version="2.0",
kind=4,
specifier="requests (>=2.0)",
))
dbapp.engine.execute(release_dependencies.insert().values(
name="test-project",
version="1.0",
kind=5,
specifier="test-project-old",
))
dbapp.engine.execute(release_dependencies.insert().values(
name="test-project",
version="2.0",
kind=5,
specifier="test-project-old",
))
dbapp.engine.execute(release_dependencies.insert().values(
name="test-project",
version="1.0",
kind=8,
specifier="Repository,git://git.example.com/",
))
dbapp.engine.execute(release_dependencies.insert().values(
name="test-project",
version="2.0",
kind=8,
specifier="Repository,git://git.example.com/",
))
test_release = dbapp.db.packaging.get_release("test-project", "1.0")
assert test_release == {
"name": "test-project",
"version": "1.0",
"author": "John Doe",
"author_email": "[email protected]",
"maintainer": "Jane Doe",
"maintainer_email": "[email protected]",
"home_page": "https://example.com/",
"license": "Apache License v2.0",
"summary": "A Test Project",
"description": "A Longer Test Project",
"keywords": "foo,bar,wat",
"platform": "All",
"download_url": ("https://example.com/downloads/"
"test-project-1.0.tar.gz"),
"requires_dist": ["requests (>=2.0)"],
"provides_dist": ["test-project-old"],
"project_url": {"Repository": "git://git.example.com/"},
"created": created,
}
示例15: test_get_recently_updated
def test_get_recently_updated(dbapp):
dbapp.engine.execute(packages.insert().values(name="foo1"))
dbapp.engine.execute(packages.insert().values(name="foo2"))
dbapp.engine.execute(packages.insert().values(name="foo3"))
dbapp.engine.execute(packages.insert().values(name="foo4"))
dbapp.engine.execute(packages.insert().values(name="foo5"))
dbapp.engine.execute(packages.insert().values(name="foo6"))
dbapp.engine.execute(packages.insert().values(name="foo7"))
dbapp.engine.execute(packages.insert().values(name="foo8"))
dbapp.engine.execute(packages.insert().values(name="foo9"))
dbapp.engine.execute(packages.insert().values(name="foo10"))
dbapp.engine.execute(packages.insert().values(name="foo11"))
dbapp.engine.execute(packages.insert().values(name="foo12"))
now = datetime.datetime.utcnow()
dbapp.engine.execute(releases.insert().values(
name="foo1", version="2.0", created=now,
))
dbapp.engine.execute(releases.insert().values(
name="foo1", version="1.0",
created=now - datetime.timedelta(seconds=5),
))
dbapp.engine.execute(releases.insert().values(
name="foo2", version="1.0",
created=now - datetime.timedelta(seconds=10),
))
dbapp.engine.execute(releases.insert().values(
name="foo3", version="1.0",
created=now - datetime.timedelta(seconds=15),
))
dbapp.engine.execute(releases.insert().values(
name="foo4", version="1.0",
created=now - datetime.timedelta(seconds=20),
))
dbapp.engine.execute(releases.insert().values(
name="foo5", version="1.0",
created=now - datetime.timedelta(seconds=25),
))
dbapp.engine.execute(releases.insert().values(
name="foo6", version="1.0",
created=now - datetime.timedelta(seconds=30),
))
dbapp.engine.execute(releases.insert().values(
name="foo7", version="1.0",
created=now - datetime.timedelta(seconds=35),
))
dbapp.engine.execute(releases.insert().values(
name="foo8", version="1.0",
created=now - datetime.timedelta(seconds=40),
))
dbapp.engine.execute(releases.insert().values(
name="foo9", version="1.0",
created=now - datetime.timedelta(seconds=45),
))
dbapp.engine.execute(releases.insert().values(
name="foo10", version="1.0",
created=now - datetime.timedelta(seconds=50),
))
dbapp.engine.execute(releases.insert().values(
name="foo11", version="1.0",
created=now - datetime.timedelta(seconds=55),
))
dbapp.engine.execute(releases.insert().values(
name="foo12", version="1.0",
created=now - datetime.timedelta(seconds=60),
))
assert dbapp.db.packaging.get_recently_updated() == [
{
"name": "foo1",
"version": "2.0",
"summary": None,
"created": now,
},
{
"name": "foo2",
"version": "1.0",
"summary": None,
"created": now - datetime.timedelta(seconds=10),
},
{
"name": "foo3",
"version": "1.0",
"summary": None,
"created": now - datetime.timedelta(seconds=15),
},
{
"name": "foo4",
"version": "1.0",
"summary": None,
"created": now - datetime.timedelta(seconds=20),
},
{
"name": "foo5",
"version": "1.0",
"summary": None,
"created": now - datetime.timedelta(seconds=25),
},
#.........这里部分代码省略.........