Test Failed
Pull Request — master (#86)
by Daniel
06:22 queued 03:08
created

test_joke   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 21
dl 0
loc 35
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A JokeTest.testJokeRequest() 0 7 2
A JokeTest.testJokeError() 0 4 2
A JokeTest.assertJokeOutput() 0 6 2
A JokeTest.testJoke() 0 3 1
1
"""
2
Tests for the Marvin Joke action
3
"""
4
5
from unittest import mock
6
7
from test_action import ActionTest
8
from irc2phpbb import marvin_actions
9
10
class JokeTest(ActionTest):
11
    """Tests for the Marvin Joke action"""
12
    def assertJokeOutput(self, exampleFile, expectedOutput):
13
        """Assert that a joke is returned, given an input file"""
14
        response = self.createResponseFrom("joke", exampleFile)
15
        with mock.patch("irc2phpbb.marvin_actions.requests") as r:
16
            r.get.return_value = response
17
            self.assertActionOutput(marvin_actions.marvinJoke, "joke", expectedOutput)
18
19
    def testJokeRequest(self):
20
        """Test that marvin sends a proper request for a joke"""
21
        with mock.patch("irc2phpbb.marvin_actions.requests") as r:
22
            self.executeAction(marvin_actions.marvinJoke, "joke")
23
            self.assertEqual(
24
                r.get.call_args.args[0],
25
                "https://api.chucknorris.io/jokes/random?category=dev")
26
27
    def testJoke(self):
28
        """Test that marvin sends a joke when requested"""
29
        self.assertJokeOutput("joke", "There is no Esc key on Chuck Norris' keyboard, because no one escapes Chuck Norris.")
30
31
    def testJokeError(self):
32
        """Tests that marvin returns the proper error message when joke API is down"""
33
        with mock.patch("irc2phpbb.marvin_actions.requests.get", side_effect=Exception("API Down!")):
34
            self.assertStringsOutput(marvin_actions.marvinJoke, "kör ett skämt", "joke", "error")
35