Projet

Général

Profil

0001-misc-don-t-use-permanent-redirect-for-moved-pages-25.patch

Frédéric Péters, 20 juillet 2018 10:17

Télécharger (3,05 ko)

Voir les différences:

Subject: [PATCH] misc: don't use permanent redirect for moved pages (#25390)

 combo/public/views.py |  2 +-
 tests/test_public.py  | 16 ++++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)
combo/public/views.py
363 363
            return HttpResponsePermanentRedirect(url + '/')
364 364
        redirect = Redirect.objects.filter(old_url=url).last()
365 365
        if redirect:
366
            return HttpResponsePermanentRedirect(redirect.page.get_online_url())
366
            return HttpResponseRedirect(redirect.page.get_online_url())
367 367
        raise Http404()
368 368

  
369 369
    return publish_page(request, page)
tests/test_public.py
603 603
    redirect = Redirect(old_url='/whatever/', page=page3)
604 604
    redirect.save()
605 605

  
606
    assert urlparse(app.get('/whatever/', status=301).location).path == '/second/third/'
606
    assert urlparse(app.get('/whatever/', status=302).location).path == '/second/third/'
607 607
    assert urlparse(app.get('/whatever', status=301).location).path == '/whatever/'
608 608

  
609 609
    # check the most recent redirect is called
610 610
    redirect = Redirect(old_url='/whatever/', page=page2)
611 611
    redirect.save()
612
    assert urlparse(app.get('/whatever/', status=301).location).path == '/second/'
612
    assert urlparse(app.get('/whatever/', status=302).location).path == '/second/'
613 613

  
614 614
    # rename page
615 615
    page3.slug = 'third2'
616 616
    page3.save()
617 617
    assert app.get('/second/third2/', status=200)
618
    assert urlparse(app.get('/second/third/', status=301).location).path == '/second/third2/'
618
    assert urlparse(app.get('/second/third/', status=302).location).path == '/second/third2/'
619 619

  
620 620
    page2.slug = 'second2'
621 621
    page2.save()
622
    assert urlparse(app.get('/second/third/', status=301).location).path == '/second2/third2/'
623
    assert urlparse(app.get('/second/third2/', status=301).location).path == '/second2/third2/'
624
    assert urlparse(app.get('/second/', status=301).location).path == '/second2/'
622
    assert urlparse(app.get('/second/third/', status=302).location).path == '/second2/third2/'
623
    assert urlparse(app.get('/second/third2/', status=302).location).path == '/second2/third2/'
624
    assert urlparse(app.get('/second/', status=302).location).path == '/second2/'
625 625

  
626 626
    # change parent
627 627
    page3.parent = None
628 628
    page3.save()
629
    assert urlparse(app.get('/second/third/', status=301).location).path == '/third2/'
630
    assert urlparse(app.get('/second2/third2/', status=301).location).path == '/third2/'
629
    assert urlparse(app.get('/second/third/', status=302).location).path == '/third2/'
630
    assert urlparse(app.get('/second2/third2/', status=302).location).path == '/third2/'
631
-