Skip to content

Commit

Permalink
Preprocess start/end CLI options for add command
Browse files Browse the repository at this point in the history
  • Loading branch information
pylipp committed Dec 31, 2020
1 parent 96e6841 commit f06471f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
17 changes: 9 additions & 8 deletions financeager/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,15 @@ def _preprocess(data):
:raises: PreprocessError if preprocessing failed.
"""
date = data.get("date")
if date is not None:
try:
date = time.strftime(POCKET_DATE_FORMAT,
du_parser.parse(date).timetuple())
data["date"] = date
except ValueError:
raise exceptions.PreprocessingError("Invalid date format.")
for field in ["date", "start", "end"]:
date = data.get(field)
if date is not None:
try:
date = time.strftime(POCKET_DATE_FORMAT,
du_parser.parse(date).timetuple())
data[field] = date
except ValueError:
raise exceptions.PreprocessingError("Invalid date format.")

filter_items = data.get("filters")
if filter_items is not None:
Expand Down
24 changes: 24 additions & 0 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,30 @@ def test_convert_periods_to_pocket(self):
disk_period_content = json.load(f)
self.assertDictEqual(period_content, disk_period_content)

def test_add_recurrent_entry(self):
entry_id = self.cli_run(
"add credit -100 -t recurrent -f monthly -s 01-01")
self.assertEqual(entry_id, 1)

year = dt.today().year
response = self.cli_run("get {} -t recurrent", format_args=entry_id)
self.assertEqual(
response, """\
Name : Credit
Value : -100.0
Frequency: Monthly
Start : {}-01-01
End : None
Category : No-Category""".format(year))

entry_id = self.cli_run(
"add gift -200 -t recurrent -f quarter-yearly -e 12-31")
self.assertEqual(entry_id, 2)

response = self.cli_run("get {} -t recurrent", format_args=entry_id)

self.assertIn("End : {}-12-31".format(year), response)


CONVERT_TEST_DATA_DIR = tempfile.mkdtemp(prefix="financeager-convert-")

Expand Down

0 comments on commit f06471f

Please sign in to comment.