MCPcopy
hub / github.com/django/django / test_basic_mutable_operations

Method test_basic_mutable_operations

tests/httpwrappers/tests.py:148–186  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

146 self.assertNotIn("name", q)
147
148 def test_basic_mutable_operations(self):
149 q = QueryDict(mutable=True)
150 q["name"] = "john"
151 self.assertEqual(q.get("foo", "default"), "default")
152 self.assertEqual(q.get("name", "default"), "john")
153 self.assertEqual(q.getlist("name"), ["john"])
154 self.assertEqual(q.getlist("foo"), [])
155
156 q.setlist("foo", ["bar", "baz"])
157 self.assertEqual(q.get("foo", "default"), "baz")
158 self.assertEqual(q.getlist("foo"), ["bar", "baz"])
159
160 q.appendlist("foo", "another")
161 self.assertEqual(q.getlist("foo"), ["bar", "baz", "another"])
162 self.assertEqual(q["foo"], "another")
163 self.assertIn("foo", q)
164
165 self.assertCountEqual(q, ["foo", "name"])
166 self.assertCountEqual(q.items(), [("foo", "another"), ("name", "john")])
167 self.assertCountEqual(
168 q.lists(), [("foo", ["bar", "baz", "another"]), ("name", ["john"])]
169 )
170 self.assertCountEqual(q.keys(), ["foo", "name"])
171 self.assertCountEqual(q.values(), ["another", "john"])
172
173 q.update({"foo": "hello"})
174 self.assertEqual(q["foo"], "hello")
175 self.assertEqual(q.get("foo", "not available"), "hello")
176 self.assertEqual(q.getlist("foo"), ["bar", "baz", "another", "hello"])
177 self.assertEqual(q.pop("foo"), ["bar", "baz", "another", "hello"])
178 self.assertEqual(q.pop("foo", "not there"), "not there")
179 self.assertEqual(q.get("foo", "not there"), "not there")
180 self.assertEqual(q.setdefault("foo", "bar"), "bar")
181 self.assertEqual(q["foo"], "bar")
182 self.assertEqual(q.getlist("foo"), ["bar"])
183 self.assertIn(q.urlencode(), ["foo=bar&name=john", "name=john&foo=bar"])
184
185 q.clear()
186 self.assertEqual(len(q), 0)
187
188 def test_multiple_keys(self):
189 """Test QueryDict with two key/value pairs with same keys."""

Callers

nothing calls this directly

Calls 14

setlistMethod · 0.95
appendlistMethod · 0.95
popMethod · 0.95
setdefaultMethod · 0.95
urlencodeMethod · 0.95
clearMethod · 0.95
QueryDictClass · 0.90
listsMethod · 0.80
getMethod · 0.45
getlistMethod · 0.45
itemsMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected