| Total Complexity | 5 |
| Total Lines | 28 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 |