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
7577a8ed
Verified
Commit
7577a8ed
authored
9 months ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
test: add tests for day schedule & playout
parent
bb088cbd
No related branches found
No related tags found
No related merge requests found
Pipeline
#8263
passed
9 months ago
Stage: check
Stage: test
Stage: build
Stage: deploy
Stage: release
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
program/tests/test_day_schedule.py
+75
-0
75 additions, 0 deletions
program/tests/test_day_schedule.py
program/tests/test_playout.py
+71
-0
71 additions, 0 deletions
program/tests/test_playout.py
with
146 additions
and
0 deletions
program/tests/test_day_schedule.py
0 → 100644
+
75
−
0
View file @
7577a8ed
from
datetime
import
datetime
,
timedelta
import
pytest
pytestmark
=
pytest
.
mark
.
django_db
def
url
(
include_virtual
=
False
):
year
,
month
,
day
=
datetime
.
today
().
year
,
datetime
.
today
().
month
,
datetime
.
today
().
day
if
include_virtual
:
return
f
"
/api/v1/program/
{
year
}
/
{
month
}
/
{
day
}
/?include_virtual=true
"
else
:
return
f
"
/api/v1/program/
{
year
}
/
{
month
}
/
{
day
}
/
"
def
create_once_schedule
(
admin_api_client
,
once_rrule
,
show
)
->
None
:
"""
creates a schedule for a show that repeats once using the REST API.
"""
now
=
datetime
.
now
()
in_an_hour
=
now
+
timedelta
(
hours
=
1
)
data
=
{
"
schedule
"
:
{
"
end_time
"
:
in_an_hour
.
strftime
(
"
%H:%M:%S
"
),
"
first_date
"
:
now
.
strftime
(
"
%Y-%m-%d
"
),
"
last_date
"
:
None
,
"
rrule_id
"
:
once_rrule
.
id
,
"
show_id
"
:
show
.
id
,
"
start_time
"
:
now
.
strftime
(
"
%H:%M:%S
"
),
},
}
admin_api_client
.
post
(
"
/api/v1/schedules/
"
,
data
=
data
,
format
=
"
json
"
)
def
test_day_schedule
(
admin_api_client
,
api_client
,
once_rrule
,
show
):
create_once_schedule
(
admin_api_client
,
once_rrule
,
show
)
response
=
api_client
.
get
(
url
())
assert
response
.
status_code
==
200
assert
len
(
response
.
json
())
==
1
entry
=
response
.
json
()[
0
]
assert
not
entry
[
"
isVirtual
"
]
assert
entry
[
"
showId
"
]
==
show
.
id
assert
entry
[
"
showName
"
]
==
show
.
name
def
test_day_schedule_include_virtual
(
admin_api_client
,
api_client
,
once_rrule
,
show
,
fallback_show
,
radio_settings
,
):
create_once_schedule
(
admin_api_client
,
once_rrule
,
show
)
response
=
api_client
.
get
(
url
(
include_virtual
=
True
))
assert
response
.
status_code
==
200
assert
len
(
response
.
json
())
==
3
for
entry
in
response
.
json
():
if
entry
[
"
isVirtual
"
]:
print
(
"
V
"
)
assert
entry
[
"
showId
"
]
==
fallback_show
.
id
assert
entry
[
"
showName
"
]
==
fallback_show
.
name
else
:
print
(
"
R
"
)
assert
entry
[
"
showId
"
]
==
show
.
id
assert
entry
[
"
showName
"
]
==
show
.
name
This diff is collapsed.
Click to expand it.
program/tests/test_playout.py
0 → 100644
+
71
−
0
View file @
7577a8ed
from
datetime
import
datetime
,
timedelta
import
pytest
pytestmark
=
pytest
.
mark
.
django_db
def
url
(
include_virtual
=
False
):
if
include_virtual
:
return
"
/api/v1/playout/?include_virtual=true
"
return
"
/api/v1/playout/
"
def
create_daily_schedule
(
admin_api_client
,
daily_rrule
,
show
)
->
None
:
"""
creates a schedule for a show that repeats daily using the REST API.
"""
now
=
datetime
.
now
()
in_one_hour
=
now
+
timedelta
(
hours
=
1
)
in_seven_days
=
now
+
timedelta
(
days
=
7
)
data
=
{
"
schedule
"
:
{
"
end_time
"
:
in_one_hour
.
strftime
(
"
%H:%M:%S
"
),
"
first_date
"
:
now
.
strftime
(
"
%Y-%m-%d
"
),
"
last_date
"
:
in_seven_days
.
strftime
(
"
%Y-%m-%d
"
),
"
rrule_id
"
:
daily_rrule
.
id
,
"
show_id
"
:
show
.
id
,
"
start_time
"
:
now
.
strftime
(
"
%H:%M:%S
"
),
}
}
admin_api_client
.
post
(
"
/api/v1/schedules/
"
,
data
=
data
,
format
=
"
json
"
)
def
test_playout
(
admin_api_client
,
api_client
,
daily_rrule
,
show
):
create_daily_schedule
(
admin_api_client
,
daily_rrule
,
show
)
response
=
api_client
.
get
(
url
())
assert
response
.
status_code
==
200
assert
len
(
response
.
json
())
==
7
for
entry
in
response
.
json
():
assert
not
entry
[
"
isVirtual
"
]
assert
entry
[
"
showId
"
]
==
show
.
id
assert
entry
[
"
showName
"
]
==
show
.
name
def
test_playout_include_virtual
(
admin_api_client
,
api_client
,
daily_rrule
,
show
,
fallback_show
,
radio_settings
,
):
create_daily_schedule
(
admin_api_client
,
daily_rrule
,
show
)
response
=
api_client
.
get
(
url
(
include_virtual
=
True
))
assert
response
.
status_code
==
200
assert
len
(
response
.
json
())
==
14
or
15
for
entry
in
response
.
json
():
if
entry
[
"
isVirtual
"
]:
assert
entry
[
"
showId
"
]
==
fallback_show
.
id
assert
entry
[
"
showName
"
]
==
fallback_show
.
name
else
:
assert
entry
[
"
showId
"
]
==
show
.
id
assert
entry
[
"
showName
"
]
==
show
.
name
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