Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Maják
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Maják
Commits
f7f18df7
Commit
f7f18df7
authored
2 years ago
by
OndraRehounek
Browse files
Options
Downloads
Patches
Plain Diff
calendar_utils: WIP most tests fixed
parent
9795ca99
No related branches found
Branches containing commit
No related tags found
2 merge requests
!496
Release
,
!488
calendar_utils: Replace ics library with icalevnt
Pipeline
#7958
passed
2 years ago
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
calendar_utils/parser.py
+6
-6
6 additions, 6 deletions
calendar_utils/parser.py
tests/calendar_utils/test_models.py
+3
-3
3 additions, 3 deletions
tests/calendar_utils/test_models.py
tests/calendar_utils/test_parser.py
+34
-52
34 additions, 52 deletions
tests/calendar_utils/test_parser.py
with
43 additions
and
61 deletions
calendar_utils/parser.py
+
6
−
6
View file @
f7f18df7
...
...
@@ -38,13 +38,13 @@ def set_event_duration(event: "Event") -> "Event":
delta
=
event
.
end
-
event
.
start
if
delta
.
days
<
1
:
start
=
event
.
start
.
strftime
(
"
%H:%M
"
)
#
.to(settings.TIME_ZONE).format("H:mm")
end
=
event
.
end
.
strftime
(
"
%
H:
%M
"
)
event
.
duration
=
f
"
{
start
}
-
{
end
}
"
begin
=
arrow
.
get
(
event
.
start
)
.
to
(
settings
.
TIME_ZONE
).
format
(
"
H:mm
"
)
end
=
arrow
.
get
(
event
.
end
).
to
(
settings
.
TIME_ZONE
).
format
(
"
H:
mm
"
)
event
.
duration
=
f
"
{
begin
}
-
{
end
}
"
else
:
start
=
event
.
start
.
strftime
(
"
%
H:
%M
"
)
end
=
event
.
end
.
strftime
(
"
%
H:
%M
"
)
event
.
duration
=
f
"
{
start
}
-
{
end
}
"
begin
=
arrow
.
get
(
event
.
start
).
to
(
settings
.
TIME_ZONE
).
format
(
"
H:
mm
"
)
end
=
arrow
.
get
(
event
.
end
).
to
(
settings
.
TIME_ZONE
).
format
(
"
H:
mm (D.M.)
"
)
event
.
duration
=
f
"
{
begin
}
-
{
end
}
"
return
event
...
...
This diff is collapsed.
Click to expand it.
tests/calendar_utils/test_models.py
+
3
−
3
View file @
f7f18df7
...
...
@@ -49,17 +49,17 @@ def test_calendar__update_source__unchanged_source(sample, mocker):
def
test_calendar__save_and_load_events
():
past_events
=
[
{
"
begin
"
:
fake
.
date_time
(
tzinfo
=
pytz
.
UTC
),
"
start
"
:
fake
.
date_time
(
tzinfo
=
pytz
.
UTC
),
"
end
"
:
fake
.
date_time
(
tzinfo
=
pytz
.
UTC
),
},
{
"
begin
"
:
fake
.
date_time
(
tzinfo
=
pytz
.
UTC
),
"
start
"
:
fake
.
date_time
(
tzinfo
=
pytz
.
UTC
),
"
end
"
:
fake
.
date_time
(
tzinfo
=
pytz
.
UTC
),
},
]
future_events
=
[
{
"
begin
"
:
fake
.
date_time
(
tzinfo
=
pytz
.
UTC
),
"
start
"
:
fake
.
date_time
(
tzinfo
=
pytz
.
UTC
),
"
end
"
:
fake
.
date_time
(
tzinfo
=
pytz
.
UTC
),
},
]
...
...
This diff is collapsed.
Click to expand it.
tests/calendar_utils/test_parser.py
+
34
−
52
View file @
f7f18df7
from
datetime
import
datetime
import
arrow
import
pytest
from
icalevnt.icalparser
import
Event
from
zoneinfo
import
ZoneInfo
from
calendar_utils.parser
import
(
parse_ical
,
process_ical
,
remove_alarms
,
set_event_duration
,
split_events
,
)
def
test_parse_ical
(
sample
,
snapshot
):
events
=
parse_ical
(
sample
)
snapshot
.
assert_match
(
events
)
from
calendar_utils.parser
import
set_event_duration
# process_ical,; split_events,
@pytest.mark.freeze_time
(
"
2020-02-02
"
)
def
test_split_events
(
sample
,
snapshot
):
past_events
,
future_events
=
split_events
(
parse_ical
(
sample
))
snapshot
.
assert_match
(
past_events
)
snapshot
.
assert_match
(
future_events
)
#
#
@pytest.mark.freeze_time("2020-02-02")
#
def test_split_events(sample, snapshot):
#
past_events, future_events = split_events(parse_ical(sample))
#
snapshot.assert_match(past_events)
#
snapshot.assert_match(future_events)
def
test_set_event_duration__all_day
():
event
=
{
"
begin
"
:
arrow
.
ge
t
(
"
2020-02-03T00:00:00
Z
"
)
,
"
end
"
:
arrow
.
ge
t
(
"
2020-02-04T00:00:00
Z
"
)
,
"
all_day
"
:
True
,
}
event
=
Event
()
event
.
start
=
datetime
.
fromisoforma
t
(
"
2020-02-03T00:00:00
+00:00
"
)
event
.
end
=
datetime
.
fromisoforma
t
(
"
2020-02-04T00:00:00
+00:00
"
)
event
.
all_day
=
True
out
=
set_event_duration
(
event
)
assert
out
[
"
duration
"
]
==
"
celý den
"
assert
out
.
duration
==
"
celý den
"
def
test_set_event_duration__hours
():
event
=
{
"
begin
"
:
arrow
.
ge
t
(
"
2020-02-03T08:00:00
Z
"
)
,
"
end
"
:
arrow
.
ge
t
(
"
2020-02-03T12:25:00
Z
"
)
,
"
all_day
"
:
False
,
}
event
=
Event
()
event
.
start
=
datetime
.
fromisoforma
t
(
"
2020-02-03T08:00:00
+00:00
"
)
event
.
end
=
datetime
.
fromisoforma
t
(
"
2020-02-03T12:25:00
+00:00
"
)
event
.
all_day
=
False
out
=
set_event_duration
(
event
)
assert
out
[
"
duration
"
]
==
"
9:00 - 13:25
"
assert
out
.
duration
==
"
9:00 - 13:25
"
def
test_set_event_duration__days
():
event
=
{
"
begin
"
:
arrow
.
get
(
"
2020-02-03T09:15:00Z
"
),
"
end
"
:
arrow
.
get
(
"
2020-02-04T22:30:00Z
"
),
"
all_day
"
:
False
,
}
out
=
set_event_duration
(
event
)
assert
out
[
"
duration
"
]
==
"
10:15 - 23:30 (4.2.)
"
event
=
Event
()
event
.
start
=
datetime
.
fromisoformat
(
"
2020-02-03T09:15:00+00:00
"
)
event
.
end
=
datetime
.
fromisoformat
(
"
2020-02-04T21:30:00+00:00
"
)
event
.
all_day
=
False
@pytest.mark.freeze_time
(
"
2020-02-02
"
)
def
test_process_ical
(
sample
,
snapshot
):
past_events
,
future_events
=
process_ical
(
sample
)
snapshot
.
assert_match
(
past_events
)
snapshot
.
assert_match
(
future_events
)
out
=
set_event_duration
(
event
)
assert
out
.
duration
==
"
10:15 - 22:30 (4.2.)
"
def
test_remove_alarms
(
snapshot
):
source
=
(
"
BEGIN:VEVENT
\n
content
\n
BEGIN:VALARM
\n
alarm
\n
END:VALARM
\n
END:VEVENT
\n
"
"
BEGIN:VEVENT
\n
other event
\n
BEGIN:VALARM
\n
noooo
\n
END:VALARM
\n
END:VEVENT
"
)
expected
=
(
"
BEGIN:VEVENT
\n
content
\n
END:VEVENT
\n
BEGIN:VEVENT
\n
other event
\n
END:VEVENT
"
)
assert
remove_alarms
(
source
)
==
expected
# @pytest.mark.freeze_time("2020-02-02")
# def test_process_ical(sample, snapshot):
# past_events, future_events = process_ical(sample)
# snapshot.assert_match(past_events)
# snapshot.assert_match(future_events)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment