Test Request copy
(self)
| 183 | assert r4.body == b"Price: \xa3100" |
| 184 | |
| 185 | def test_copy(self): |
| 186 | """Test Request copy""" |
| 187 | |
| 188 | def somecallback(): |
| 189 | pass |
| 190 | |
| 191 | r1 = self.request_class( |
| 192 | "http://www.example.com", |
| 193 | flags=["f1", "f2"], |
| 194 | callback=somecallback, |
| 195 | errback=somecallback, |
| 196 | ) |
| 197 | r1.meta["foo"] = "bar" |
| 198 | r1.cb_kwargs["key"] = "value" |
| 199 | r2 = r1.copy() |
| 200 | |
| 201 | # make sure copy does not propagate callbacks |
| 202 | assert r1.callback is somecallback |
| 203 | assert r1.errback is somecallback |
| 204 | assert r2.callback is r1.callback |
| 205 | assert r2.errback is r2.errback |
| 206 | |
| 207 | # make sure flags list is shallow copied |
| 208 | assert r1.flags is not r2.flags, "flags must be a shallow copy, not identical" |
| 209 | assert r1.flags == r2.flags |
| 210 | |
| 211 | # make sure cb_kwargs dict is shallow copied |
| 212 | assert r1.cb_kwargs is not r2.cb_kwargs, ( |
| 213 | "cb_kwargs must be a shallow copy, not identical" |
| 214 | ) |
| 215 | assert r1.cb_kwargs == r2.cb_kwargs |
| 216 | |
| 217 | # make sure meta dict is shallow copied |
| 218 | assert r1.meta is not r2.meta, "meta must be a shallow copy, not identical" |
| 219 | assert r1.meta == r2.meta |
| 220 | |
| 221 | # make sure headers attribute is shallow copied |
| 222 | assert r1.headers is not r2.headers, ( |
| 223 | "headers must be a shallow copy, not identical" |
| 224 | ) |
| 225 | assert r1.headers == r2.headers |
| 226 | assert r1.encoding == r2.encoding |
| 227 | assert r1.dont_filter == r2.dont_filter |
| 228 | |
| 229 | # Request.body can be identical since it's an immutable object (str) |
| 230 | |
| 231 | def test_copy_inherited_classes(self): |
| 232 | """Test Request children copies preserve their class""" |