Projet

Général

Profil

0001-jsoncell-copy-Content-Disposition-in-raw-cell-s-acti.patch

Benjamin Dauvergne, 03 mai 2021 13:07

Télécharger (3 ko)

Voir les différences:

Subject: [PATCH] jsoncell: copy Content-Disposition in raw cell's actions
 (#53666)

 combo/public/views.py |  7 ++++++-
 tests/test_public.py  | 23 +++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
combo/public/views.py
144 144
                )
145 145

  
146 146
        if action_response:
147
            return HttpResponse(action_response.content, content_type=action_response.headers['Content-Type'])
147
            response = HttpResponse(
148
                action_response.content, content_type=action_response.headers['Content-Type']
149
            )
150
            if 'Content-Disposition' in action_response.headers:
151
                response['Content-Disposition'] = action_response.headers['Content-Disposition']
152
            return response
148 153

  
149 154
        if not request.is_ajax():
150 155
            return HttpResponseRedirect(cell.page.get_online_url())
tests/test_public.py
733 733
                        'method': 'GET',
734 734
                        'response': 'raw',
735 735
                    },
736
                    'download': {
737
                        'url': 'http://test-post-cell/{{slug}}/download/',
738
                        'method': 'GET',
739
                        'response': 'raw',
740
                    },
736 741
                },
737 742
            }
738 743
        },
......
821 826
                assert requests_search.call_args[0][1] == 'http://test-post-cell/slug/search/'
822 827
                assert resp2.json == {'foo': 'bar'}
823 828

  
829
            # check raw result with content-disposition
830
            with mock.patch('combo.utils.requests.request') as requests_search:
831
                resp.form['action'] = 'download'
832
                requests_search.return_value = mock.Mock(
833
                    content=b'a,b\n1,2',
834
                    status_code=200,
835
                    headers={
836
                        'Content-Type': 'application/octet-stream',
837
                        'Content-Disposition': 'attachment; filename=table.csv',
838
                    },
839
                )
840
                resp2 = resp.form.submit()
841
                assert requests_search.call_args[0][0] == 'GET'
842
                assert requests_search.call_args[0][1] == 'http://test-post-cell/slug/download/'
843
                assert resp2['Content-Type'] == 'application/octet-stream'
844
                assert resp2['Content-Disposition'] == 'attachment; filename=table.csv'
845
                assert resp2.content == b'a,b\n1,2'
846

  
824 847

  
825 848
def test_familyinfos_cell_with_placeholders(app, admin_user):
826 849
    Page.objects.all().delete()
827
-