Fix failing behave tests

This commit is contained in:
Matthias Vogelgesang 2014-06-28 11:38:06 +02:00 committed by Manuel Ebert
parent b6ef517356
commit 06f8dbe678
4 changed files with 25 additions and 20 deletions

View file

@ -41,7 +41,7 @@ def open_journal(journal_name="default"):
config.update(journal_conf)
else: # But also just give them a string to point to the journal file
config['journal'] = journal_conf
return Journal.Journal(**config)
return Journal.open_journal(journal_name, config)
@given('we use the config "{config_file}"')

View file

@ -50,6 +50,7 @@ class DayOne(Journal.Journal):
entry.tags = [self.config['tagsymbols'][0] + tag for tag in dict_entry.get("Tags", [])]
self.entries.append(entry)
self.sort()
return self
def write(self):
"""Writes only the entries that have been modified into plist files."""

View file

@ -5,6 +5,8 @@ from __future__ import absolute_import
from . import Entry
from . import util
from datetime import datetime
import os
import sys
import codecs
import re
import dateutil
@ -267,3 +269,22 @@ class PlainJournal(Journal):
def _store(self, filename, text):
with codecs.open(filename, 'w', "utf-8") as f:
f.write(text)
def open_journal(name, config):
"""
Creates a normal, encrypted or DayOne journal based on the passed config.
"""
if os.path.isdir(config['journal']):
if config['journal'].strip("/").endswith(".dayone") or "entries" in os.listdir(config['journal']):
from . import DayOneJournal
return DayOneJournal.DayOne(**config).open()
else:
util.prompt(u"[Error: {0} is a directory, but doesn't seem to be a DayOne journal either.".format(config['journal']))
sys.exit(1)
if not config['encrypt']:
return PlainJournal(name, **config).open()
else:
from . import EncryptedJournal
return EncryptedJournal.EncryptedJournal(name, **config).open()

View file

@ -76,7 +76,7 @@ def encrypt(journal, filename=None):
new_journal.write(filename)
if util.yesno("Do you want to store the password in your keychain?", default=True):
util.set_keychain(journal.name, password)
util.set_keychain(journal.name, journal.config['password'])
util.prompt("Journal encrypted to {0}.".format(filename or new_journal.config['journal']))
@ -119,23 +119,6 @@ def update_config(config, new_config, scope, force_local=False):
config.update(new_config)
def open_journal(name, config):
"""
Creates a normal, encrypted or DayOne journal based on the passed config.
"""
if os.path.isdir(config['journal']):
if config['journal'].strip("/").endswith(".dayone") or "entries" in os.listdir(config['journal']):
from . import DayOneJournal
return DayOneJournal.DayOne(**config).open()
else:
util.prompt(u"[Error: {0} is a directory, but doesn't seem to be a DayOne journal either.".format(config['journal']))
sys.exit(1)
if not config['encrypt']:
return Journal.PlainJournal(name, **config).open()
else:
from . import EncryptedJournal
return EncryptedJournal.EncryptedJournal(name, **config).open()
def run(manual_args=None):
@ -199,7 +182,7 @@ def run(manual_args=None):
else:
mode_compose = False
journal = open_journal(journal_name, config)
journal = Journal.open_journal(journal_name, config)
# Writing mode
if mode_compose: