Test Failed
Pull Request — master (#86)
by Daniel
04:59
created

test_sun   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 16
dl 0
loc 28
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A sunTest.testSun() 0 4 1
A sunTest.assertSunOutput() 0 6 2
A sunTest.testSunError() 0 4 2
1
"""
2
Tests for the Marvin Sun action
3
"""
4
5
from unittest import mock
6
7
from test_action import ActionTest
8
from irc2phpbb import marvin_actions
9
10
class sunTest(ActionTest):
11
    """Tests for the Marvin Sun action"""
12
    def assertSunOutput(self, expectedOutput):
13
        """Test that marvin knows when the sun comes up, given an input file"""
14
        response = self.createResponseFrom("sun", "sun")
15
        with mock.patch("irc2phpbb.marvin_actions.requests") as r:
16
            r.get.return_value = response
17
            self.assertActionOutput(marvin_actions.marvinSun, "sol", expectedOutput)
18
19
    def testSun(self):
20
        """Test that marvin sends the sunrise and sunset times """
21
        self.assertSunOutput(
22
            "Idag går solen upp 7:12 och ner 18:21. Iallafall i trakterna kring BTH.")
23
24
    def testSunError(self):
25
        """Tests that marvin returns the proper error message when joke API is down"""
26
        with mock.patch("irc2phpbb.marvin_actions.requests.get", side_effect=Exception("API Down!")):
27
            self.assertStringsOutput(marvin_actions.marvinSun, "när går solen ner?", "sun", "error")
28