-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import os | ||
import tempfile | ||
|
||
import pytest | ||
|
||
from dangerzone.document import DocumentFilenameException, DocumentHolder | ||
|
||
from . import sample_doc | ||
|
||
|
||
@pytest.fixture | ||
def unwriteable_pdf(): | ||
file_path = tempfile.mktemp(suffix=".pdf") | ||
with open(file_path, "w+"): | ||
# create file | ||
pass | ||
os.chmod(file_path, mode=600) | ||
return file_path | ||
|
||
|
||
@pytest.fixture | ||
def unreadable_pdf(): | ||
file_path = tempfile.mktemp(suffix=".pdf") | ||
with open(file_path, "w+"): | ||
# create file | ||
pass | ||
os.chmod(file_path, mode=0) | ||
return file_path | ||
|
||
|
||
def test_input_sample_init(sample_doc): | ||
DocumentHolder(sample_doc) | ||
|
||
|
||
def test_input_sample_after(sample_doc): | ||
d = DocumentHolder() | ||
d.input_filename = sample_doc | ||
|
||
|
||
def test_input_file_none(): | ||
""" | ||
Attempts to read a document's filename when no doc has been set | ||
""" | ||
d = DocumentHolder() | ||
with pytest.raises(DocumentFilenameException): | ||
d.input_filename | ||
|
||
|
||
def test_input_file_non_existing(): | ||
with pytest.raises(DocumentFilenameException): | ||
DocumentHolder("fake-dir/non-existing-file.pdf") | ||
|
||
|
||
def test_input_file_unreadable(unreadable_pdf): | ||
with pytest.raises(DocumentFilenameException): | ||
DocumentHolder(unreadable_pdf) | ||
|
||
|
||
def test_output_file_unwriteable(unwriteable_pdf): | ||
d = DocumentHolder() | ||
with pytest.raises(DocumentFilenameException): | ||
d.output_filename = unwriteable_pdf | ||
|
||
|
||
def test_output(): | ||
pdf_file = tempfile.mktemp(suffix=".pdf") | ||
d = DocumentHolder() | ||
d.output_filename = pdf_file | ||
|
||
|
||
def test_output_file_none(): | ||
""" | ||
Attempts to read a document's filename when no doc has been set | ||
""" | ||
d = DocumentHolder() | ||
with pytest.raises(DocumentFilenameException): | ||
d.output_filename(self, filename) | ||
|
||
|
||
def test_output_file_not_pdf(): | ||
docx_file = tempfile.mktemp(suffix=".docx") | ||
d = DocumentHolder() | ||
|
||
with pytest.raises(DocumentFilenameException): | ||
d.output_filename = docx_file | ||
|
||
assert not os.path.exists(docx_file) |