|
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
|
|
|
|