55
66import itertools
77import json
8- from unittest import mock
98
109import ddt
1110from django .conf import settings
1211from django .test .utils import override_settings
13- from edx_toggles .toggles .testutils import override_waffle_flag
1412from opaque_keys .edx .keys import AssetKey
1513
16- from cms .djangoapps .contentstore import toggles
1714from cms .djangoapps .contentstore .tests .utils import CourseTestCase
1815from cms .djangoapps .contentstore .utils import get_lms_link_for_certificate_web_view , reverse_course_url
1916from common .djangoapps .course_modes .tests .factories import CourseModeFactory
@@ -277,11 +274,9 @@ def test_lms_link_for_certificate_web_view(self):
277274 )
278275 self .assertEqual (link , test_url ) # noqa: PT009
279276
280- @override_waffle_flag (toggles .LEGACY_STUDIO_CERTIFICATES , True )
281- @mock .patch .dict ('django.conf.settings.FEATURES' , {'CERTIFICATES_HTML_VIEW' : True })
282277 def test_certificate_info_in_response (self ):
283278 """
284- Test that certificate has been created and rendered properly with non-audit course mode .
279+ Test that a created certificate is returned in the JSON GET response .
285280 """
286281 CourseModeFactory .create (course_id = self .course .id , mode_slug = 'verified' )
287282 response = self .client .ajax_post (
@@ -291,36 +286,13 @@ def test_certificate_info_in_response(self):
291286
292287 self .assertEqual (response .status_code , 201 ) # noqa: PT009
293288
294- # in html response
295- result = self .client .get_html (self ._url ())
296- self .assertContains (result , 'Test certificate' )
297- self .assertContains (result , 'Test description' )
298-
299- # in JSON response
300289 response = self .client .get_json (self ._url ())
301290 data = json .loads (response .content .decode ('utf-8' ))
302291 self .assertEqual (len (data ), 1 ) # noqa: PT009
303292 self .assertEqual (data [0 ]['name' ], 'Test certificate' ) # noqa: PT009
304293 self .assertEqual (data [0 ]['description' ], 'Test description' ) # noqa: PT009
305294 self .assertEqual (data [0 ]['version' ], CERTIFICATE_SCHEMA_VERSION ) # noqa: PT009
306295
307- @mock .patch .dict ('django.conf.settings.FEATURES' , {'CERTIFICATES_HTML_VIEW' : True })
308- @override_waffle_flag (toggles .LEGACY_STUDIO_CERTIFICATES , True )
309- def test_certificate_info_not_in_response (self ):
310- """
311- Test that certificate has not been rendered audit only course mode.
312- """
313- response = self .client .ajax_post (
314- self ._url (),
315- data = CERTIFICATE_JSON_WITH_SIGNATORIES
316- )
317-
318- self .assertEqual (response .status_code , 201 ) # noqa: PT009
319-
320- # in html response
321- result = self .client .get_html (self ._url ())
322- self .assertNotContains (result , 'Test certificate' )
323-
324296 def test_unsupported_http_accept_header (self ):
325297 """
326298 Test if not allowed header present in request.
@@ -350,55 +322,6 @@ def test_not_permitted(self):
350322 )
351323 self .assertContains (response , "error" , status_code = 403 )
352324
353- @override_waffle_flag (toggles .LEGACY_STUDIO_CERTIFICATES , True )
354- def test_audit_course_mode_is_skipped (self ):
355- """
356- Tests audit course mode is skipped when rendering certificates page.
357- """
358- CourseModeFactory .create (course_id = self .course .id )
359- CourseModeFactory .create (course_id = self .course .id , mode_slug = 'verified' )
360- response = self .client .get_html (
361- self ._url (),
362- )
363- self .assertEqual (response .status_code , 200 ) # noqa: PT009
364- self .assertContains (response , 'verified' )
365- self .assertNotContains (response , 'audit' )
366-
367- @override_waffle_flag (toggles .LEGACY_STUDIO_CERTIFICATES , True )
368- def test_audit_only_disables_cert (self ):
369- """
370- Tests audit course mode is skipped when rendering certificates page.
371- """
372- CourseModeFactory .create (course_id = self .course .id , mode_slug = 'audit' )
373- response = self .client .get_html (
374- self ._url (),
375- )
376- self .assertEqual (response .status_code , 200 ) # noqa: PT009
377- self .assertContains (response , 'This course does not use a mode that offers certificates.' )
378- self .assertNotContains (response , 'This module is not enabled.' )
379- self .assertNotContains (response , 'Loading' )
380-
381- @ddt .data (
382- ['audit' , 'verified' ],
383- ['verified' ],
384- ['audit' , 'verified' , 'credit' ],
385- ['verified' , 'credit' ],
386- ['professional' ]
387- )
388- @override_waffle_flag (toggles .LEGACY_STUDIO_CERTIFICATES , True )
389- def test_non_audit_enables_cert (self , slugs ):
390- """
391- Tests audit course mode is skipped when rendering certificates page.
392- """
393- for slug in slugs :
394- CourseModeFactory .create (course_id = self .course .id , mode_slug = slug )
395- response = self .client .get_html (
396- self ._url (),
397- )
398- self .assertEqual (response .status_code , 200 ) # noqa: PT009
399- self .assertNotContains (response , 'This course does not use a mode that offers certificates.' )
400- self .assertNotContains (response , 'This module is not enabled.' )
401- self .assertContains (response , 'Loading' )
402325
403326 def test_assign_unique_identifier_to_certificates (self ):
404327 """
0 commit comments