Commit 5128a4f5 by Andy Armstrong

Fix learner profile bug and tests that didn't catch it

parent ff5c6f0c
...@@ -19,10 +19,10 @@ from openedx.core.djangolib.markup import HTML, Text ...@@ -19,10 +19,10 @@ from openedx.core.djangolib.markup import HTML, Text
course = certificate['course'] course = certificate['course']
completion_date_message_html = Text(_('Completed {completion_date_html}')).format( completion_date_message_html = Text(_('Completed {completion_date_html}')).format(
completion_date=HTML( completion_date_html=HTML(
'<span' '<span'
' class="localized-datetime start-date"' ' class="localized-datetime start-date"'
' data-datetime="{completion_date_html}"' ' data-datetime="{completion_date}"'
' data-format="shortDate"' ' data-format="shortDate"'
' data-timezone="{user_timezone}"' ' data-timezone="{user_timezone}"'
' data-language="{user_language}"' ' data-language="{user_language}"'
......
...@@ -4,20 +4,20 @@ ...@@ -4,20 +4,20 @@
import datetime import datetime
import ddt import ddt
from certificates.tests.factories import GeneratedCertificateFactory # pylint: disable=import-error
from course_modes.models import CourseMode
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.client import RequestFactory from django.test.client import RequestFactory
from util.testing import UrlResetMixin from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag
from course_modes.models import CourseMode
from certificates.tests.factories import GeneratedCertificateFactory # pylint: disable=import-error
from student.tests.factories import CourseEnrollmentFactory, UserFactory
from openedx.features.learner_profile.views.learner_profile import learner_profile_context from openedx.features.learner_profile.views.learner_profile import learner_profile_context
from student.tests.factories import CourseEnrollmentFactory, UserFactory
from util.testing import UrlResetMixin
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from ... import SHOW_ACHIEVEMENTS_FLAG
@ddt.ddt @ddt.ddt
class LearnerProfileViewTest(UrlResetMixin, ModuleStoreTestCase): class LearnerProfileViewTest(UrlResetMixin, ModuleStoreTestCase):
...@@ -130,6 +130,7 @@ class LearnerProfileViewTest(UrlResetMixin, ModuleStoreTestCase): ...@@ -130,6 +130,7 @@ class LearnerProfileViewTest(UrlResetMixin, ModuleStoreTestCase):
) )
@ddt.data(CourseMode.HONOR, CourseMode.PROFESSIONAL, CourseMode.VERIFIED) @ddt.data(CourseMode.HONOR, CourseMode.PROFESSIONAL, CourseMode.VERIFIED)
@override_waffle_flag(SHOW_ACHIEVEMENTS_FLAG, active=True)
def test_certificate_visibility(self, cert_mode): def test_certificate_visibility(self, cert_mode):
""" """
Verify that certificates are displayed with the correct card mode. Verify that certificates are displayed with the correct card mode.
...@@ -138,27 +139,22 @@ class LearnerProfileViewTest(UrlResetMixin, ModuleStoreTestCase): ...@@ -138,27 +139,22 @@ class LearnerProfileViewTest(UrlResetMixin, ModuleStoreTestCase):
cert = self._create_certificate(cert_mode) cert = self._create_certificate(cert_mode)
cert.save() cert.save()
request = RequestFactory().get('/url') response = self.client.get('/u/{username}'.format(username=self.user.username))
request.user = self.user
context = learner_profile_context(request, self.user.username, self.user.is_staff)
self.assertTrue('card certificate-card mode-' + cert_mode in str(context['achievements_fragment'].content)) self.assertContains(response, 'card certificate-card mode-{cert_mode}'.format(cert_mode=cert_mode))
@ddt.data(True, False) @ddt.data(True, False)
@override_waffle_flag(SHOW_ACHIEVEMENTS_FLAG, active=True)
def test_no_certificate_visibility(self, own_profile): def test_no_certificate_visibility(self, own_profile):
""" """
Verify that the 'You haven't earned any certificates yet.' well appears on the user's Verify that the 'You haven't earned any certificates yet.' well appears on the user's
own profile when they do not have certificates and does not appear when viewing own profile when they do not have certificates and does not appear when viewing
another user that does not have any certificates. another user that does not have any certificates.
""" """
request = RequestFactory().get('/url')
request.user = self.user
profile_username = self.user.username if own_profile else self.other_user.username profile_username = self.user.username if own_profile else self.other_user.username
context = learner_profile_context(request, profile_username, self.user.is_staff) response = self.client.get('/u/{username}'.format(username=profile_username))
if own_profile: if own_profile:
content = str(context['achievements_fragment'].content) self.assertContains(response, 'You haven&#39;t earned any certificates yet.')
self.assertIn('icon fa fa-search', content)
self.assertIn("You haven't earned any certificates yet", content)
else: else:
self.assertIsNone(context['achievements_fragment']) self.assertNotContains(response, 'You haven&#39;t earned any certificates yet.')
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