Skip to content

Commit e9b7f6d

Browse files
committed
test: unit tests passing
1 parent 3405ccc commit e9b7f6d

File tree

4 files changed

+25
-69
lines changed

4 files changed

+25
-69
lines changed

tuttle/calendar.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pathlib import Path
55
import io
66
import re
7+
import calendar
78

89
from loguru import logger
910
import ics
@@ -180,3 +181,17 @@ class GoogleCalendar(CloudCalendar):
180181

181182
def to_data(self) -> DataFrame:
182183
raise NotImplementedError("TODO")
184+
185+
186+
def get_month_start_end(month_str):
187+
# Parse the string into a datetime object
188+
dt = datetime.datetime.strptime(month_str, "%B %Y")
189+
190+
# Get the date information from the datetime object
191+
year, month = dt.date().year, dt.date().month
192+
193+
# Get the start and end dates of the month
194+
start_date = datetime.date(year, month, 1)
195+
end_date = datetime.date(year, month, calendar.monthrange(year, month)[1])
196+
197+
return start_date, end_date

tuttle_tests/test_invoice.py

Lines changed: 5 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from tuttle import invoicing, timetracking, rendering
77
from tuttle.model import Invoice, InvoiceItem
8+
from tuttle.calendar import get_month_start_end
89

910

1011
def test_invoice():
@@ -50,10 +51,12 @@ def test_generate_invoice(
5051
for project in demo_projects:
5152
timesheets = []
5253
for period in ["January 2022", "February 2022"]:
54+
(period_start, period_end) = get_month_start_end(period)
5355
timesheet = timetracking.generate_timesheet(
54-
source=demo_calendar_timetracking,
56+
timetracking_data=demo_calendar_timetracking.to_data(),
5557
project=project,
56-
period_start=period,
58+
period_start=period_start,
59+
period_end=period_end,
5760
item_description=project.title,
5861
)
5962
if not timesheet.empty:
@@ -65,67 +68,3 @@ def test_generate_invoice(
6568
date=datetime.date.today(),
6669
)
6770
# assert invoice.total > 0
68-
69-
70-
def test_render_invoice_to_html(
71-
demo_user,
72-
demo_projects,
73-
demo_calendar_timetracking,
74-
):
75-
for project in demo_projects:
76-
timesheets = []
77-
for period in ["January 2022", "February 2022"]:
78-
timesheet = timetracking.generate_timesheet(
79-
source=demo_calendar_timetracking,
80-
project=project,
81-
period_start=period,
82-
item_description=project.title,
83-
)
84-
if not timesheet.empty:
85-
timesheets.append(timesheet)
86-
invoice = invoicing.generate_invoice(
87-
timesheets=timesheets,
88-
contract=project.contract,
89-
project=project,
90-
date=datetime.date.today(),
91-
)
92-
# RENDERING
93-
rendering.render_invoice(
94-
user=demo_user,
95-
invoice=invoice,
96-
style="anvil",
97-
document_format="html",
98-
out_dir=Path("tuttle_tests/tmp"),
99-
)
100-
101-
102-
def test_render_invoice_to_pdf(
103-
demo_user,
104-
demo_projects,
105-
demo_calendar_timetracking,
106-
):
107-
for project in demo_projects:
108-
timesheets = []
109-
for period in ["January 2022", "February 2022"]:
110-
timesheet = timetracking.generate_timesheet(
111-
source=demo_calendar_timetracking,
112-
project=project,
113-
period_start=period,
114-
item_description=project.title,
115-
)
116-
if not timesheet.empty:
117-
timesheets.append(timesheet)
118-
invoice = invoicing.generate_invoice(
119-
timesheets=timesheets,
120-
contract=project.contract,
121-
project=project,
122-
date=datetime.date.today(),
123-
)
124-
# RENDERING
125-
rendering.render_invoice(
126-
user=demo_user,
127-
invoice=invoice,
128-
style="anvil",
129-
document_format="pdf",
130-
out_dir=Path("tuttle_tests/tmp"),
131-
)

tuttle_tests/test_rendering.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class TestRenderTimesheet:
1616
"""Tests for render_timesheet"""
1717

1818
def test_returns_html_when_out_dir_is_none(self, fake):
19-
2019
user = demo.create_fake_user(fake)
2120
timesheet = demo.create_fake_timesheet(fake)
2221
document_format = "html"

tuttle_tests/test_timetracking.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import datetime
55

66
from tuttle import timetracking
7+
from tuttle.calendar import get_month_start_end
78

89

910
def test_timetracking_import_toggl():
@@ -27,11 +28,13 @@ def test_generate_timesheet_from_demo_calendar(
2728
demo_calendar_timetracking,
2829
):
2930
for period in ["January 2022", "February 2022"]:
31+
(period_start, period_end) = get_month_start_end(period)
3032
for project in demo_projects:
3133
timesheet = timetracking.generate_timesheet(
32-
source=demo_calendar_timetracking,
34+
timetracking_data=demo_calendar_timetracking.to_data(),
3335
project=project,
34-
period_start=period,
36+
period_start=period_start,
37+
period_end=period_end,
3538
item_description=project.title,
3639
)
3740
assert (timesheet.empty) or (timesheet.total >= pandas.Timedelta("0 hours"))

0 commit comments

Comments
 (0)