Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Bug 1088752: Add Shape of the Web app to serve JSON.
Shape of the Web is a standalone site that pulls data from JSON files. In order to make the l10n easier initially, we’re going to host the JSON files on Bedrock to take advantage of the existing l10n process. Also adds a middleware to handle adding CORS headers to the locale redirects when loading the JSON.
- Loading branch information
Showing
with
6,019 additions
and 0 deletions.
- +15 −0 bedrock/mozorg/middleware.py
- +39 −0 bedrock/mozorg/tests/test_middleware.py
- +6 −0 bedrock/settings/base.py
- 0 bedrock/shapeoftheweb/__init__.py
- 0 bedrock/shapeoftheweb/models.py
- +3,740 −0 bedrock/shapeoftheweb/templates/shapeoftheweb/country-data.json
- +1,445 −0 bedrock/shapeoftheweb/templates/shapeoftheweb/infographics.json
- +745 −0 bedrock/shapeoftheweb/templates/shapeoftheweb/main.json
- +12 −0 bedrock/shapeoftheweb/urls.py
- +13 −0 bedrock/shapeoftheweb/views.py
- +1 −0 bedrock/urls.py
- +3 −0 etc/httpd/global.conf
@@ -0,0 +1,39 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
from django.http import HttpRequest, HttpResponse | ||
|
||
from bedrock.mozorg.middleware import CrossOriginResourceSharingMiddleware | ||
from bedrock.mozorg.tests import TestCase | ||
|
||
|
||
class TestCrossOriginResourceSharingMiddleware(TestCase): | ||
def setUp(self): | ||
self.middleware = CrossOriginResourceSharingMiddleware() | ||
self.request = HttpRequest() | ||
self.response = HttpResponse() | ||
|
||
def test_match(self): | ||
self.request.path = '/foo/bar/baz/' | ||
|
||
cors_urls = {r'^/foo/bar': '*'} | ||
with self.settings(CORS_URLS=cors_urls): | ||
self.middleware.process_response(self.request, self.response) | ||
self.assertEqual(self.response['Access-Control-Allow-Origin'], '*') | ||
|
||
def test_middle_match(self): | ||
# Ensure that matches in the middle of the URL work. | ||
self.request.path = '/foo/bar/baz/' | ||
|
||
cors_urls = {r'/bar': '*'} | ||
with self.settings(CORS_URLS=cors_urls): | ||
self.middleware.process_response(self.request, self.response) | ||
self.assertEqual(self.response['Access-Control-Allow-Origin'], '*') | ||
|
||
def test_no_match(self): | ||
self.request.path = '/foo/bar/baz/' | ||
|
||
cors_urls = {r'^/biff/bak': '*'} | ||
with self.settings(CORS_URLS=cors_urls): | ||
self.middleware.process_response(self.request, self.response) | ||
self.assertFalse('Access-Control-Allow-Origin' in self.response) |
Empty file.
Empty file.
Oops, something went wrong.