Skip to content

Commit

Permalink
LEARNER-4703: Adds in skeleton view and tests for Program Record page
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff LaJoie authored and jlajoie committed May 25, 2018
1 parent f57d52a commit dc58415
Show file tree
Hide file tree
Showing 19 changed files with 657 additions and 18 deletions.
68 changes: 68 additions & 0 deletions credentials/apps/records/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Tests for records rendering views.
"""
import uuid

from django.template.loader import select_template
from django.test import TestCase
from django.urls import reverse
Expand Down Expand Up @@ -76,3 +78,69 @@ def test_xss(self):
'\\u0022uuid\\u0022: \\u0022uuid\\u0022' +
'}]\')')
self.assertNotContains(response, '<xss>')


@override_flag(WAFFLE_FLAG_RECORDS, active=True)
class ProgramRecordViewTests(SiteMixin, TestCase):
MOCK_USER_DATA = {'username': 'test-user', 'name': 'Test User', 'email': 'test@example.org', }

def setUp(self):
super().setUp()
user = UserFactory(username=self.MOCK_USER_DATA['username'])
self.client.login(username=user.username, password=USER_PASSWORD)

def _render_program_record(self, record_data=None, status_code=200):
""" Helper method to render a user certificate."""
if record_data is None:
record_data = {}

with patch('credentials.apps.records.views.ProgramRecordView._get_record') as get_record:
get_record.return_value = record_data
response = self.client.get(reverse('records:programs', kwargs={'uuid': uuid.uuid4().hex}))
self.assertEqual(response.status_code, status_code)

return response

def assert_matching_template_origin(self, actual, expected_template_name):
expected = select_template([expected_template_name])
self.assertEqual(actual.origin, expected.origin)

def test_no_anonymous_access(self):
""" Verify that the view rejects non-logged-in users. """
self.client.logout()
response = self._render_program_record(status_code=302)
self.assertRegex(response.url, '^/login/.*') # pylint: disable=deprecated-method

@override_flag(WAFFLE_FLAG_RECORDS, active=False)
def test_feature_toggle(self):
""" Verify that the view rejects everyone without the waffle flag. """
self._render_program_record(status_code=404)

def test_normal_access(self):
""" Verify that the view works in default case. """
response = self._render_program_record()
response_context_data = response.context_data

self.assertContains(response, 'Record')

actual_child_templates = response_context_data['child_templates']
self.assert_matching_template_origin(actual_child_templates['footer'], '_footer.html')
self.assert_matching_template_origin(actual_child_templates['header'], '_header.html')

def test_xss(self):
""" Verify that the view protects against xss in translations. """
response = self._render_program_record({
"name": "<xss>",
'program': {
'name': '<xss>',
'school': 'XSS School',
},
'uuid': 'uuid',
})

# Test that the data is parsed from an escaped string
self.assertContains(response, "JSON.parse(\'{\\u0022name\\u0022: \\u0022\\u003Cxss\\u003E\\u0022, " +
"\\u0022program\\u0022: {\\u0022name\\u0022: \\u0022\\u003Cxss\\u003E\\u0022, " +
"\\u0022school\\u0022: \\u0022XSS School\\u0022}, \\u0022uuid\\u0022: " +
"\\u0022uuid\\u0022}\')")
self.assertNotContains(response, '<xss>')
3 changes: 3 additions & 0 deletions credentials/apps/records/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from django.conf.urls import url

from credentials.apps.credentials.constants import UUID_PATTERN

from . import views

urlpatterns = [
url(r'^$', views.RecordsView.as_view(), name='index'),
url(r'^programs/{uuid}/$'.format(uuid=UUID_PATTERN), views.ProgramRecordView.as_view(), name='programs'),
]
85 changes: 85 additions & 0 deletions credentials/apps/records/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,88 @@ def dispatch(self, request, *args, **kwargs):
if not waffle.flag_is_active(request, WAFFLE_FLAG_RECORDS):
raise http.Http404()
return super().dispatch(request, *args, **kwargs)


class ProgramRecordView(LoginRequiredMixin, TemplateView, ThemeViewMixin):
template_name = 'programs.html'

def _get_record(self):
# FIXME: Stop using fake data here, can reconsider data format as well
return {
'learner': {
'full_name': 'Firsty Lasty',
'username': 'edxIsGood',
'email': 'edx@example.com',
},
'program': {
'name': 'Test Program ',
'school': 'TestX'
},
'platform_name': 'edX',
'grades': [
{
'name': 'Course 1',
'school': 'TestX',
'attempts': 1,
'course_id': 'course1x',
'issue_date': '2018-01-01',
'percent_grade': '98%',
'letter_grade': 'A'
},
{
'name': 'Course 2',
'school': 'TestX',
'attempts': 1,
'course_id': 'course2x',
'issue_date': '2018-01-01',
'percent_grade': '98%',
'letter_grade': 'A'
},
{
'name': 'Course 3',
'school': 'TestX',
'attempts': 1,
'course_id': 'course3x',
'issue_date': '2018-01-01',
'percent_grade': '98%',
'letter_grade': 'A'
},
{
'name': 'Course 4',
'school': 'TestX',
'attempts': 1,
'course_id': 'course4x',
'issue_date': '2018-01-01',
'percent_grade': '98%',
'letter_grade': 'A'
},
{
'name': 'Course 5',
'school': 'TestX',
'attempts': 1,
'course_id': 'course5x',
'issue_date': '2018-01-01',
'percent_grade': '98%',
'letter_grade': 'A'
}
]
}

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
record = self._get_record()
context.update({
'child_templates': {
'footer': self.select_theme_template(['_footer.html']),
'header': self.select_theme_template(['_header.html']),
},
'record': json.dumps(record, sort_keys=True),
'program_name': record.get('program', {}).get('name'),
'render_language': self.request.LANGUAGE_CODE,
})
return context

def dispatch(self, request, *args, **kwargs):
if not waffle.flag_is_active(request, WAFFLE_FLAG_RECORDS):
raise http.Http404()
return super().dispatch(request, *args, **kwargs)
Binary file modified credentials/conf/locale/en/LC_MESSAGES/django.mo
Binary file not shown.
9 changes: 7 additions & 2 deletions credentials/conf/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.1a\n"
"Report-Msgid-Bugs-To: openedx-translation@googlegroups.com\n"
"POT-Creation-Date: 2018-05-02 19:21+0000\n"
"PO-Revision-Date: 2018-05-02 19:21:08.156287\n"
"POT-Creation-Date: 2018-05-25 15:29+0000\n"
"PO-Revision-Date: 2018-05-25 15:29:12.579438\n"
"Last-Translator: \n"
"Language-Team: openedx-translation <openedx-translation@googlegroups.com>\n"
"Language: en\n"
Expand Down Expand Up @@ -373,6 +373,11 @@ msgstr ""
msgid "Clear cache"
msgstr ""

#: templates/programs.html
#, python-brace-format
msgid "{program_name} Record"
msgstr ""

#: templates/records.html
msgid "My Records"
msgstr ""
Expand Down
Binary file modified credentials/conf/locale/en/LC_MESSAGES/djangojs.mo
Binary file not shown.
100 changes: 94 additions & 6 deletions credentials/conf/locale/en/LC_MESSAGES/djangojs.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,107 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.1a\n"
"Report-Msgid-Bugs-To: openedx-translation@googlegroups.com\n"
"POT-Creation-Date: 2018-05-02 19:21+0000\n"
"PO-Revision-Date: 2018-05-02 19:21:08.159602\n"
"POT-Creation-Date: 2018-05-25 15:29+0000\n"
"PO-Revision-Date: 2018-05-25 15:29:12.574200\n"
"Last-Translator: \n"
"Language-Team: openedx-translation <openedx-translation@googlegroups.com>\n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: static/components/ProgramRecord.jsx
msgid "< Back to My Records"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "Share"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "{program_name} Record"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "{platform} | {school}"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "Name"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "{platform} User ID"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "Email"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "Name: {}"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "{platform} User ID: {}"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "Email: {}"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "Course Name"
msgstr ""

#: static/components/ProgramRecord.jsx static/components/RecordsList.jsx
msgid "School"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "Verified Attempts"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "Course ID"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "Issue Date"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "Highest Grade Earned"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "Letter Grade"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "Verified Attempts: {}"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "Course ID: {}"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "Start Date: {}"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "End Date: {}"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "Percent Grade: {}"
msgstr ""

#: static/components/ProgramRecord.jsx
msgid "Letter Grade: {}"
msgstr ""

#: static/components/RecordsList.jsx
msgid "FAQ"
msgstr ""
Expand All @@ -28,10 +120,6 @@ msgstr ""
msgid "Program Name"
msgstr ""

#: static/components/RecordsList.jsx
msgid "School"
msgstr ""

#: static/components/RecordsList.jsx
msgid "Record Link"
msgstr ""
Expand Down
Binary file modified credentials/conf/locale/eo/LC_MESSAGES/django.mo
Binary file not shown.
9 changes: 7 additions & 2 deletions credentials/conf/locale/eo/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.1a\n"
"Report-Msgid-Bugs-To: openedx-translation@googlegroups.com\n"
"POT-Creation-Date: 2018-05-02 19:21+0000\n"
"PO-Revision-Date: 2018-05-02 19:21:08.156287\n"
"POT-Creation-Date: 2018-05-25 15:29+0000\n"
"PO-Revision-Date: 2018-05-25 15:29:12.579438\n"
"Last-Translator: \n"
"Language-Team: openedx-translation <openedx-translation@googlegroups.com>\n"
"Language: eo\n"
Expand Down Expand Up @@ -434,6 +434,11 @@ msgstr "Mänägémént Vïéw Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт α#"
msgid "Clear cache"
msgstr "Çléär çäçhé Ⱡ'σяєм ιρѕυм ∂σłσя #"

#: templates/programs.html
#, python-brace-format
msgid "{program_name} Record"
msgstr "{program_name} Réçörd Ⱡ'σяєм ιρѕυм ∂σłσ#"

#: templates/records.html
msgid "My Records"
msgstr "Mý Réçörds Ⱡ'σяєм ιρѕυм ∂σłσ#"
Expand Down
Binary file modified credentials/conf/locale/eo/LC_MESSAGES/djangojs.mo
Binary file not shown.
Loading

0 comments on commit dc58415

Please sign in to comment.