jrnl/tests/test_plugin.py
MinchinWeb 80a1eeff42
Plugin list on Diagnostic (#1282)
* CLI: Unhide "diagnostic" commandline option
* Display loaded plugins under "--diagnostic" rather than "--version"
* Align plugin names on diagnostic
* Store plugin module paths as variables
* Don't display full plugin module paths for built in and "regular" contributed plugins
* Make flake8 happy
* Adjust new plugin imports
2021-10-16 13:58:24 -07:00

46 lines
1.4 KiB
Python

from datetime import date
import json
import pytest
from jrnl import Entry
from jrnl import Journal
from jrnl.plugins.exporter import json as json_exporter
try:
from jrnl.contrib.exporter import testing as testing_exporter
except ImportError:
testing_exporter = None
if testing_exporter:
@pytest.fixture()
def create_entry():
entry = Entry.Entry(
journal=Journal.Journal(),
text="This is the entry text",
date=date(year=2001, month=1, day=1),
starred=True,
)
yield entry
class TestBaseExporter(testing_exporter.Exporter):
def test_unimplemented_export(self, create_entry):
entry = create_entry
with pytest.raises(NotImplementedError):
self.export_entry(entry)
class TestJsonExporter(json_exporter.Exporter):
def test_json_exporter_name(self):
assert "json" in self.names
def test_export_entry(self, create_entry):
entry = create_entry
fake_uuid = "ewqf09-432p9p0433-243209" # generated by mashing keys
entry.uuid = fake_uuid
exported = self.export_entry(entry)
deserialized_export = json.loads(exported)
assert deserialized_export["title"] == "This is the entry text"
assert deserialized_export["date"] == "2001-01-01"
assert "uuid" in deserialized_export.keys()