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

test_commit.CommitTest.testCommitRequest()   A

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 2
nop 1
1
"""
2
Tests for the Marvin Commit action
3
"""
4
5
from unittest import mock
6
7
import requests
8
9
from test_action import ActionTest
10
from irc2phpbb import marvin_actions
11
12
class CommitTest(ActionTest):
13
    """Tests for the Marvin Commit action"""
14
    def testCommitRequest(self):
15
        """Test that marvin sends proper requests when generating commit messages"""
16
        with mock.patch("irc2phpbb.marvin_actions.requests") as r:
17
            self.executeAction(marvin_actions.marvinCommit, "vad skriver man efter commit -m?")
18
            self.assertEqual(r.get.call_args.args[0], "https://whatthecommit.com/index.txt")
19
20
    def testCommitResponse(self):
21
        """Test that marvin properly handles responses when generating commit messages"""
22
        message = "Secret sauce #9"
23
        response = requests.models.Response()
24
        response._content = str.encode(message)
25
        with mock.patch("irc2phpbb.marvin_actions.requests") as r:
26
            r.get.return_value = response
27
            expected = f"Använd detta meddelandet: '{message}'"
28
            self.assertActionOutput(marvin_actions.marvinCommit, "commit", expected)
29
30
    def testCommitReaction(self):
31
        """Test that marvin only generates commit messages when asked"""
32
        self.assertActionSilent(marvin_actions.marvinCommit, "nocommit")
33
34
35
    def testCommitError(self):
36
        """Tests that marvin sends the proper message when get commit fails"""
37
        with mock.patch("irc2phpbb.marvin_actions.requests.get", side_effect=Exception('API Down!')):
38
            self.assertStringsOutput(
39
                marvin_actions.marvinCommit,
40
                "vad skriver man efter commit -m?",
41
                "commit",
42
                "error")
43