Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_no_args(self):
from webob.multidict import MultiDict
md = MultiDict()
self.assertEqual(md._items, [])
def test_fails_with_stdlib_names(self, pyramid_config, db_request, name):
user = UserFactory.create()
EmailFactory.create(user=user)
db_request.user = user
pyramid_config.testing_securitypolicy(userid=1)
db_request.POST = MultiDict(
{
"metadata_version": "1.2",
"name": name,
"version": "1.0",
"filetype": "sdist",
"md5_digest": "a fake md5 digest",
"content": pretend.stub(
filename=f"{name}-1.0.tar.gz",
file=io.BytesIO(_TAR_GZ_PKG_TESTDATA),
type="application/tar",
),
}
)
db_request.help_url = pretend.call_recorder(lambda **kw: "/the/help/url/")
def test_full_validate_valid(self, data):
form = legacy.MetadataForm(MultiDict(data))
form.full_validate()
def test_view_list(self):
from webob.multidict import MultiDict
d = MultiDict()
self.assertEqual(d.view_list([1, 2])._items, [1, 2])
Test that if a release with a version like '1.0' exists, that a future
upload with an equivalent version like '1.0.0' will not make a second
release
"""
pyramid_config.testing_securitypolicy(userid=1)
user = UserFactory.create()
EmailFactory.create(user=user)
project = ProjectFactory.create()
release = ReleaseFactory.create(project=project, version="1.0")
RoleFactory.create(user=user, project=project)
db_request.user = user
db_request.remote_addr = "10.10.10.20"
db_request.user_agent = "warehouse-tests/6.6.6"
db_request.POST = MultiDict(
{
"metadata_version": "1.2",
"name": project.name,
"version": "1.0.0",
"summary": "This is my summary!",
"filetype": "sdist",
"md5_digest": _TAR_GZ_PKG_MD5,
"content": pretend.stub(
filename="{}-{}.tar.gz".format(project.name, "1.0.0"),
file=io.BytesIO(_TAR_GZ_PKG_TESTDATA),
type="application/tar",
),
}
)
storage_service = pretend.stub(store=lambda path, filepath, meta: None)
def test_unflatten_params(self):
dic = {
'test:0:test1:value': 'v1',
'test:1:test1:value': 'v2',
}
result = utils.unflatten_params(dic)
expected = {
'test': [{'test1': {'value': 'v1'}},
{'test1': {'value': 'v2'}}]}
self.assertEqual(result, expected)
if not hasattr(webob, 'MultiDict'):
dic = webob.multidict.MultiDict(dic)
else:
dic = webob.MultiDict(dic)
result = utils.unflatten_params(dic)
self.assertEqual(result, expected)
def test_none2empty(self):
form = FormWithFile(self.env)
form.accept(MultiDict({'file.file': None,
'file.original_name': '',
'file.transient_name': '',
'file.mode': 'empty',}))
data = form.python_data
self.assertEqual(data['file'], None)
def _get_instance(self, environ=None, **kwargs):
if environ is None:
environ = {}
if kwargs:
data = multidict.MultiDict(kwargs)
else:
data = self.data.copy()
return self.klass(data, environ)
def _dict_to_multidict(dict_):
"""Convert a validated query param dict back to a ``MultiDict``."""
result = MultiDict()
for key, value in dict_.items():
if isinstance(value, list):
for item in value:
result.add(key, item)
else:
result.add(key, value)
return result
def _search_replies(self, annotation_ids):
if not self.separate_replies:
return []
# The only difference between a search for annotations and a search for
# replies to annotations is the RepliesMatcher and the params passed to
# the modifiers.
response = self._search(
[query.RepliesMatcher(annotation_ids)] + self._modifiers,
[], # Aggregations aren't used in replies.
MultiDict({"limit": self._replies_limit}),
)
if len(response["hits"]["hits"]) < response["hits"]["total"]:
log.warning(
"The number of reply annotations exceeded the page size "
"of the Elasticsearch query. We currently don't handle "
"this, our search API doesn't support pagination of the "
"reply set."
)
return [hit["_id"] for hit in response["hits"]["hits"]]