Opened 6 years ago
Last modified 6 years ago
#30089 closed Bug
TestClient doesn't accept data with duplicate keys (SELECT multiple) — at Version 5
Reported by: | Adam Gilman | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
When constructing tests for forms with SELECT elements which allow multiple item selection, the test client doesn't accept multiple selections due to the fact it uses dict internally and results in a squashed single key
Failing test
def test_post_multi_select(self): "POST SELECT multiple data to a view" post_data = QueryDict(mutable=True) post_data.update({'value':37}) post_data.update({'value':38}) response = self.client.post('/post_view/', post_data) # Check some response details self.assertEqual(response.status_code, 200) self.assertEqual(response.context['data'], ['37', '38']) self.assertEqual(response.templates[0].name, 'POST Template') self.assertContains(response, 'Data received')
*updated
Change History (5)
comment:1 by , 6 years ago
Easy pickings: | unset |
---|
comment:2 by , 6 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:3 by , 6 years ago
Apologies, typo in my original test. Good catch. Updated test in description and failure below:
FAIL: test_post_multi_select (test_client.tests.ClientTest) POST SELECT multiple data to a view ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/dev2/.pyenv/versions/3.7.0/lib/python3.7/unittest/case.py", line 59, in testPartExecutor yield File "/Users/dev2/.pyenv/versions/3.7.0/lib/python3.7/unittest/case.py", line 615, in run testMethod() File "/Users/dev2/Documents/GitHub/django/tests/test_client/tests.py", line 113, in test_post_multi_select self.assertEqual(response.context['data'], ['37', '38']) File "/Users/dev2/.pyenv/versions/3.7.0/lib/python3.7/unittest/case.py", line 839, in assertEqual assertion_func(first, second, msg=msg) File "/Users/dev2/.pyenv/versions/3.7.0/lib/python3.7/unittest/case.py", line 832, in _baseAssertEqual raise self.failureException(msg) AssertionError: '38' != ['37', '38']
comment:4 by , 6 years ago
Resolution: | invalid |
---|---|
Status: | closed → new |
comment:5 by , 6 years ago
Description: | modified (diff) |
---|
Note:
See TracTickets
for help on using tickets.
It looks like you have a bug in your reported test case, you are updating
post_data
twice with{'value':37}
and never including38
.Please re-open if you reproduce with
.update({'value':38})
.