Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DashboardLeaf
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ProjectLeaf
DashboardLeaf
Commits
a31100d2
Commit
a31100d2
authored
4 years ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
#45 - added unittests for _send_notification()
parent
5f6e5961
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/logic/tile/tiles/SensorLineChartTile.py
+5
-3
5 additions, 3 deletions
src/logic/tile/tiles/SensorLineChartTile.py
test/logic/tile/tiles/TestSensorLineChartTile.py
+40
-0
40 additions, 0 deletions
test/logic/tile/tiles/TestSensorLineChartTile.py
with
45 additions
and
3 deletions
src/logic/tile/tiles/SensorLineChartTile.py
+
5
−
3
View file @
a31100d2
...
@@ -184,8 +184,7 @@ class SensorLineChartTile(Tile):
...
@@ -184,8 +184,7 @@ class SensorLineChartTile(Tile):
warningSettings
=
self
.
_settings
[
'
outdatedValueWarning
'
]
warningSettings
=
self
.
_settings
[
'
outdatedValueWarning
'
]
timeSinceLastValue
=
self
.
_get_time_since_last_value
(
warningSettings
,
data
)
timeSinceLastValue
=
self
.
_get_time_since_last_value
(
warningSettings
,
data
)
if
warningSettings
[
'
enableNotificationViaPushbullet
'
]:
self
.
_send_notification
(
warningSettings
,
data
[
'
sensorInfo
'
],
data
[
'
deviceInfo
'
],
timeSinceLastValue
)
self
.
__send_notification
(
warningSettings
,
data
[
'
sensorInfo
'
],
data
[
'
deviceInfo
'
],
timeSinceLastValue
)
return
Tile
.
render_template
(
os
.
path
.
dirname
(
__file__
),
__class__
.
__name__
,
return
Tile
.
render_template
(
os
.
path
.
dirname
(
__file__
),
__class__
.
__name__
,
x
=
data
[
'
x
'
],
x
=
data
[
'
x
'
],
...
@@ -222,7 +221,10 @@ class SensorLineChartTile(Tile):
...
@@ -222,7 +221,10 @@ class SensorLineChartTile(Tile):
return
timeAgo
return
timeAgo
def
__send_notification
(
self
,
warningSettings
:
Dict
,
sensorInfo
:
Dict
,
deviceInfo
:
Dict
,
timeSinceLastValue
:
str
):
def
_send_notification
(
self
,
warningSettings
:
Dict
,
sensorInfo
:
Dict
,
deviceInfo
:
Dict
,
timeSinceLastValue
:
str
):
if
not
warningSettings
[
'
enableNotificationViaPushbullet
'
]:
return
token
=
warningSettings
[
'
pushbulletToken
'
]
token
=
warningSettings
[
'
pushbulletToken
'
]
sensorName
=
sensorInfo
[
'
name
'
]
sensorName
=
sensorInfo
[
'
name
'
]
...
...
This diff is collapsed.
Click to expand it.
test/logic/tile/tiles/TestSensorLineChartTile.py
+
40
−
0
View file @
a31100d2
...
@@ -2,6 +2,7 @@ import datetime
...
@@ -2,6 +2,7 @@ import datetime
from
unittest
import
mock
from
unittest
import
mock
from
unittest.mock
import
MagicMock
from
unittest.mock
import
MagicMock
from
logic
import
Helpers
from
logic.tile.tiles.SensorLineChartTile
import
SensorLineChartTile
,
SensorType
from
logic.tile.tiles.SensorLineChartTile
import
SensorLineChartTile
,
SensorType
...
@@ -204,3 +205,42 @@ class TestGetTimeSinceLastValue:
...
@@ -204,3 +205,42 @@ class TestGetTimeSinceLastValue:
data
=
{
'
latestTime
'
:
datetime
.
datetime
(
year
=
2021
,
month
=
1
,
day
=
1
,
hour
=
11
,
minute
=
00
,
second
=
00
)}
data
=
{
'
latestTime
'
:
datetime
.
datetime
(
year
=
2021
,
month
=
1
,
day
=
1
,
hour
=
11
,
minute
=
00
,
second
=
00
)}
assert
tile
.
_get_time_since_last_value
(
warningSettings
,
data
)
==
'
1 hour ago
'
assert
tile
.
_get_time_since_last_value
(
warningSettings
,
data
)
==
'
1 hour ago
'
class
TestSendNotification
:
def
__get_warning_settings
(
self
,
enable
:
bool
,
enableNotification
:
bool
):
return
{
'
enable
'
:
enable
,
'
limitInSeconds
'
:
10
,
'
enableNotificationViaPushbullet
'
:
enableNotification
,
'
pushbulletToken
'
:
'
myToken
'
}
@mock.patch
(
'
logic.tile.tiles.SensorLineChartTile.Helpers
'
)
def
test_notification_disabled_should_do_nothing
(
self
,
helpersMock
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
(
False
),
10
)
warningSettings
=
self
.
__get_warning_settings
(
True
,
False
)
tile
.
_send_notification
(
warningSettings
,
{},
{},
'
1 hour ago
'
)
helpersMock
.
send_notification_via_pushbullet
.
assert_not_called
()
@mock.patch
(
'
logic.Helpers.requests
'
)
def
test_send_notification_should_call_pushbullet_api
(
self
,
requestsMock
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
(
False
),
10
)
warningSettings
=
self
.
__get_warning_settings
(
True
,
True
)
sensorInfo
=
{
'
name
'
:
'
mySensor
'
,
'
type
'
:
'
temperature
'
}
deviceInfo
=
{
'
name
'
:
'
myDevice
'
}
requestsMock
.
post
.
return_value
.
status_code
=
200
tile
.
_send_notification
(
warningSettings
,
sensorInfo
,
deviceInfo
,
'
1 hour ago
'
)
requestsMock
.
post
.
assert_called_once_with
(
Helpers
.
PUSHBULLET_PUSH_URL
,
data
=
mock
.
ANY
,
headers
=
mock
.
ANY
)
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