Fix failing behave tests

This commit is contained in:
Matthias Vogelgesang 2014-06-28 11:38:06 +02:00
parent 61739dd3b0
commit ae47c5bb80
4 changed files with 25 additions and 3 deletions

View file

@ -41,7 +41,7 @@ def open_journal(journal_name="default"):
config.update(journal_conf) config.update(journal_conf)
else: # But also just give them a string to point to the journal file else: # But also just give them a string to point to the journal file
config['journal'] = journal_conf config['journal'] = journal_conf
return Journal.Journal(**config) return Journal.open_journal(journal_name, config)
@given('we use the config "{config_file}"') @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", [])] entry.tags = [self.config['tagsymbols'][0] + tag for tag in dict_entry.get("Tags", [])]
self.entries.append(entry) self.entries.append(entry)
self.sort() self.sort()
return self
def write(self): def write(self):
"""Writes only the entries that have been modified into plist files.""" """Writes only the entries that have been modified into plist files."""

View file

@ -5,6 +5,8 @@ from __future__ import absolute_import, unicode_literals
from . import Entry from . import Entry
from . import util from . import util
from . import time from . import time
import os
import sys
import codecs import codecs
import re import re
from datetime import datetime from datetime import datetime
@ -224,3 +226,22 @@ class PlainJournal(Journal):
def _store(self, filename, text): def _store(self, filename, text):
with codecs.open(filename, 'w', "utf-8") as f: with codecs.open(filename, 'w', "utf-8") as f:
f.write(text) 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

@ -77,7 +77,7 @@ def encrypt(journal, filename=None):
new_journal.write(filename) new_journal.write(filename)
if util.yesno("Do you want to store the password in your keychain?", default=True): 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'])) util.prompt("Journal encrypted to {0}.".format(filename or new_journal.config['journal']))
@ -204,7 +204,7 @@ def run(manual_args=None):
else: else:
mode_compose = False mode_compose = False
journal = open_journal(journal_name, config) journal = Journal.open_journal(journal_name, config)
# Writing mode # Writing mode
if mode_compose: if mode_compose: