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
54554c82
Commit
54554c82
authored
11 months ago
by
Chris Pastl
Browse files
Options
Downloads
Patches
Plain Diff
test: add test cases for AuraMonitor
parent
73a95dec
No related branches found
No related tags found
1 merge request
!39
Improve test coverage for monitor
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_plugins_monitor.py
+165
-0
165 additions, 0 deletions
tests/test_plugins_monitor.py
with
165 additions
and
0 deletions
tests/test_plugins_monitor.py
0 → 100644
+
165
−
0
View file @
54554c82
#
# 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.utils
import
SimpleUtil
as
SU
from
aura_engine.plugins.monitor
import
AuraMonitor
#
# Mock
#
class
MockedMixer
:
"""
Mocked version of mixer.
"""
def
get_inputs
(
self
)
->
dict
:
state
=
{
"
ready
"
:
True
,
"
selected
"
:
True
,
"
single
"
:
True
,
"
volume
"
:
0
,
"
remaining
"
:
0.0
,
}
return
{
"
in_queue_0
"
:
state
,
"
in_queue_1
"
:
state
,
"
in_stream_0
"
:
state
,
"
in_stream_1
"
:
state
,
"
in_line_0
"
:
state
,
"
in_line_1
"
:
state
,
}
def
get_outputs
(
self
)
->
list
:
return
[
"
lineout_0
"
,
"
out_http_0
"
]
class
MockedPlayer
:
"""
Mocked version of engine.
"""
mixer
=
MockedMixer
()
class
MockedEventDispather
:
"""
Mocked version of event dispatcher.
"""
def
on_sick
(
self
,
data
):
pass
class
MockedEngine
:
"""
Mocked version of engine.
"""
player
=
MockedPlayer
()
event_dispatcher
=
MockedEventDispather
()
def
init_version
(
self
):
versions
=
{
"
control
"
:
1
,
"
core
"
:
1
,
"
liquidsoap
"
:
1
}
AuraConfig
.
instance
.
init_version
(
versions
)
def
update_playout_state
(
self
):
return
True
class
TestPluginsMonitor
(
unittest
.
TestCase
):
"""
Testing the monitor plugin.
"""
monitor
:
AuraMonitor
config
:
AuraConfig
# Setup and teardown
def
setUp
(
self
):
self
.
config
=
AuraConfig
.
instance
.
config
self
.
monitor
=
AuraMonitor
(
MockedEngine
())
def
tearDown
(
self
):
pass
#
# Test Cases
#
def
test_has_valid_status_vitality_only
(
self
):
print
(
self
.
_testMethodName
)
# will fail due to missing info
status
=
self
.
monitor
.
has_valid_status
(
update_vitality_only
=
True
)
self
.
assertFalse
(
status
)
def
test_has_valid_status
(
self
):
print
(
self
.
_testMethodName
)
# mock valid status by swizzling some methonds
def
validate_url_connection
(
url
:
str
)
->
bool
:
return
True
def
validate_directory
(
dir_path
:
str
)
->
dict
:
return
{
"
path
"
:
dir_path
,
"
exists
"
:
True
,
"
has_content
"
:
True
}
def
get_url_response
(
url
:
str
)
->
dict
:
return
{
"
auth
"
:
"
string
"
,
"
importer
"
:
"
string
"
,
"
store
"
:
"
string
"
}
def
get_ip
()
->
str
:
return
"
0.0.0.0
"
self
.
monitor
.
validate_url_connection
=
validate_url_connection
self
.
monitor
.
validate_directory
=
validate_directory
self
.
monitor
.
get_url_response
=
get_url_response
self
.
monitor
.
get_ip
=
get_ip
status
=
self
.
monitor
.
has_valid_status
(
update_vitality_only
=
False
)
self
.
assertTrue
(
status
)
def
test_validate_url_connection
(
self
):
print
(
self
.
_testMethodName
)
self
.
assertTrue
(
self
.
monitor
.
validate_url_connection
(
"
https://debian.org/
"
))
self
.
assertFalse
(
self
.
monitor
.
validate_url_connection
(
"
https://debian.123/
"
))
def
test_validate_directory
(
self
):
print
(
self
.
_testMethodName
)
path
=
"
./tests
"
status
=
self
.
monitor
.
validate_directory
(
path
)
self
.
assertEqual
(
status
[
"
path
"
],
path
)
self
.
assertEqual
(
status
[
"
exists
"
],
True
)
self
.
assertEqual
(
status
[
"
has_content
"
],
True
)
path
=
"
./tests_
"
status
=
self
.
monitor
.
validate_directory
(
path
)
self
.
assertEqual
(
status
[
"
path
"
],
path
)
self
.
assertEqual
(
status
[
"
exists
"
],
False
)
self
.
assertEqual
(
status
[
"
has_content
"
],
False
)
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