44from typing import Any
55from unittest .mock import MagicMock , patch
66
7- from django .test import override_settings
87from xblock .field_data import DictFieldData
98from xblock .fields import ScopeIds
109from xblock .test .toy_runtime import ToyRuntime
@@ -52,7 +51,7 @@ def test_download_button():
5251
5352
5453def test_source_url ():
55- """Test rendering based on whether or not there's a source URL"""
54+ """Test rendering based on whether there's a source URL"""
5655 block = make_block ()
5756 get_student_content (block )
5857 content = get_student_content (block )
@@ -62,60 +61,6 @@ def test_source_url():
6261 assert "Download the source document" in content
6362
6463
65- @override_settings (PDFXBLOCK_DISABLE_ALL_DOWNLOAD = False )
66- def test_saves_settings ():
67- """Test that PDF settings are saved."""
68- block = make_block ()
69- request = mock_handle_request (
70- {
71- "display_name" : "Novel application of theory" ,
72- "url" : "https://example.com/nature_article.pdf" ,
73- "allow_download" : "false" ,
74- "source_text" : "Get educated" ,
75- "source_url" : "https://example.com/nature_article.tex" ,
76- }
77- )
78- block .save_pdf (request )
79- assert block .display_name == "Novel application of theory"
80- assert block .url == "https://example.com/nature_article.pdf"
81- assert not block .allow_download
82- assert block .source_text == "Get educated"
83- assert block .source_url == "https://example.com/nature_article.tex"
84-
85-
86- @override_settings (PDFXBLOCK_DISABLE_ALL_DOWNLOAD = True )
87- def test_saves_settings_omits_on_download_disabled_flag ():
88- """
89- Test that fields relating to download are ignored when the universal
90- downloads disabled flag is set.
91- """
92- block = make_block ()
93- request = mock_handle_request (
94- {
95- "display_name" : "Novel application of theory" ,
96- "url" : "https://example.com/nature_article.pdf" ,
97- # These fields shouldn't be visible on the front end,
98- # but should be dropped if they somehow are.
99- #
100- # Potential future improvement would be saving these
101- # but ignoring them when rendering. This is not currently
102- # the case since the fields are entirely absent from the studio
103- # render, and so would send blank data which would error out.
104- "allow_download" : "false" ,
105- "source_text" : "Get educated" ,
106- "source_url" : "https://example.com/nature_article.tex" ,
107- }
108- )
109- block .save_pdf (request )
110- assert block .display_name == "Novel application of theory"
111- assert block .url == "https://example.com/nature_article.pdf"
112- # Flag will be the default, which is True, even though download will be
113- # disabled in practice.
114- assert block .allow_download
115- assert block .source_text == ""
116- assert block .source_url == ""
117-
118-
11964@patch .object (ToyRuntime , "publish" )
12065def test_download_event_fires (mock_publish ):
12166 """Test that we fire a download event."""
0 commit comments