Commit graph

14 commits

Author SHA1 Message Date
bnewc
752eff02d8
Prevent user from using illegal characters in output filename
Add some checks in the Dangerzone GUI and CLI that will prevent a user
from mistakenly adding illegal characters in the output filename.
2024-10-07 18:04:47 +03:00
9bad001c04
chore: remove fixture imports in the tests
They ideally should find their way by themselves.

> You don’t need to import the fixture you want to use in a test,
> it automatically gets discovered by pytest. The discovery of fixture
> functions starts at test classes, then test modules, then conftest.py
> files and finally builtin and third party plugins.>
>
> — [pytest docs](https://docs.pytest.org/en/4.6.x/fixture.html#conftest-py-sharing-fixture-functions)
2024-06-05 15:56:09 +02:00
Alexis Métaireau
cbbd6afcc1
chore: remove unused code
This commit removes code that's not being used, it can be exceptions
with the `as e` where the exception itself is not used, the same with
`with` statements, and some other parts where there were duplicated
code.
2024-06-05 14:19:31 +02:00
Alexis Métaireau
5aa4863b52
chore(imports): remove useless imports
As detected by [ruff](https://github.com/astral-sh/ruff)

Related to #254, although it doesn't provide the command to lint the
codebase itself.
2024-06-05 14:19:30 +02:00
Alex Pyrgiotis
1c70ee6771
Fix archiving the same doc twice on Windows
On Windows, if we somehow attempt to archive the same document twice
(e.g, because it got archived once, and then we copy it back), we will
get an error, because Windows does not overwrite the target path, if it
already exists.

Fix this issue by always removing the previously archived version, when
performing the next archival action, and update our tests.
2024-05-09 15:57:42 +03:00
deeplow
6216761058
remove number from test_doc2 variable
create a pytest fixture for a .doc file and .pdf file
2023-07-25 15:00:31 +01:00
deeplow
c6a0b59379
Add unit tests to cover archive-related methods
Additionally this adds the pytest-mock dev dependency to be able to mock
certain methods.
2022-11-24 11:16:34 +00:00
Alex Pyrgiotis
699258543a
Fail if a provided suffix cannot be applied
If a user has provided an output filename for a document, then we should
no longer accept suffixes. The reason is that we can't do something
meaningful with it, as we can't alter the provided output filename.

The proper behavior is to reject this action with an exception. Note
that this acts more of a safeguard, since (currently) there is no path
where a user may add a suffix to a document that already has an output
filename.
2022-11-21 12:39:25 +00:00
deeplow
5a6c72f09e
Add output_dir manipulation methods to DocumentHolder
These will be needed in for the GUI's settings. This also adds test
cases for these documents. The methods are the following:

  - set_output_dir()
    For changing the output directory of the safe file

  - suffix setter and getter - for changing the suffix of the file
2022-11-21 12:37:47 +00:00
deeplow
0b738ba490
Do not create outfile files when checking if writeable
Checking if files were writeable created files in the process. In the
case where someone adds a list of N files to dangerzone but exits before
converting, they would be left with N 0-byte files for the -safe
version. Now they don't.

Fixes #214
2022-11-14 09:04:54 +00:00
deeplow
93f17b3166
Specialize DocumentFilenameException() for disambiguation
All filename-related exceptions were of class DocumentFilenameException.
This made it difficult to disambiguate them. Specializing them makes it
it easier for tests to detect which exception in particular we want to
verify.
2022-11-14 09:04:23 +00:00
deeplow
d71e230173
Update document state exclusively in convert()
The document's state update is better update in the convert() function.
This is because this function is always called for the conversion
progress regardless of the frontend.
2022-11-14 09:03:50 +00:00
deeplow
981716ccff
Sequential bulk document support in cli
Basic implementation of bulk document support in dangerzone-cli.

Usage: dangerzone-cli [OPTIONS] doc1.pdf doc2.pdf
2022-11-14 08:51:00 +00:00
deeplow
be5a942a73
Add unit tests for document.py 2022-10-27 13:44:09 +01:00