Python webob.multidict.MultiDict() Examples
The following are 30
code examples of webob.multidict.MultiDict().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
webob.multidict
, or try the search function
.
Example #1
Source File: test_parser.py From alchemyjsonschema with MIT License | 6 votes |
def test_multiple__convert_to_dict_list__order_also_same(): from webob.multidict import MultiDict mdict = MultiDict( [ ("name", "foo"), ("country", "jp"), ("name", "bar"), ("country", "us"), ("name", "boo"), ("country", "ch"), ] ) result = _callFUT(mdict) assert result == [ {"name": "foo", "country": "jp"}, {"name": "bar", "country": "us"}, {"name": "boo", "country": "ch"}, ]
Example #2
Source File: blobstore_viewer_test.py From browserscope with Apache License 2.0 | 6 votes |
def test_post(self): request = webapp2.Request.blank( '/blobstore', method='POST', POST=multidict.MultiDict([('blob_key', 'a'), ('blob_key', 'b')])) response = webapp2.Response() handler = blobstore_viewer.BlobstoreRequestHandler(request, response) self.mox.StubOutWithMock(blobstore, 'delete') blobstore.delete(['a', 'b']) self.mox.ReplayAll() handler.post() self.mox.VerifyAll() self.assertEqual(302, response.status_int) self.assertEqual('http://localhost/blobstore', response.headers.get('Location'))
Example #3
Source File: test_parser.py From alchemyjsonschema with MIT License | 6 votes |
def test_multiple2__convert_to_dict_list__order_also_same(): from webob.multidict import MultiDict mdict = MultiDict( [ ("name", "foo"), ("name", "bar"), ("name", "boo"), ("country", "jp"), ("country", "us"), ("country", "ch"), ] ) result = _callFUT(mdict) assert result == [ {"name": "foo", "country": "jp"}, {"name": "bar", "country": "us"}, {"name": "boo", "country": "ch"}, ]
Example #4
Source File: blobstore_viewer_test.py From python-compat-runtime with Apache License 2.0 | 6 votes |
def test_post(self): request = webapp2.Request.blank( '/blobstore', method='POST', POST=multidict.MultiDict([('blob_key', 'a'), ('blob_key', 'b')])) response = webapp2.Response() handler = blobstore_viewer.BlobstoreRequestHandler(request, response) admin_request_handler.AdminRequestHandler(handler).post() self.mox.StubOutWithMock(blobstore, 'delete') blobstore.delete(['a', 'b']) self.mox.ReplayAll() handler.post() self.mox.VerifyAll() self.assertEqual(302, response.status_int) self.assertEqual('http://localhost/blobstore', response.headers.get('Location'))
Example #5
Source File: headers.py From isthislegit with BSD 3-Clause "New" or "Revised" License | 6 votes |
def transform(self, fn, decode=False): """Accepts a function, getting a key, val and returning a new pair of key, val and applies the function to all header, value pairs in the message. """ changed = [False] def tracking_fn(key, val): new_key, new_val = fn(key, val) if new_val != val or new_key != key: changed[0] = True return new_key, new_val v = MultiDict(tracking_fn(key, val) for key, val in self.iteritems(raw=not decode)) if changed[0]: self._v = v self.changed = True
Example #6
Source File: __init__.py From nova-ideo with GNU Affero General Public License v3.0 | 5 votes |
def get_flattened_mapping(mapping): result = [list(s.items()) for s in mapping.values()] result = list(set([item for sublist in result for item in sublist])) result = MultiDict(result).dict_of_lists() return result
Example #7
Source File: test_parser.py From alchemyjsonschema with MIT License | 5 votes |
def test_php_compatible_mdict_return_list(): from webob.multidict import MultiDict mdict = MultiDict([("name", "foo"), ("g_id[]", "1"), ("g_id[]", "2")]) result = _callFUT(mdict) assert result == {"name": "foo", "g_id": ["1", "2"]}
Example #8
Source File: case.py From pyvac with BSD 3-Clause "New" or "Revised" License | 5 votes |
def create_request(self, params=None, environ=None, matchdict=None, headers=None, path='/', cookies=None, post=None, **kw): if params and not isinstance(params, MultiDict): mparams = MultiDict() for k, v in params.items(): mparams.add(k, v) params = mparams rv = DummyRequest(params, environ, headers, path, cookies, post, matchdict=(matchdict or {}), **kw) return rv
Example #9
Source File: test_account_item.py From travelcrm with GNU General Public License v3.0 | 5 votes |
def test_form_valid(self, _by_name): request = DummyRequest() csrf_token = request.session.get_csrf_token() request.params = ( MultiDict({ 'name': 'test', 'csrf_token': csrf_token, 'type': 'revenue', 'status': 'active', 'parent_id': 1 }) ) form = AccountItemForm(request) form.validate() self.assertTrue(form.validate())
Example #10
Source File: test_parser.py From alchemyjsonschema with MIT License | 5 votes |
def test_django_like_mdict__return_dict(): from webob.multidict import MultiDict from alchemyjsonschema.parser import DjangoMultiDictWrapper mdict = DjangoMultiDictWrapper(MultiDict({"name": "foo", "country": "jp"})) result = _callFUT(mdict) assert result == {"name": "foo", "country": "jp"}
Example #11
Source File: test_parser.py From alchemyjsonschema with MIT License | 5 votes |
def test_single_mdict__return_dict(): from webob.multidict import MultiDict mdict = MultiDict({"name": "foo", "country": "jp"}) result = _callFUT(mdict) assert result == {"name": "foo", "country": "jp"}
Example #12
Source File: test_company.py From travelcrm with GNU General Public License v3.0 | 5 votes |
def test_form_add_invalid(self): request = DummyRequest(params=MultiDict()) form = CompanyAddForm(request) self.assertFalse(form.validate())
Example #13
Source File: test_accomodation.py From travelcrm with GNU General Public License v3.0 | 5 votes |
def test_form_valid(self, _by_name): request = DummyRequest() csrf_token = request.session.get_csrf_token() request.params = ( MultiDict({ 'name': 'test', 'csrf_token': csrf_token }) ) form = AccomodationForm(request) form.validate() self.assertTrue(form.validate())
Example #14
Source File: test_accomodation.py From travelcrm with GNU General Public License v3.0 | 5 votes |
def test_form_unique_name(self, _by_name): request = DummyRequest( params=MultiDict({'name': 'test', 'csrf_token': 'test'}) ) form = AccomodationForm(request) form.validate() self.assertTrue('name' in form._errors)
Example #15
Source File: test_accomodation.py From travelcrm with GNU General Public License v3.0 | 5 votes |
def test_form_invalid(self): request = DummyRequest(params=MultiDict()) form = AccomodationForm(request) self.assertFalse(form.validate())
Example #16
Source File: test_account.py From travelcrm with GNU General Public License v3.0 | 5 votes |
def test_form_valid(self, _by_name): request = DummyRequest() csrf_token = request.session.get_csrf_token() request.params = ( MultiDict({ 'name': 'test', 'csrf_token': csrf_token, 'currency_id': 10, 'account_type': 'bank', 'status': 'active', 'display_text': 'test' }) ) form = AccountForm(request) form.validate() self.assertTrue(form.validate())
Example #17
Source File: test_jsonify.py From pecan with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_multidict(self): md = MultiDict() md.add('arg', 'foo') md.add('arg', 'bar') result = encode(md) assert loads(result) == {'arg': ['foo', 'bar']}
Example #18
Source File: test_account.py From travelcrm with GNU General Public License v3.0 | 5 votes |
def test_form_invalid(self): request = DummyRequest(params=MultiDict()) form = AccountForm(request) self.assertFalse(form.validate()) self.assertIn('currency_id', form._errors) self.assertIn('name', form._errors) self.assertIn('account_type', form._errors) self.assertIn('display_text', form._errors) self.assertIn('status', form._errors)
Example #19
Source File: test_account_item.py From travelcrm with GNU General Public License v3.0 | 5 votes |
def test_form_self_parent(self): request = DummyRequest( params=MultiDict({'id': '1', 'parent_id': '1'}) ) form = AccountItemForm(request) form.validate() self.assertTrue('parent_id' in form._errors)
Example #20
Source File: test_account_item.py From travelcrm with GNU General Public License v3.0 | 5 votes |
def test_form_unique_name(self, _by_name): request = DummyRequest( params=MultiDict({'name': 'test', 'csrf_token': 'test'}) ) form = AccountItemForm(request) form.validate() self.assertTrue('name' in form._errors)
Example #21
Source File: test_account_item.py From travelcrm with GNU General Public License v3.0 | 5 votes |
def test_form_invalid(self): request = DummyRequest(params=MultiDict()) form = AccountItemForm(request) self.assertFalse(form.validate())
Example #22
Source File: test_advsource.py From travelcrm with GNU General Public License v3.0 | 5 votes |
def test_form_unique_name(self, _by_name): request = DummyRequest( params=MultiDict({'name': 'test', 'csrf_token': 'test'}) ) form = AdvsourceForm(request) form.validate() self.assertIn('name', form._errors)
Example #23
Source File: test_advsource.py From travelcrm with GNU General Public License v3.0 | 5 votes |
def test_form_invalid(self): request = DummyRequest(params=MultiDict()) form = AdvsourceForm(request) self.assertFalse(form.validate()) self.assertIn('name', form._errors)
Example #24
Source File: test_adress.py From travelcrm with GNU General Public License v3.0 | 5 votes |
def test_form_valid(self): request = DummyRequest() csrf_token = request.session.get_csrf_token() request.params = ( MultiDict({ 'csrf_token': csrf_token, 'location_id': 10, 'zip_code': '02121', 'address': 'test' }) ) form = AddressForm(request) form.validate() self.assertTrue(form.validate())
Example #25
Source File: test_adress.py From travelcrm with GNU General Public License v3.0 | 5 votes |
def test_form_invalid(self): request = DummyRequest( params=MultiDict({'address': 'a'}) ) form = AddressForm(request) self.assertFalse(form.validate()) self.assertIn('location_id', form._errors) self.assertIn('zip_code', form._errors) self.assertIn('address', form._errors)
Example #26
Source File: test_accomodations.py From travelcrm with GNU General Public License v3.0 | 5 votes |
def test_view(self, by_resource_id): from pyramid.httpexceptions import HTTPFound AccomodationsView._get_title = lambda x, y=None: 'test' view = AccomodationsView( DummyResource(), DummyRequest(params=MultiDict({'rid': 1})) ) self.assertIsInstance(view.view(), HTTPFound) AccomodationsView.edit = lambda x=None: {} view = AccomodationsView(DummyResource(), DummyRequest()) self.assertSetEqual({'title', 'readonly'}, set(view.view().keys()))
Example #27
Source File: response_test.py From pyramid_swagger with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, **kw): super(EnhancedDummyRequest, self).__init__(**kw) self.GET = MultiDict(self.GET) # Make sure content_type attr exists is not passed in via **kw self.content_type = getattr(self, 'content_type', None)
Example #28
Source File: wsgi.py From searchlight with Apache License 2.0 | 5 votes |
def _sanitizer(self, obj): """Sanitizer method that will be passed to jsonutils.dumps.""" if hasattr(obj, "to_dict"): return obj.to_dict() if isinstance(obj, multidict.MultiDict): return obj.mixed() return jsonutils.to_primitive(obj)
Example #29
Source File: unit_test_helpers.py From n6 with GNU Affero General Public License v3.0 | 5 votes |
def __make_request_params(kwargs): params = MultiDict() for key, val in kwargs.iteritems(): assert isinstance(key, basestring) if isinstance(val, basestring): params[key] = val else: assert isinstance(val, (list, tuple)) for v in val: assert isinstance(v, basestring) params.add(key, v) return params
Example #30
Source File: part.py From isthislegit with BSD 3-Clause "New" or "Revised" License | 5 votes |
def transform(self, func): changed = [False] def wrapped_func(key, value): new_key, new_value = func(key, value) if new_value != value or new_key != key: changed[0] = True return new_key, new_value transformed_headers = [wrapped_func(k, v) for k, v in self._m.items()] if changed[0]: self._m._headers = transformed_headers self._v = MultiDict([(normalize(k), remove_newlines(v)) for k, v in transformed_headers]) self.changed = True