|
1
|
|
|
""" |
|
2
|
|
|
Tests for the Marvin Power Price action |
|
3
|
|
|
""" |
|
4
|
|
|
|
|
5
|
|
|
import datetime |
|
6
|
|
|
|
|
7
|
|
|
from datetime import date, time |
|
8
|
|
|
|
|
9
|
|
|
from unittest import mock |
|
10
|
|
|
|
|
11
|
|
|
from test_action import ActionTest |
|
12
|
|
|
from irc2phpbb import marvin_actions |
|
13
|
|
|
|
|
14
|
|
|
class PowerPriceTest(ActionTest): |
|
15
|
|
|
"""Tests for the Marvin Power Price action""" |
|
16
|
|
|
def testPowerPriceRequest(self): |
|
17
|
|
|
"""Test that marvin sends the expected request for power price info""" |
|
18
|
|
|
with mock.patch("irc2phpbb.marvin_actions.datetime", wraps=datetime) as d: |
|
19
|
|
|
d.datetime.today.return_value = date(2025, 1, 12) |
|
20
|
|
|
with mock.patch("irc2phpbb.marvin_actions.requests") as r: |
|
21
|
|
|
self.executeAction(marvin_actions.marvinPowerPrice, "elpris") |
|
22
|
|
|
expectedUrl = self.strings.get("powerprice").get("url").format("2025-01-12") |
|
23
|
|
|
self.assertEqual(r.get.call_args.args[0], expectedUrl) |
|
24
|
|
|
|
|
25
|
|
|
def testPowerPriceResponse(self): |
|
26
|
|
|
"""Test that marvin properly parses weather responses""" |
|
27
|
|
|
with mock.patch("irc2phpbb.marvin_actions.random") as r: |
|
28
|
|
|
r.randint.return_value = 0 |
|
29
|
|
|
self.assertPowerPriceOutput("singleAreaResponse", time(12, 1, 0, 0), "Just nu kostar en kWh 1.4007 SEK i SE4.") |
|
30
|
|
|
self.assertPowerPriceOutput("singleAreaResponse", time(15, 0, 1, 0), "Just nu kostar en kWh 1.5130 SEK i SE4. Huvva!") |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
def testPowerPriceReaction(self): |
|
34
|
|
|
"""Test that marvin only reacts to power price requests when asked""" |
|
35
|
|
|
self.assertActionSilent(marvin_actions.marvinPowerPrice, "strömmen är dyr idag!") |
|
36
|
|
|
|
|
37
|
|
|
def assertPowerPriceOutput(self, exampleFile, timeOfDay, expectedOutput): |
|
38
|
|
|
"""Assert that marvin knows the current power price, given an input file and a time (in UTC)""" |
|
39
|
|
|
response = self.createResponseFrom("powerPriceFiles", exampleFile) |
|
40
|
|
|
with mock.patch("irc2phpbb.marvin_actions.datetime", wraps=datetime) as d: |
|
41
|
|
|
d.datetime.utcnow.return_value = timeOfDay |
|
42
|
|
|
with mock.patch("irc2phpbb.marvin_actions.requests") as r: |
|
43
|
|
|
r.get.return_value = response |
|
44
|
|
|
self.assertActionOutput(marvin_actions.marvinPowerPrice, "elpris", expectedOutput) |
|
45
|
|
|
|