66
77from packaging .version import Version
88
9- from ..pandoc import get_pandoc_args , get_pandoc_reference_document , get_pandoc_reference_documents , get_pandoc_version
9+ from ..pandoc import (
10+ get_pandoc_args ,
11+ get_pandoc_content ,
12+ get_pandoc_content_disposition ,
13+ get_pandoc_reference_document ,
14+ get_pandoc_reference_documents ,
15+ get_pandoc_version ,
16+ )
1017
1118rdmo_path = Path (apps .get_app_config ('rdmo' ).path )
1219testing_path = rdmo_path .parent / 'testing'
6572class MockedView :
6673 uri = 'http://example.com/terms/views/view'
6774
75+
6876@pytest .mark .parametrize ('pandoc_version' , pandoc_versions )
6977def test_get_pandoc_version (mocker , pandoc_version ):
7078 mocker .patch ('pypandoc.get_pandoc_version' , return_value = pandoc_version )
@@ -75,9 +83,21 @@ def test_get_pandoc_version(mocker, pandoc_version):
7583@pytest .mark .parametrize ('export_format' , export_formats )
7684def test_get_pandoc_args (settings , mocker , pandoc_version , export_format ):
7785 mocker .patch ('pypandoc.get_pandoc_version' , return_value = pandoc_version )
86+ pandoc_args = pandoc_args_map [pandoc_version ].get (export_format , pandoc_args_map [pandoc_version ]['other' ])
87+
88+ assert get_pandoc_args (export_format , {}) == pandoc_args
89+
90+
91+ @pytest .mark .parametrize ('pandoc_version' , pandoc_versions )
92+ @pytest .mark .parametrize ('export_format' , export_formats )
93+ def test_get_pandoc_args_resource_path (settings , mocker , pandoc_version , export_format ):
94+ mocker .patch ('pypandoc.get_pandoc_version' , return_value = pandoc_version )
95+ pandoc_args = pandoc_args_map [pandoc_version ].get (export_format , pandoc_args_map [pandoc_version ]['other' ]).copy ()
96+
97+ if Version (pandoc_version ) >= Version ('2' ):
98+ pandoc_args .append (f'--resource-path={ testing_path } /media_root/test' )
7899
79- assert get_pandoc_args (export_format , {}) == \
80- pandoc_args_map [pandoc_version ].get (export_format , pandoc_args_map [pandoc_version ]['other' ])
100+ assert get_pandoc_args (export_format , {'resource_path' : 'test' }) == pandoc_args
81101
82102
83103def test_get_pandoc_reference_document (mocker ):
@@ -154,3 +174,29 @@ def test_get_pandoc_reference_documents_settings(settings, export_format):
154174 assert reference_documents == [mock_file , rdmo_path / 'share' / f'reference.{ export_format } ' ]
155175 else :
156176 assert reference_documents == []
177+
178+
179+ @pytest .mark .parametrize ('export_format' , export_formats )
180+ def test_get_pandoc_content (settings , export_format ):
181+ html_path = settings .BASE_DIR / 'export' / 'project.html'
182+ html = html_path .read_text ()
183+
184+ metadata = {
185+ 'title' : 'this is a very nice title' ,
186+ 'author' : ['author one' , 'author two' ],
187+ 'keywords' : ['nothing' , 'something' , 'whatever' ]
188+ }
189+
190+ assert len (get_pandoc_content (html , metadata , export_format , {})) > 0
191+
192+
193+ @pytest .mark .parametrize ('export_format' , export_formats )
194+ def test_get_pandoc_content_disposition (export_format ):
195+ title = 'Test'
196+
197+ if export_format == 'pdf' :
198+ content_disposition = f'filename="{ title } .{ export_format } "'
199+ else :
200+ content_disposition = f'attachment; filename="{ title } .{ export_format } "'
201+
202+ assert get_pandoc_content_disposition (export_format , 'Test' ) == content_disposition
0 commit comments