def test_multiple_params(self): """ If multiple parameter values exist for single key in query_string, the QueryDict returned should return the last value for __getitem__, but should still return the full list using the .get_list() method. If the QueryDict is converted to a dict(), than the value should be the last value set. """ url = self.base_url + '?baz=1&x=y&baz=5' params = get_query_params(url) assert params['baz'] == '5' assert params.getlist('baz') == ['1', '5'] params = get_query_params(url, as_dict=True) assert params['baz'] == '5'
def test_returns_dict(self): """ Specifying `as_dict = True` for get_query_params() should result in a mutable dict instance being returned. """ url = self.base_url + '?baz=1&x=y' params = get_query_params(url, mutable=False, as_dict=True) assert isinstance(params, dict)
def test_default_is_query_dict(self): """ By default, get_query_params() should return a QueryDict instance, not a dict instance. """ url = self.base_url + '?baz=1&x=y' params = get_query_params(url) assert isinstance(params, QueryDict)
def test_empty(self): """ If the url has no query params, get_query_params() should return an empty QueryDict instance. """ url = self.base_url params = get_query_params(url) assert params.dict() == {}
def test_can_be_mutable(self): """ Passing `mutable=True` into get_query_params() should create a QueryDict instance that we are allowed to mutate. """ url = self.base_url + '?baz=1&x=y' params = get_query_params(url, mutable=True) params['baz'] = '2' assert params.dict() == {'baz': '2', 'x': 'y'}
def test_default_immutable(self): """ By default, the QueryDict returned from get_query_params() should not be mutable. """ url = self.base_url + '?baz=1&x=y' params = get_query_params(url) with pytest.raises(AttributeError): params['baz'] = '2'