Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.

implement SCL3 httpd redirects in Django#4215

Closed
bookshelfdave wants to merge 7 commits intomasterfrom
dp_httpd_redirects
Closed

implement SCL3 httpd redirects in Django#4215
bookshelfdave wants to merge 7 commits intomasterfrom
dp_httpd_redirects

Conversation

@bookshelfdave
Copy link
Contributor

@bookshelfdave bookshelfdave commented May 4, 2017

This PR uses @pmac's https://github.com/pmac/django-redirect-urls lib to implement SCL3 Apache httpd redirects in Python/Django. Original rewrite rules are saved as comments to each Django redirect. Test layout is similar to the Bedrock redirect tests.

Some (or all) of these redirects may be unusued/leftover from A Long Time Ago.

The only rewrite rule that isn't implemented in this PR is as follows:

RewriteCond %{SERVER_NAME} ^developer\.mozilla\.com$
RewriteRule (.*) http://developer.mozilla.org$1 [R=301,L]

which redirects requests to developer.mozilla.com/* --> developer.mozilla.org/*

Tracked in this infra issue

cc @jgmize @pmac @jwhitlock @escattone


This site was a great help when working with mod_rewrite.


# other
'kuma.humans',
'redirect_urls',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? I would think that the kuma.redirects app added above should be sufficient.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is needed. This loads the machinery that then goes to find the redirects.py files in the other apps.

redirectpatterns = [
# RewriteRule ^/media/(redesign/)?css/(.*)-min.css$
# /static/build/styles/$2.css [L,R=301]
redirect(r'^media/(?:redesign/)?css/(?P<doc>.*)-min.css$',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want the prepend_locale=False arg on some/most of these. Probably works without, but more regex than you need.

Copy link
Contributor

@jwhitlock jwhitlock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • An empty file is needed at tests/redirects/__init__.py Update - was tests_redirects.py, which makes no sense

After adding that file, I was able to run py.test tests/redirects/test_redirects.py, and get 6 passing tests. I'll have to read a little more of tests/redirects/base.py to see what that means...

There's a few more items, noted in the diff, but this is the first 5 min feedback.

Werkzeug==0.11.4 \
--hash=sha256:7db3cb2d4725be0680abf64a45b18229186f03ad8b9989abbe053f9357b17b37 \
--hash=sha256:e48fb7e3f2bb5a740dd9a666624699a4d83e2e028555f9c46bcc8ecfc2cd8c32
django-redirect-urls==0.1 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dev.txt includes default.txt, so this should be removed

pytest-base-url==1.1.0 \
--hash=sha256:90a1ce6a00a558231117b5aee32300edecbc0c2fd701c13e8cec62177900d28c \
--hash=sha256:001c1b2678dae82c2891db415251361b29ed6824cb2085e4821635119499071e
pytest-django==3.1.2 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is pytest-django actually needed in functional tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't test redirects without it.

@@ -0,0 +1,34 @@
import pytest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pytest imported but unused

@@ -0,0 +1,34 @@
import pytest
from redirect_urls import redirect
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redirect imported but unused

@@ -0,0 +1,14 @@
from __future__ import absolute_import
from operator import itemgetter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

itemgetter imported but unused

@@ -0,0 +1 @@
from django.db import models
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this file be omitted?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the file is required for django to consider it an "app" (that could be old info though). It can be empty though. Looks like the default models.py when you use manage.py startapp.

pytest-django==3.1.2 \
--hash=sha256:038ccc5a9daa1b1b0eb739ab7dce54e495811eca5ea3af4815a2a3ac45152309 \
--hash=sha256:00995c2999b884a38ae9cd30a8c00ed32b3d38c1041250ea84caf18085589662
django-redirect-urls==0.1 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is unused in functional tests

@jwhitlock
Copy link
Contributor

jwhitlock commented May 4, 2017

Also, moving tests/utils/urls.py to tests/redirects/base.py will break functional (Selenium) tests. Instead, it should be imported like tests/function/test_home.py does: from utils.urls import assert_valid_url

@codecov-io
Copy link

codecov-io commented May 5, 2017

Codecov Report

Merging #4215 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4215      +/-   ##
==========================================
+ Coverage   86.31%   86.31%   +<.01%     
==========================================
  Files         147      148       +1     
  Lines        9103     9105       +2     
  Branches     1222     1222              
==========================================
+ Hits         7857     7859       +2     
  Misses       1005     1005              
  Partials      241      241
Impacted Files Coverage Δ
kuma/settings/common.py 93.33% <ø> (ø) ⬆️
kuma/redirects/redirects.py 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 368b6f3...83d97d6. Read the comment docs.

@bookshelfdave
Copy link
Contributor Author

going to split this into 2 PRs: one for requirements so the base Docker image can be updated, and another with the redirects impl.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants