@@ -223,7 +223,7 @@ def test_unit_parse_form_data_none_filename_error():
223223
224224
225225def test_unit_is_pdf_valid_pdf ():
226- """Test is pdf method returns True for valid pdf file (has .pdf extension and can be read) ."""
226+ """Test is pdf method returns True for valid pdf file with filename ."""
227227 filename = "_sample_docs/layout-parser-paper-fast.pdf"
228228
229229 with open (filename , "rb" ) as f :
@@ -237,28 +237,48 @@ def test_unit_is_pdf_valid_pdf():
237237 assert result is True
238238
239239
240- def test_unit_is_pdf_invalid_extension (caplog ):
240+ def test_unit_is_pdf_valid_pdf_without_file_extension ():
241+ """Test is pdf method returns True for file with valid pdf content without basing on file extension."""
242+ filename = "_sample_docs/layout-parser-paper-fast.pdf"
243+
244+ with open (filename , "rb" ) as f :
245+ file = shared .Files (
246+ content = f .read (),
247+ file_name = "uuid1234" ,
248+ )
249+
250+ result = pdf_utils .is_pdf (file )
251+
252+ assert result is True
253+
254+
255+ def test_unit_is_pdf_invalid_extension ():
241256 """Test is pdf method returns False for file with invalid extension."""
242257 file = shared .Files (content = b"txt_content" , file_name = "test_file.txt" )
243258
244- with caplog .at_level (logging .INFO ):
245- result = pdf_utils .is_pdf (file )
259+ result = pdf_utils .is_pdf (file )
246260
247261 assert result is False
248- assert "Given file doesn't have '.pdf' extension" in caplog .text
249262
250263
251- def test_unit_is_pdf_invalid_pdf (caplog ):
264+ def test_unit_is_pdf_invalid_pdf ():
252265 """Test is pdf method returns False for file with invalid pdf content."""
253266 file = shared .Files (content = b"invalid_pdf_content" , file_name = "test_file.pdf" )
254267
255- with caplog .at_level (logging .WARNING ):
256- result = pdf_utils .is_pdf (file )
268+ result = pdf_utils .is_pdf (file )
257269
258270 assert result is False
259- assert "The file does not appear to be a valid PDF." in caplog .text
260271
261272
273+ def test_unit_is_pdf_invalid_pdf_without_file_extension ():
274+ """Test is pdf method returns False for file with invalid pdf content without basing on file extension."""
275+ file = shared .Files (content = b"invalid_pdf_content" , file_name = "uuid1234" )
276+
277+ result = pdf_utils .is_pdf (file )
278+
279+ assert result is False
280+
281+
262282def test_unit_get_starting_page_number_missing_key ():
263283 """Test _get_starting_page_number method with missing key."""
264284 form_data = {}
0 commit comments