Adding documentation

This commit is contained in:
Trenton H
2024-06-06 08:23:44 -07:00
parent bccd1d11d3
commit 9251a3054f
4 changed files with 100 additions and 9 deletions

View File

@@ -206,7 +206,7 @@ class Command(CryptMixin, BaseCommand):
if (
self.version is not None
and self.version != version.__full_version_str__
):
): # pragma: no cover
self.stdout.write(
self.style.ERROR(
"Version mismatch: "
@@ -235,10 +235,10 @@ class Command(CryptMixin, BaseCommand):
self.pre_check()
self.load_manifest_files()
self.load_metadata()
self.load_manifest_files()
self.check_manifest_validity()
self.decrypt_secret_fields()
@@ -404,8 +404,18 @@ class Command(CryptMixin, BaseCommand):
# Salt has been loaded from metadata.json at this point, so it cannot be None
self.setup_crypto(passphrase=self.passphrase, salt=self.salt)
for record in self.manifest:
had_an_account = False
for index, record in enumerate(self.manifest):
if record["model"] == "paperless_mail.mailaccount":
record["fields"]["password"] = self.decrypt_string(
value=record["fields"]["password"],
)
self.manifest[index] = record
had_an_account = True
if had_an_account:
# It's annoying, but the DB is loaded from the JSON directly
# Maybe could change that in the future?
(self.source / "manifest.json").write_text(
json.dumps(self.manifest, indent=2, ensure_ascii=False),
)

View File

@@ -886,3 +886,38 @@ class TestCryptExportImport(
mail_account_data = mail_accounts[0]
self.assertNotEqual(mail_account_data["fields"]["password"], "mypassword")
MailAccount.objects.all().delete()
call_command(
"document_importer",
"--no-progress-bar",
"--passphrase",
"securepassword",
self.target,
)
account = MailAccount.objects.first()
self.assertIsNotNone(account)
self.assertEqual(account.password, "mypassword")
def test_import_crypt_no_passphrase(self):
call_command(
"document_exporter",
"--no-progress-bar",
"--passphrase",
"securepassword",
self.target,
)
with self.assertRaises(CommandError) as err:
call_command(
"document_importer",
"--no-progress-bar",
self.target,
)
self.assertEqual(
err.msg,
"No passphrase was given, but this export contains encrypted fields",
)

View File

@@ -279,3 +279,43 @@ class TestCommandImport(
"Found existing documents(s), this might indicate a non-empty installation",
str(stdout.read()),
)
def test_import_no_metadata_or_version_file(self):
stdout = StringIO()
(self.dirs.scratch_dir / "manifest.json").touch()
# We're not building a manifest, so it fails, but this test doesn't care
with self.assertRaises(json.decoder.JSONDecodeError):
call_command(
"document_importer",
"--no-progress-bar",
str(self.dirs.scratch_dir),
stdout=stdout,
)
stdout.seek(0)
stdout_str = str(stdout.read())
self.assertIn("No version.json or metadata.json file located", stdout_str)
def test_import_version_file(self):
stdout = StringIO()
(self.dirs.scratch_dir / "manifest.json").touch()
(self.dirs.scratch_dir / "version.json").write_text(
json.dumps({"version": "2.8.1"}),
)
# We're not building a manifest, so it fails, but this test doesn't care
with self.assertRaises(json.decoder.JSONDecodeError):
call_command(
"document_importer",
"--no-progress-bar",
str(self.dirs.scratch_dir),
stdout=stdout,
)
stdout.seek(0)
stdout_str = str(stdout.read())
self.assertIn("Version mismatch:", stdout_str)
self.assertIn("importing 2.8.1", stdout_str)