Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
steering
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
AURA
steering
Commits
84fc954e
Verified
Commit
84fc954e
authored
8 months ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
test: add one week calendar program tests
parent
75943bed
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!52
new program endpoint
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/tests/test_calendar_program.py
+71
-15
71 additions, 15 deletions
program/tests/test_calendar_program.py
with
71 additions
and
15 deletions
program/tests/test_calendar_program.py
+
71
−
15
View file @
84fc954e
from
datetime
import
datetime
,
timedelta
import
pytest
from
conftest
import
create_daily_schedule
...
...
@@ -16,19 +18,20 @@ def url(include_virtual=False, start=None, end=None):
return
"
/api/v1/program/calendar/
"
def
assert_episodes
(
episodes
)
->
None
:
def
assert_episodes
(
episodes
,
one_week
=
False
)
->
None
:
"""
asserts the episodes are valid.
"""
assert
len
(
episodes
)
==
1
assert
len
(
episodes
)
==
1
if
not
one_week
else
7
assert
episodes
[
0
][
"
id
"
]
assert
episodes
[
0
][
"
timeslotId
"
]
for
episode
in
episodes
:
assert
episode
[
"
id
"
]
assert
episode
[
"
timeslotId
"
]
def
assert_program
(
program
,
show
,
fallback_show
=
None
)
->
None
:
def
assert_program
(
program
,
show
,
fallback_show
=
None
,
one_week
=
False
)
->
None
:
"""
asserts the program are valid and correspond to the given show and fallback show.
"""
assert
len
(
program
)
==
1
if
fallback_show
is
None
else
3
assert
len
(
program
)
==
1
if
fallback_show
is
None
and
not
one_week
else
(
7
if
one_week
else
3
)
assert
program
[
0
][
"
end
"
]
assert
program
[
0
][
"
id
"
]
...
...
@@ -60,16 +63,17 @@ def assert_shows(shows, show, fallback_show=None) -> None:
assert
shows
[
1
][
"
name
"
]
==
fallback_show
.
name
def
assert_timeslots
(
timeslots
,
show
)
->
None
:
"""
asserts the timeslots are valid correspond to the given show.
"""
def
assert_timeslots
(
timeslots
,
show
,
one_week
=
False
)
->
None
:
"""
asserts the timeslots are valid
and
correspond to the given show.
"""
assert
len
(
timeslots
)
==
1
assert
len
(
timeslots
)
==
1
if
not
one_week
else
7
assert
timeslots
[
0
][
"
id
"
]
assert
timeslots
[
0
][
"
noteId
"
]
assert
timeslots
[
0
][
"
end
"
]
assert
timeslots
[
0
][
"
start
"
]
assert
timeslots
[
0
][
"
showId
"
]
==
show
.
id
for
timeslot
in
timeslots
:
assert
timeslot
[
"
id
"
]
assert
timeslot
[
"
noteId
"
]
assert
timeslot
[
"
end
"
]
assert
timeslot
[
"
start
"
]
assert
timeslot
[
"
showId
"
]
==
show
.
id
def
test_calendar
(
admin_api_client
,
api_client
,
daily_rrule
,
show
):
...
...
@@ -91,6 +95,28 @@ def test_calendar(admin_api_client, api_client, daily_rrule, show):
assert_timeslots
(
value
,
show
)
def
test_calendar_one_week
(
admin_api_client
,
api_client
,
daily_rrule
,
show
):
create_daily_schedule
(
admin_api_client
,
daily_rrule
,
show
)
now
=
datetime
.
now
()
in_one_week
=
now
+
timedelta
(
days
=
7
)
response
=
api_client
.
get
(
url
(
start
=
now
.
isoformat
(),
end
=
in_one_week
.
isoformat
()))
assert
response
.
status_code
==
200
for
key
,
value
in
response
.
json
().
items
():
match
key
:
case
"
episodes
"
:
assert_episodes
(
value
,
one_week
=
True
)
case
"
program
"
:
assert_program
(
value
,
show
,
one_week
=
True
)
case
"
shows
"
:
assert_shows
(
value
,
show
)
case
"
timeslots
"
:
assert_timeslots
(
value
,
show
,
one_week
=
True
)
def
test_calendar_include_virtual
(
admin_api_client
,
api_client
,
...
...
@@ -110,9 +136,39 @@ def test_calendar_include_virtual(
case
"
episodes
"
:
assert_episodes
(
value
)
case
"
program
"
:
print
(
value
)
assert_program
(
value
,
show
,
fallback_show
)
case
"
shows
"
:
assert_shows
(
value
,
show
,
fallback_show
)
case
"
timeslots
"
:
assert_timeslots
(
value
,
show
)
def
test_calendar_one_week_include_virtual
(
admin_api_client
,
api_client
,
daily_rrule
,
show
,
fallback_show
,
radio_settings
,
):
create_daily_schedule
(
admin_api_client
,
daily_rrule
,
show
)
now
=
datetime
.
now
()
in_one_week
=
now
+
timedelta
(
days
=
7
)
response
=
api_client
.
get
(
url
(
include_virtual
=
True
,
start
=
now
.
isoformat
(),
end
=
in_one_week
.
isoformat
())
)
assert
response
.
status_code
==
200
for
key
,
value
in
response
.
json
().
items
():
match
key
:
case
"
episodes
"
:
assert_episodes
(
value
,
one_week
=
True
)
case
"
program
"
:
assert_program
(
value
,
show
=
show
,
fallback_show
=
fallback_show
,
one_week
=
True
)
case
"
shows
"
:
assert_shows
(
value
,
show
=
show
,
fallback_show
=
fallback_show
)
case
"
timeslots
"
:
assert_timeslots
(
value
,
show
=
show
,
one_week
=
True
)
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