Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
engine
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
engine
Commits
0d1f0244
Commit
0d1f0244
authored
1 year ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
test: add test cases for domain model
parent
755caf93
No related branches found
No related tags found
1 merge request
!35
ORM-less scheduling
Pipeline
#4754
failed
1 year ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_domain.py
+227
-0
227 additions, 0 deletions
tests/test_domain.py
with
227 additions
and
0 deletions
tests/test_domain.py
0 → 100644
+
227
−
0
View file @
0d1f0244
#
# Aura Engine (https://gitlab.servus.at/aura/engine)
#
# Copyright (C) 2017-now() - The Aura Engine Team.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
unittest
from
aura_engine.base.config
import
AuraConfig
from
aura_engine.base.logger
import
AuraLogger
from
aura_engine.resources
import
ResourceType
from
aura_engine.scheduling.domain
import
Playlist
,
PlaylistItem
,
PlaylistType
,
Timeslot
class
TestDomain
(
unittest
.
TestCase
):
"""
Testing the Domain Models.
"""
aura_logger
=
None
def
setUp
(
self
):
self
.
config
=
AuraConfig
()
self
.
aura_logger
=
AuraLogger
(
self
.
config
)
def
test_timeslot_init
(
self
):
print
(
self
.
_testMethodName
)
show
=
Timeslot
.
Show
(
id
=
555
,
name
=
"
3angulation
"
,
type
=
"
type_xy
"
,
cat
=
"
cat
"
,
funding_cat
=
"
fcat
"
,
music_focus
=
"
abstract
"
,
)
episode
=
Timeslot
.
Episode
(
hosts
=
[
"
host1
"
,
"
host2
"
],
languages
=
[
"
en
"
,
"
de
"
,
"
ar
"
],
topics
=
[
"
topic1
"
,
"
topic2
"
,
"
topic3
"
],
memo
=
"
Some memo or note.
"
,
)
ts
=
Timeslot
(
id
=
333
,
repetition_id
=
888
,
start
=
1675463003
,
end
=
1675466003
,
show
=
show
,
episode
=
episode
)
ts
.
set_playlists
(
Playlist
(),
Playlist
(),
Playlist
())
def
test_timeslot_to_string
(
self
):
print
(
self
.
_testMethodName
)
show
=
Timeslot
.
Show
(
id
=
555
,
name
=
"
3angulation
"
,
type
=
"
type_xy
"
,
cat
=
"
cat
"
,
funding_cat
=
"
fcat
"
,
music_focus
=
"
abstract
"
,
)
ts
=
Timeslot
(
id
=
333
,
repetition_id
=
888
,
start
=
1
,
end
=
2
,
show
=
show
,
episode
=
None
)
self
.
assertEqual
(
"
ID#333: 01:00:01 - 01:00:02 [Show#555: 3angulation]
"
,
str
(
ts
))
def
test_playlist_init
(
self
):
print
(
self
.
_testMethodName
)
pl
=
Playlist
()
pl
.
id
:
333
pl
.
timeslot
:
Timeslot
()
pl
.
type
:
PlaylistType
.
TIMESLOT
def
test_assign_playlists_to_timeslot
(
self
):
print
(
self
.
_testMethodName
)
ts
=
Timeslot
(
id
=
333
,
repetition_id
=
888
,
start
=
1675463003
,
end
=
1675466003
,
show
=
None
,
episode
=
None
)
pl_timeslot
=
Playlist
()
pl_schedule
=
Playlist
()
pl_show
=
Playlist
()
ts
.
set_playlists
(
pl_timeslot
,
None
,
None
)
ts
.
set_playlists
(
None
,
pl_schedule
,
None
)
ts
.
set_playlists
(
None
,
None
,
pl_show
)
ts
.
set_playlists
(
pl_timeslot
,
pl_schedule
,
pl_show
)
self
.
assertIsNotNone
(
ts
.
playlist
.
timeslot
)
self
.
assertIsNotNone
(
ts
.
playlist
.
schedule
)
self
.
assertIsNotNone
(
ts
.
playlist
.
show
)
self
.
assertEqual
(
PlaylistType
.
TIMESLOT
,
ts
.
playlist
.
timeslot
.
type
)
self
.
assertEqual
(
PlaylistType
.
SCHEDULE
,
ts
.
playlist
.
schedule
.
type
)
self
.
assertEqual
(
PlaylistType
.
SHOW
,
ts
.
playlist
.
show
.
type
)
def
test_playlist_duration_zero
(
self
):
print
(
self
.
_testMethodName
)
pl
=
Playlist
()
self
.
assertEqual
(
0
,
pl
.
get_duration
())
def
test_playlist_add_items
(
self
):
print
(
self
.
_testMethodName
)
pl
=
Playlist
()
e1
=
PlaylistItem
(
"
file1.flac
"
,
2
,
100
,
PlaylistItem
.
Metadata
(
"
a1
"
,
"
b1
"
,
"
c1
"
))
e2
=
PlaylistItem
(
"
file2.flac
"
,
3
,
100
,
PlaylistItem
.
Metadata
(
"
a2
"
,
"
b2
"
,
"
c2
"
))
e3
=
PlaylistItem
(
"
file3.flac
"
,
5
,
100
,
PlaylistItem
.
Metadata
(
"
a3
"
,
"
b3
"
,
"
c3
"
))
pl
.
add
(
e1
)
pl
.
add
(
e2
)
pl
.
add
(
e3
)
self
.
assertEqual
(
3
,
len
(
pl
.
items
))
def
test_playlist_duration
(
self
):
print
(
self
.
_testMethodName
)
pl
=
Playlist
()
e1
=
PlaylistItem
(
"
file1.flac
"
,
2
,
100
,
PlaylistItem
.
Metadata
(
"
a1
"
,
"
b1
"
,
"
c1
"
))
e2
=
PlaylistItem
(
"
file2.flac
"
,
3
,
100
,
PlaylistItem
.
Metadata
(
"
a2
"
,
"
b2
"
,
"
c2
"
))
e3
=
PlaylistItem
(
"
file3.flac
"
,
5
,
100
,
PlaylistItem
.
Metadata
(
"
a3
"
,
"
b3
"
,
"
c3
"
))
pl
.
add
(
e1
)
pl
.
add
(
e2
)
pl
.
add
(
e3
)
self
.
assertEqual
(
10
,
pl
.
get_duration
())
def
test_playlist_all_prev_and_next
(
self
):
print
(
self
.
_testMethodName
)
ts
=
Timeslot
(
id
=
333
,
repetition_id
=
888
,
start
=
100
,
end
=
120
,
show
=
None
,
episode
=
None
)
pl
=
Playlist
()
e1
=
PlaylistItem
(
"
file1.flac
"
,
2
,
100
,
PlaylistItem
.
Metadata
(
"
a1
"
,
"
b1
"
,
"
c1
"
))
e2
=
PlaylistItem
(
"
file2.flac
"
,
3
,
100
,
PlaylistItem
.
Metadata
(
"
a2
"
,
"
b2
"
,
"
c2
"
))
e3
=
PlaylistItem
(
"
file3.flac
"
,
5
,
100
,
PlaylistItem
.
Metadata
(
"
a3
"
,
"
b3
"
,
"
c3
"
))
e4
=
PlaylistItem
(
"
file4.flac
"
,
7
,
100
,
PlaylistItem
.
Metadata
(
"
a4
"
,
"
b4
"
,
"
c4
"
))
e5
=
PlaylistItem
(
"
file5.flac
"
,
9
,
100
,
PlaylistItem
.
Metadata
(
"
a5
"
,
"
b5
"
,
"
c5
"
))
e6
=
PlaylistItem
(
"
file6.flac
"
,
11
,
100
,
PlaylistItem
.
Metadata
(
"
a6
"
,
"
b6
"
,
"
c6
"
))
ts
.
set_playlists
(
pl
,
None
,
None
)
pl
.
add
(
e1
)
pl
.
add
(
e2
)
pl
.
add
(
e3
)
pl
.
add
(
e4
)
pl
.
add
(
e5
)
pl
.
add
(
e6
)
prev
=
e3
.
get_all_prev
()
self
.
assertEqual
(
2
,
len
(
prev
))
next
=
e3
.
get_all_next
(
True
)
self
.
assertEqual
(
2
,
len
(
next
))
next
=
e3
.
get_all_next
(
False
)
self
.
assertEqual
(
3
,
len
(
next
))
def
test_playlist_item_start_end
(
self
):
print
(
self
.
_testMethodName
)
ts
=
Timeslot
(
id
=
333
,
repetition_id
=
888
,
start
=
100
,
end
=
200
,
show
=
None
,
episode
=
None
)
pl
=
Playlist
()
e1
=
PlaylistItem
(
"
file1.flac
"
,
2
,
100
,
PlaylistItem
.
Metadata
(
"
a1
"
,
"
b1
"
,
"
c1
"
))
e2
=
PlaylistItem
(
"
file2.flac
"
,
3
,
100
,
PlaylistItem
.
Metadata
(
"
a2
"
,
"
b2
"
,
"
c2
"
))
e3
=
PlaylistItem
(
"
file3.flac
"
,
5
,
100
,
PlaylistItem
.
Metadata
(
"
a3
"
,
"
b3
"
,
"
c3
"
))
ts
.
set_playlists
(
pl
,
None
,
None
)
pl
.
add
(
e1
)
pl
.
add
(
e2
)
pl
.
add
(
e3
)
self
.
assertEqual
(
100
,
e1
.
get_start
())
self
.
assertEqual
(
102
,
e1
.
get_end
())
self
.
assertEqual
(
102
,
e2
.
get_start
())
self
.
assertEqual
(
105
,
e2
.
get_end
())
self
.
assertEqual
(
105
,
e3
.
get_start
())
self
.
assertEqual
(
110
,
e3
.
get_end
())
def
test_playlist_item_content_type
(
self
):
print
(
self
.
_testMethodName
)
e1
=
PlaylistItem
(
"
file://file1.flac
"
,
2
,
100
,
PlaylistItem
.
Metadata
(
"
a1
"
,
"
b1
"
,
"
c1
"
))
e2
=
PlaylistItem
(
"
https://stream.your.radio
"
,
3
,
100
,
PlaylistItem
.
Metadata
(
"
a2
"
,
"
b2
"
,
"
c2
"
)
)
e3
=
PlaylistItem
(
"
line://
"
,
5
,
100
,
PlaylistItem
.
Metadata
(
"
a3
"
,
"
b3
"
,
"
c3
"
))
e4
=
PlaylistItem
(
"
playlist://
"
,
5
,
100
,
PlaylistItem
.
Metadata
(
"
a3
"
,
"
b3
"
,
"
c3
"
))
e5
=
PlaylistItem
(
"
pool://
"
,
5
,
100
,
PlaylistItem
.
Metadata
(
"
a3
"
,
"
b3
"
,
"
c3
"
))
e6
=
PlaylistItem
(
"
unknown
"
,
5
,
100
,
PlaylistItem
.
Metadata
(
"
a3
"
,
"
b3
"
,
"
c3
"
))
e7
=
PlaylistItem
(
None
,
5
,
100
,
PlaylistItem
.
Metadata
(
"
a3
"
,
"
b3
"
,
"
c3
"
))
self
.
assertEqual
(
ResourceType
.
FILE
,
e1
.
get_content_type
())
self
.
assertEqual
(
ResourceType
.
STREAM_HTTP
,
e2
.
get_content_type
())
self
.
assertEqual
(
ResourceType
.
LINE
,
e3
.
get_content_type
())
self
.
assertEqual
(
ResourceType
.
PLAYLIST
,
e4
.
get_content_type
())
self
.
assertEqual
(
ResourceType
.
POOL
,
e5
.
get_content_type
())
self
.
assertEqual
(
None
,
e6
.
get_content_type
())
self
.
assertEqual
(
None
,
e7
.
get_content_type
())
def
test_playlist_item_to_string
(
self
):
print
(
self
.
_testMethodName
)
ts
=
Timeslot
(
id
=
333
,
repetition_id
=
888
,
start
=
100
,
end
=
200
,
show
=
None
,
episode
=
None
)
pl
=
Playlist
()
item
=
PlaylistItem
(
"
https://stream.your.radio
"
,
3
,
100
,
PlaylistItem
.
Metadata
(
"
a2
"
,
"
b2
"
,
"
c2
"
)
)
ts
.
set_playlists
(
pl
,
None
,
None
)
pl
.
add
(
item
)
self
.
assertEqual
(
"
PlaylistItem [01:01:40 - 01:01:43 | 3sec | Source: ...https://stream.your.radio]
"
,
str
(
item
),
)
if
__name__
==
"
__main__
"
:
unittest
.
main
()
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