[Django] #30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

[Django] #30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)

Django
#30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)
---------------------------------------------+------------------------
               Reporter:  adamgilman         |          Owner:  nobody
                   Type:  Uncategorized      |         Status:  new
              Component:  Testing framework  |        Version:  2.1
               Severity:  Normal             |       Keywords:
           Triage Stage:  Unreviewed         |      Has patch:  0
    Needs documentation:  0                  |    Needs tests:  0
Patch needs improvement:  0                  |  Easy pickings:  1
                  UI/UX:  0                  |
---------------------------------------------+------------------------
 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

 {{{#!python

     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':37})
         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')

 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30089>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/053.4cf1232b8374093a6e161b1095d65c6a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)

Django
#30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)
-----------------------------------+--------------------------------------
     Reporter:  adamgilman         |                    Owner:  nobody
         Type:  Uncategorized      |                   Status:  new
    Component:  Testing framework  |                  Version:  2.1
     Severity:  Normal             |               Resolution:
     Keywords:                     |             Triage Stage:  Unreviewed
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+--------------------------------------
Changes (by adamgilman):

 * easy:  1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/30089#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.f8bb29f4bcf5cddc700bf0768dc7eacb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)

Django
In reply to this post by Django
#30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)
-----------------------------------+--------------------------------------
     Reporter:  adamgilman         |                    Owner:  nobody
         Type:  Uncategorized      |                   Status:  closed
    Component:  Testing framework  |                  Version:  2.1
     Severity:  Normal             |               Resolution:  invalid
     Keywords:                     |             Triage Stage:  Unreviewed
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+--------------------------------------
Changes (by Simon Charette):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 It looks like you have a bug in your reported test case, you are updating
 `post_data` twice with `{'value':37}` and never including `38`.

 Please re-open if you reproduce with `.update({'value':38})`.

--
Ticket URL: <https://code.djangoproject.com/ticket/30089#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.cee40cb287503a0cc44147eb23fa1508%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)

Django
In reply to this post by Django
#30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)
-----------------------------------+--------------------------------------
     Reporter:  Adam Gilman        |                    Owner:  nobody
         Type:  Uncategorized      |                   Status:  closed
    Component:  Testing framework  |                  Version:  2.1
     Severity:  Normal             |               Resolution:  invalid
     Keywords:                     |             Triage Stage:  Unreviewed
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+--------------------------------------

Comment (by Adam Gilman):

 Apologies, typo in my original test. Good catch. Updated test and failure
 below

 {{{#!python

     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')

 }}}

 {{{#!bash
 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']
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30089#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.206fc76b65d3175836e5df715cd666ee%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)

Django
In reply to this post by Django
#30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)
-----------------------------------+--------------------------------------
     Reporter:  Adam Gilman        |                    Owner:  nobody
         Type:  Uncategorized      |                   Status:  new
    Component:  Testing framework  |                  Version:  2.1
     Severity:  Normal             |               Resolution:
     Keywords:                     |             Triage Stage:  Unreviewed
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+--------------------------------------
Changes (by Adam Gilman):

 * status:  closed => new
 * resolution:  invalid =>


--
Ticket URL: <https://code.djangoproject.com/ticket/30089#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.f4a989cc45b97f4ea92b2198bd5d33ea%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)

Django
In reply to this post by Django
#30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)
-----------------------------------+--------------------------------------
     Reporter:  Adam Gilman        |                    Owner:  nobody
         Type:  Uncategorized      |                   Status:  new
    Component:  Testing framework  |                  Version:  2.1
     Severity:  Normal             |               Resolution:
     Keywords:                     |             Triage Stage:  Unreviewed
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+--------------------------------------
Description changed by Adam Gilman:

Old description:

> 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
>
> {{{#!python
>
>     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':37})
>         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')
>
> }}}
New description:

 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

 {{{#!python
 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

--

--
Ticket URL: <https://code.djangoproject.com/ticket/30089#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.052e3acf01ff7b49323e79557c6295c9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)

Django
In reply to this post by Django
#30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)
-----------------------------------+--------------------------------------
     Reporter:  Adam Gilman        |                    Owner:  nobody
         Type:  Uncategorized      |                   Status:  new
    Component:  Testing framework  |                  Version:  2.1
     Severity:  Normal             |               Resolution:
     Keywords:                     |             Triage Stage:  Unreviewed
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+--------------------------------------

Comment (by Carlton Gibson):

 I'm not sure the test is right here.

 `post_view` isn't using `getList()`, so even if `POST` is a `QueryDict`,
 we'll only get the single value...


 {{{

             c = Context({'data': request.POST['value']})

 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30089#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.4a3087242fb8a60e40c210cae46c2228%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)

Django
In reply to this post by Django
#30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)
-----------------------------------+------------------------------------
     Reporter:  Adam Gilman        |                    Owner:  nobody
         Type:  Bug                |                   Status:  new
    Component:  Testing framework  |                  Version:  master
     Severity:  Normal             |               Resolution:
     Keywords:                     |             Triage Stage:  Accepted
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+------------------------------------
Changes (by Carlton Gibson):

 * version:  2.1 => master
 * type:  Uncategorized => Bug
 * stage:  Unreviewed => Accepted


Comment:

 But this fails:



 {{{
         post_data = QueryDict(mutable=True)
         post_data.update({'value':37})
         post_data.update({'value':38})
         self.assertEqual(post_data.getlist('value'), [37, 38])
         request = RequestFactory().post('/post_view/', post_data)
         self.assertEqual(request.POST.getlist('value'), ['37', '38'])
 }}}


 {{{
    self.assertEqual(request.POST.getlist('value'), ['37', '38'])
 AssertionError: Lists differ: ['38'] != ['37', '38']
 }}}

 So this looks valid.

--
Ticket URL: <https://code.djangoproject.com/ticket/30089#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.6b982a73abc30ffac51f9165a1110844%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)

Django
In reply to this post by Django
#30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)
-----------------------------------+------------------------------------
     Reporter:  Adam Gilman        |                    Owner:  nobody
         Type:  Bug                |                   Status:  new
    Component:  Testing framework  |                  Version:  master
     Severity:  Normal             |               Resolution:
     Keywords:                     |             Triage Stage:  Accepted
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+------------------------------------

Comment (by Nasir Hussain):

 Replying to [comment:7 Carlton Gibson]:
 **request.POST** is actual representation of **request.body**. A post
 request could have only one parameter of the same name in its body. That's
 why it returns a single element. I don't think if it's a bug.

--
Ticket URL: <https://code.djangoproject.com/ticket/30089#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.09bea128619acc8237463a6a060ada2f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)

Django
In reply to this post by Django
#30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)
-----------------------------------+------------------------------------
     Reporter:  Adam Gilman        |                    Owner:  nobody
         Type:  Bug                |                   Status:  new
    Component:  Testing framework  |                  Version:  master
     Severity:  Normal             |               Resolution:
     Keywords:                     |             Triage Stage:  Accepted
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+------------------------------------

Comment (by Tim Graham):

 I didn't look into the cause of the issue but normally a dictionary rather
 than a `QueryDict` is used as test client data.

 `post_data = {'value': [37, 38]}` passes the test.

--
Ticket URL: <https://code.djangoproject.com/ticket/30089#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.7023d2e2df3163d6ceb76f0ea445ce5d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)

Django
In reply to this post by Django
#30089: TestClient doesn't accept data with duplicate keys (SELECT multiple)
-----------------------------------+--------------------------------------
     Reporter:  Adam Gilman        |                    Owner:  nobody
         Type:  Bug                |                   Status:  closed
    Component:  Testing framework  |                  Version:  master
     Severity:  Normal             |               Resolution:  invalid
     Keywords:                     |             Triage Stage:  Unreviewed
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+--------------------------------------
Changes (by Carlton Gibson):

 * status:  new => closed
 * resolution:   => invalid
 * stage:  Accepted => Unreviewed


Comment:

 Then it’s incorrect usage. Good. Thanks both!

--
Ticket URL: <https://code.djangoproject.com/ticket/30089#comment:10>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.615814c5f6511f0f5f8b0b898a9736db%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.