Commit 0eed5875 by chrisndodge

Merge pull request #1839 from MITx/feature/sef/pressreleases

Press Releases: generic matching rule instead of explicit lines in url.py
parents 4615f0d8 bd2330a8
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
from django.test.client import Client
class SimpleTest(TestCase):
def test_basic_addition(self):
def setUp(self):
self.client = Client()
def test_render(self):
"""
Render a normal page, like jobs
"""
response = self.client.get("/jobs")
self.assertEquals(response.status_code, 200)
def test_render_press_release(self):
"""
Tests that 1 + 1 always equals 2.
Render press releases from generic URL match
"""
self.assertEqual(1 + 1, 2)
# since I had to remap files, pedantically test all press releases
# published to date. Decent positive test while we're at it.
all_releases = ["/press/mit-and-harvard-announce-edx",
"/press/uc-berkeley-joins-edx",
"/press/edX-announces-proctored-exam-testing",
"/press/elsevier-collaborates-with-edx",
"/press/ut-joins-edx",
"/press/cengage-to-provide-book-content",
"/press/gates-foundation-announcement",
"/press/wellesley-college-joins-edx",
"/press/georgetown-joins-edx",
"/press/spring-courses",
"/press/lewin-course-announcement",
"/press/bostonx-announcement",
"/press/eric-lander-secret-of-life",
"/press/edx-expands-internationally",
"/press/xblock_announcement",
"/press/stanford-to-work-with-edx",
]
for rel in all_releases:
response = self.client.get(rel)
self.assertNotContains(response, "PAGE NOT FOUND", status_code=200)
# should work with caps
response = self.client.get("/press/STANFORD-to-work-with-edx")
self.assertContains(response, "Stanford", status_code=200)
# negative test
response = self.client.get("/press/this-shouldnt-work")
self.assertEqual(response.status_code, 404)
# can someone do something fishy? no.
response = self.client.get("/press/../homework.html")
self.assertEqual(response.status_code, 404)
# "." in is ascii 2E
response = self.client.get("/press/%2E%2E/homework.html")
self.assertEqual(response.status_code, 404)
......@@ -4,9 +4,10 @@
# security reasons.
from mitxmako.shortcuts import render_to_response, render_to_string
from mako.exceptions import TopLevelLookupException
from django.shortcuts import redirect
from django.conf import settings
from django.http import HttpResponseNotFound, HttpResponseServerError
from django.http import HttpResponseNotFound, HttpResponseServerError, Http404
from django_future.csrf import ensure_csrf_cookie
from util.cache import cache_if_anonymous
......@@ -40,6 +41,25 @@ def render(request, template):
return render_to_response('static_templates/' + template, {})
@ensure_csrf_cookie
@cache_if_anonymous
def render_press_release(request, slug):
"""
Render a press release given a slug. Similar to the "render" function above,
but takes a slug and does a basic conversion to convert it to a template file.
a) all lower case,
b) convert dashes to underscores, and
c) appending ".html"
"""
template = slug.lower().replace('-', '_') + ".html"
try:
resp = render_to_response('static_templates/press_releases/' + template, {})
except TopLevelLookupException:
raise Http404
else:
return resp
def render_404(request):
return HttpResponseNotFound(render_to_string('static_templates/404.html', {}))
......
......@@ -11,7 +11,7 @@
<id>tag:www.edx.org,2012:Post/17</id>
<published>2012-12-19T14:00:00-07:00</published>
<updated>2012-12-19T14:00:00-07:00</updated>
<link type="text/html" rel="alternate" href="${reverse('press/stanford-to-work-with-edx')}"/>
<link type="text/html" rel="alternate" href="${reverse('press_release', args=['stanford-to-work-with-edx'])}"/>
<title>Stanford University to Collaborate with edX on Development of Non-Profit Open Source edX Platform</title>
<content type="html">&lt;img src=&quot;${static.url('images/press/releases/stanford-university-m.png')}&quot; /&gt;
&lt;p&gt;&lt;/p&gt;</content>
......@@ -20,7 +20,7 @@
<id>tag:www.edx.org,2013:Post/16</id>
<published>2013-03-15T10:00:00-07:00</published>
<updated>2013-03-15T10:00:00-07:00</updated>
<link type="text/html" rel="alternate" href="${reverse('press/xblock-announcement')}"/>
<link type="text/html" rel="alternate" href="${reverse('press_release', args=['xblock-announcement'])}"/>
<title>edX releases XBlock SDK, first step toward open source vision</title>
<content type="html">&lt;img src=&quot;${static.url('images/press/releases/edx-logo_240x180.png')}&quot; /&gt;
&lt;p&gt;&lt;/p&gt;</content>
......@@ -38,7 +38,7 @@
<!-- <id>tag:www.edx.org,2013:Post/14</id> -->
<!-- <published>2013-02-20T10:00:00-07:00</published> -->
<!-- <updated>2013-02-20T10:00:00-07:00</updated> -->
<!-- <link type="text/html" rel="alternate" href="${reverse('press/edx-expands-internationally')}"/> -->
<!-- <link type="text/html" rel="alternate" href="${reverse('press_release', args=['edx-expands-internationally'])}"/> -->
<!-- <title>edX Expands Internationally and Doubles its Institutional Membership with the Addition of Six New Schools</title> -->
<!-- <content type="html">&lt;img src=&quot;${static.url('images/press/releases/edx-logo_240x180.png')}&quot; /&gt; -->
<!-- &lt;p&gt;&lt;/p&gt;</content> -->
......@@ -47,7 +47,7 @@
<id>tag:www.edx.org,2013:Post/14</id>
<published>2013-01-30T10:00:00-07:00</published>
<updated>2013-01-30T10:00:00-07:00</updated>
<link type="text/html" rel="alternate" href="${reverse('press/eric-lander-secret-of-life')}"/>
<link type="text/html" rel="alternate" href="${reverse('press_release', args=['eric-lander-secret-of-life'])}"/>
<title>New biology course from human genome pioneer Eric Lander</title>
<content type="html">&lt;img src=&quot;${static.url('images/press/releases/eric-lander_240x180.jpg')}&quot; /&gt;
&lt;p&gt;&lt;/p&gt;</content>
......@@ -56,7 +56,7 @@
<id>tag:www.edx.org,2013:Post/12</id>
<published>2013-01-22T10:00:00-07:00</published>
<updated>2013-01-22T10:00:00-07:00</updated>
<link type="text/html" rel="alternate" href="${reverse('press/lewin-course-announcement')}"/>
<link type="text/html" rel="alternate" href="${reverse('press_release', args=['lewin-course-announcement'])}"/>
<title>New course from legendary MIT physics professor Walter Lewin</title>
<content type="html">&lt;img src=&quot;${static.url('images/press/releases/dr-lewin-316_240x180.jpg')}&quot; /&gt;
&lt;p&gt;&lt;/p&gt;</content>
......@@ -65,7 +65,7 @@
<id>tag:www.edx.org,2013:Post/11</id>
<published>2013-01-29T10:00:00-07:00</published>
<updated>2013-01-29T10:00:00-07:00</updated>
<link type="text/html" rel="alternate" href="${reverse('press/bostonx-announcement')}"/>
<link type="text/html" rel="alternate" href="${reverse('press_release', args=['bostonx-announcement'])}"/>
<title>City of Boston and edX partner to establish BostonX to improve educational access for residents</title>
<content type="html">&lt;img src=&quot;${static.url('images/press/releases/edx-logo_240x180.png')}&quot; /&gt;
&lt;p&gt;&lt;/p&gt;</content>
......@@ -74,7 +74,7 @@
<!-- <id>tag:www.edx.org,2012:Post/10</id> -->
<!-- <published>2012-12-19T14:00:00-07:00</published> -->
<!-- <updated>2012-12-19T14:00:00-07:00</updated> -->
<!-- <link type="text/html" rel="alternate" href="${reverse('press/spring-courses')}"/> -->
<!-- <link type="text/html" rel="alternate" href="${reverse('press_release', args=['spring-courses'])}"/> -->
<!-- <title>edX announces first wave of new courses for Spring 2013</title> -->
<!-- <content type="html">&lt;img src=&quot;${static.url('images/press/releases/edx-logo_240x180.png')}&quot; /&gt; -->
<!-- &lt;p&gt;&lt;/p&gt;</content> -->
......@@ -83,7 +83,7 @@
<id>tag:www.edx.org,2012:Post/9</id>
<published>2012-12-10T14:00:00-07:00</published>
<updated>2012-12-10T14:00:00-07:00</updated>
<link type="text/html" rel="alternate" href="${reverse('press/georgetown-joins-edx')}"/>
<link type="text/html" rel="alternate" href="${reverse('press_release', args=['georgetown-joins-edx'])}"/>
<title>Georgetown University joins edX</title>
<content type="html">&lt;img src=&quot;${static.url('images/press/releases/georgetown-seal_240x180.png')}&quot; /&gt;
&lt;p&gt;Sixth institution to join global movement in year one&lt;/p&gt;</content>
......@@ -92,7 +92,7 @@
<id>tag:www.edx.org,2012:Post/8</id>
<published>2012-12-04T14:00:00-07:00</published>
<updated>2012-12-04T14:00:00-07:00</updated>
<link type="text/html" rel="alternate" href="${reverse('press/wellesley-college-joins-edx')}"/>
<link type="text/html" rel="alternate" href="${reverse('press_release', args=['wellesley-college-joins-edx'])}"/>
<title>Wellesley College joins edX</title>
<content type="html">&lt;img src=&quot;${static.url('images/press/releases/wellesley-seal_240x180.png')}&quot; /&gt;
&lt;p&gt;First liberal arts college to join edX&lt;/p&gt;</content>
......@@ -101,7 +101,7 @@
<id>tag:www.edx.org,2012:Post/7</id>
<published>2012-11-12T14:00:00-07:00</published>
<updated>2012-11-12T14:00:00-07:00</updated>
<link type="text/html" rel="alternate" href="${reverse('press/gates-foundation-announcement')}"/>
<link type="text/html" rel="alternate" href="${reverse('press_release', args=['gates-foundation-announcement'])}"/>
<title>edX and Massachusetts Community Colleges join in Gates-Funded educational initiative</title>
<content type="html">&lt;img src=&quot;${static.url('images/press/releases/mass-seal_240x180.png')}&quot; /&gt;
&lt;p&gt;&lt;/p&gt;</content>
......@@ -110,7 +110,7 @@
<id>tag:www.edx.org,2012:Post/6</id>
<published>2012-10-15T14:00:00-07:00</published>
<updated>2012-10-14T14:00:00-07:00</updated>
<link type="text/html" rel="alternate" href="${reverse('press/ut-joins-edx')}"/>
<link type="text/html" rel="alternate" href="${reverse('press_release', args=['ut-joins-edx'])}"/>
<title>The University of Texas System joins edX</title>
<content type="html">&lt;img src=&quot;${static.url('images/press/releases/utsys-seal_240x180.png')}&quot; /&gt;
&lt;p&gt;Nine universities and six health institutions&lt;/p&gt;</content>
......@@ -119,7 +119,7 @@
<!-- <id>tag:www.edx.org,2012:Post/5</id> -->
<!-- <published>2012-09-25T14:00:00-07:00</published> -->
<!-- <updated>2012-09-25T14:00:00-07:00</updated> -->
<!-- <link type="text/html" rel="alternate" href="${reverse('press/elsevier-collaborates-with-edx')}"/> -->
<!-- <link type="text/html" rel="alternate" href="${reverse('press_release', args=['elsevier-collaborates-with-edx'])}"/> -->
<!-- <title>Elsevier collaborates with edX</title> -->
<!-- <content type="html">&lt;img src=&quot;${static.url('images/press/releases/foundations-of-analog_240x180.jpg')}&quot; /&gt; -->
<!-- &lt;p&gt;Free course textbook made available to edX students&lt;/p&gt;</content> -->
......@@ -128,7 +128,7 @@
<id>tag:www.edx.org,2012:Post/4</id>
<published>2012-09-06T14:00:00-07:00</published>
<updated>2012-09-06T14:00:00-07:00</updated>
<link type="text/html" rel="alternate" href="${reverse('press/edX-announces-proctored-exam-testing')}"/>
<link type="text/html" rel="alternate" href="${reverse('press_release', args=['edX-announces-proctored-exam-testing'])}"/>
<title>edX to offer learners option of taking proctored final exam</title>
<content type="html">&lt;img src=&quot;${static.url('images/press/releases/diploma_240x180.jpg')}&quot; /&gt;</content>
</entry>
......@@ -136,7 +136,7 @@
<id>tag:www.edx.org,2012:Post/3</id>
<published>2012-07-16T14:08:12-07:00</published>
<updated>2012-07-16T14:08:12-07:00</updated>
<link type="text/html" rel="alternate" href="${reverse('press/uc-berkeley-joins-edx')}"/>
<link type="text/html" rel="alternate" href="${reverse('press_release', args=['uc-berkeley-joins-edx'])}"/>
<title>UC Berkeley joins edX</title>
<content type="html">&lt;img src=&quot;${static.url('images/press/releases/edx-logo_240x180.png')}&quot; /&gt;
&lt;p&gt;edX broadens course offerings&lt;/p&gt;</content>
......
......@@ -117,51 +117,9 @@ urlpatterns = ('',
{'template': 'honor.html'}, name="honor"),
#Press releases
url(r'^press/mit-and-harvard-announce-edx$', 'static_template_view.views.render',
{'template': 'press_releases/MIT_and_Harvard_announce_edX.html'}, name="press/mit-and-harvard-announce-edx"),
url(r'^press/uc-berkeley-joins-edx$', 'static_template_view.views.render',
{'template': 'press_releases/UC_Berkeley_joins_edX.html'}, name="press/uc-berkeley-joins-edx"),
url(r'^press/edX-announces-proctored-exam-testing$', 'static_template_view.views.render',
{'template': 'press_releases/edX_announces_proctored_exam_testing.html'}, name="press/edX-announces-proctored-exam-testing"),
url(r'^press/elsevier-collaborates-with-edx$', 'static_template_view.views.render',
{'template': 'press_releases/Elsevier_collaborates_with_edX.html'}, name="press/elsevier-collaborates-with-edx"),
url(r'^press/ut-joins-edx$', 'static_template_view.views.render',
{'template': 'press_releases/UT_joins_edX.html'}, name="press/ut-joins-edx"),
url(r'^press/cengage-to-provide-book-content$', 'static_template_view.views.render',
{'template': 'press_releases/Cengage_to_provide_book_content.html'}, name="press/cengage-to-provide-book-content"),
url(r'^press/gates-foundation-announcement$', 'static_template_view.views.render',
{'template': 'press_releases/Gates_Foundation_announcement.html'}, name="press/gates-foundation-announcement"),
url(r'^press/wellesley-college-joins-edx$', 'static_template_view.views.render',
{'template': 'press_releases/Wellesley_College_joins_edX.html'}, name="press/wellesley-college-joins-edx"),
url(r'^press/georgetown-joins-edx$', 'static_template_view.views.render',
{'template': 'press_releases/Georgetown_joins_edX.html'}, name="press/georgetown-joins-edx"),
url(r'^press/spring-courses$', 'static_template_view.views.render',
{'template': 'press_releases/Spring_2013_course_announcements.html'},
name="press/spring-courses"),
url(r'^press/lewin-course-announcement$', 'static_template_view.views.render',
{'template': 'press_releases/Lewin_course_announcement.html'},
name="press/lewin-course-announcement"),
url(r'^press/bostonx-announcement$', 'static_template_view.views.render',
{'template': 'press_releases/bostonx_announcement.html'},
name="press/bostonx-announcement"),
url(r'^press/eric-lander-secret-of-life$', 'static_template_view.views.render',
{'template': 'press_releases/eric_lander_secret_of_life.html'},
name="press/eric-lander-secret-of-life"),
url(r'^press/edx-expands-internationally$', 'static_template_view.views.render',
{'template': 'press_releases/edx_expands_internationally.html'},
name="press/edx-expands-internationally"),
url(r'^press/xblock_announcement$', 'static_template_view.views.render',
{'template': 'press_releases/xblock_announcement.html'},
name="press/xblock-announcement"),
url(r'^press/stanford-to-work-with-edx$', 'static_template_view.views.render',
{'template': 'press_releases/stanford_announcement.html'},
name="press/stanford-to-work-with-edx"),
# Should this always update to point to the latest press release?
(r'^pressrelease$', 'django.views.generic.simple.redirect_to',
{'url': '/press/xblock-announcement'}),
url(r'^press/([_a-zA-Z0-9-]+)$', 'static_template_view.views.render_press_release', name='press_release'),
# Favicon
(r'^favicon\.ico$', 'django.views.generic.simple.redirect_to', {'url': '/static/images/favicon.ico'}),
# TODO: These urls no longer work. They need to be updated before they are re-enabled
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment